在安裝android應用程序過程中,有的時候手機的內存不大,這個時候要求應用程序安裝到SD卡上.
如果要求程序直接安裝到SD卡上,可以使用installLoaction屬性.
在使用intallLocation的時候,要求指定的minSdkVersion 為8以上才可以,如果是在8以下使用這個屬性,系統是沒有辦法識別這個屬性.
使用installLocation屬性只要在manifest中做以下聲明,代碼如下:
android:versionCode = "1" android:installLocation = "preferExternal" android:versionName = "1.0"> <application <!-- 略 --> </application> <user-sdk android:minSdkVersion = "10"/>
android:installLocation的屬性有兩個值可以設定:
android:installLocation ="auto" android:installLocation ="preferExternal"
如果使有auto屬性,程序默認會安裝在手機內置內存中,但程序也會依據手機的最佳配置,若發現手機內存偏低又有SD卡存在,則由系統決定要安裝的位置.
在代碼中也通過 Intent對象時指定傳輸的 ACTION String "android.intent.action.MANAGE_PACKAGE_STORAGE",可引導User前往應用程序設置的Activity.
Intent intent = new Intent("android.intent.action.MANAGE_PACKAGE_STORAGE"); startActivity(intent);
有的時候我們安裝應用程序的時候,要判斷手機系統是否支持當前的應用程序版本.
可以調用 abstract ApplicationInfo getApplicationInfo()方法,裡面的targetSdkVersion屬性可判斷手機裡的ApplicationInfo的API Level是否符合程序運行的最低版本.
getApplicationInfo().targetSdkVersion <= Build.VERSION_CODES.GINGERBREAD