如何读/设置默认Android上的安装位置编程? [英] How to read/set default install location on android programmatically?

查看:137
本文介绍了如何读/设置默认Android上的安装位置编程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道默认安装在Android应用程序的位置,可以通过亚行的方法通过调用来检索:

I know that the default install location of apps in Android can be retrieved by using adb method by invoking:

adb shell pm getInstallLocation

和可以通过使用进行更改:

and can be changed by using:

adb shell pm setInstallLocation

但我的问题是我们如何编程实现这一目标(采用Android API或Java code)。

But my question is how do we achieve this programmatically(using Android API or Java code).

推荐答案

应用安装Android开发者文档的位置页面提供了关于设置应用程序的安装位置和潜在的警告信息。

The App Install Location page of the Android Developer's docs provides information on setting the app install location and potential caveats.

要做到这一点,你需要在你的清单以指定的installLocation ,就像这样:

To do so, you need to specify the installLocation in your manifest, like so:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    android:installLocation="preferExternal"
    ... >

您的选项有:


  • preferExternal :安装在设备的外部存储尽可能(不保证)

  • 自动:默认为内部存储,但允许用户将其移动到外部存储

  • internalOnly :只允许在设备的内部存储装置

  • preferExternal: Install on the device's external storage whenever possible (not guaranteed)
  • auto: Default to internal storage, but allow the user to move it to external storage
  • internalOnly: Only allow installation on the device's internal storage.

您不能设置在应用程序的code,由点任何code执行应用程序已经被安装。

You cannot set this in the app's code, as by the point any code executes the application has already been installed.

这篇关于如何读/设置默认Android上的安装位置编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆