Android應用程式的安裝位置

來源:互聯網
上載者:User
Android應用程式的預設安裝位置以及是否可移動取決於開發人員在其AndroidManifest.xml中的設定: <manifestxmlns:android="http://schemas.android.com/apk/res/android"              android:versionCode="1"       android:installLocation="auto"       android:versionName="1.0">  android:installLocation的值有三個 internalOnly ,auto,preferExternal,預設值為internalOnlyinternalOnly表示該應用程式只能安裝到手機內部儲存中。auto表示由系統決定該應用程式安裝到手機內部儲存中還是SD卡中。 如果有SD卡且應用程式大於5M的話,安裝到SD卡中,否則安排到手機內部儲存中preferExternal表示如果有SD卡就把該應用程式只能安裝到SD卡中,否則安裝到手機內部儲存中。 android:installLocation為internalOnly時,使用者在"Setting"->"Application"->"Manage applications"中不能把應用程式在SD卡與記憶體中相互移動 android:installLocation為auto或preferExternal時,使用者在"Setting"->"Application"->"Manage applications"中可以把應用程式在SD卡與記憶體中相互移動  另外,adb shell 中可以使用 pm setInstallLocation 2 命令中強行更改安裝位置。2代表的是強制安裝在SD卡中,0代表自動,1代表強制裝到手機內部儲存中。 在代碼中,對於高於Android 2.2的手機中,可以通過ApplicationInfo.FLAG_EXTERNAL_STORAGE 標記可以判斷應用是否安裝在Sdcard上,對於低於Android 2.2的手機可以通過ApplicationInfo的sourceDir屬性為/sdcard/開頭來確定APK安裝的位置。  樣本1 PackageManager pm=ctx.getPackageManager();ApplicationInfo appInfo=pm.getApplicationInfo(pkgName,0);if((appInfo.flags &ApplicationInfo.FLAG_EXTERNAL_STORAGE)!=0){                // App on sdcard                System.out.println(pkgName+" install on sdcard");
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.