Android安裝卸載程序具體操作方法解析
作者:佚名
Android安裝卸載程序在實際應(yīng)用中是一個比較基本的操作。作為初學者來說需要牢固掌握這一應(yīng)用技巧,以方便我們的使用。
對于編程愛好者們來說,Android手機操作系統(tǒng)是一款非常實用的系統(tǒng)。他們可以進行各種Android應(yīng)用程序的開發(fā)來滿足自的應(yīng)用需求。在這里我們就先來為大家講解一下有關(guān)Android安裝卸載程序的具體操作步驟。
在Android安裝卸載程序的源碼中我們知道:
- < activity android:name=".PackageInstallerActivity">
- < intent-filter>
- < action android:name="android.intent.action.VIEW" />
- < category android:name="android.intent.category.DEFAULT" />
- < data android:scheme="content" />
- < data android:scheme="file" />
- < data android:mimeType="application/vnd.android.package-archive" />
- < /intent-filter>
- < /activity>
- < activity android:name=".UninstallerActivity">
- < intent-filter>
- < action android:name="android.intent.action.VIEW" />
- < action android:name="android.intent.action.DELETE" />
- < category android:name="android.intent.category.DEFAULT" />
- < data android:scheme="package" />
- < /intent-filter>
- < /activity>
因為根據(jù)里面的權(quán)限我們可以 安裝一個程序從sd卡:
- String fileName = Environment.getExternalStorageDirectory()
+ "/myApp.apk";- Intent intent = new Intent(Intent.ACTION_VIEW);
- intent.setDataAndType(Uri.fromFile(new File(fileName)),
"application/vnd.android.package-archive");- startActivity(intent);
Android安裝卸載程序的操作中要想卸載一個程序;
- Uri packageURI = Uri.parse("package:com.android.myapp");
- Intent uninstallIntent = new Intent
(Intent.ACTION_DELETE, packageURI);- startActivity(uninstallIntent);
默認是不支持安裝非市場程序的 因此判斷一下
- int result = Settings.Secure.getInt(getContentResolver(),
Settings.Secure.INSTALL_NON_MARKET_APPS, 0);- if (result == 0) {
- // show some dialog here
- // ...
- // and may be show application settings dialog manually
- Intent intent = new Intent();
- intent.setAction(Settings.ACTION_APPLICATION_SETTINGS);
- startActivity(intent);
- }
Android安裝卸載程序的具體實現(xiàn)方法就為大家介紹到這里。
【編輯推薦】
責任編輯:曹凱
來源:
javaeye.com