Android安装卸载程序具体操作方法解析


  本文标签:Android安装卸载程序

  对于编程爱好者们来说,Android手机操作系统是一款非常实用的系统  。他们可以进行各种Android应用程序的开发来满足自的应用需求  。在这里我们就先来为大家讲解一下有关Android安装卸载程序的具体操作步骤  。

  在Android安装卸载程序的源码中我们知道:

  1. < activity android:name=".PackageInstallerActivity">   
  2. < intent-filter>   
  3. < action android:name="android.intent.action.VIEW" />   
  4. < category android:name="android.intent.category.DEFAULT" />   
  5. < data android:scheme="content" />   
  6. < data android:scheme="file" />   
  7. < data android:mimeType="application/vnd.android.package-archive" />   
  8. < /intent-filter>   
  9. < /activity>   
  10. < activity android:name=".UninstallerActivity">   
  11. < intent-filter>   
  12. < action android:name="android.intent.action.VIEW" />   
  13. < action android:name="android.intent.action.DELETE" />   
  14. < category android:name="android.intent.category.DEFAULT" />   
  15. < data android:scheme="package" />   
  16. < /intent-filter>   
  17. < /activity> 

  因为根据里面的权限我们可以 安装一个程序从sd卡:

  1. String fileName = Environment.getExternalStorageDirectory() 
    + "/myApp.apk";   
  2. Intent intent = new Intent(Intent.ACTION_VIEW);   
  3. intent.setDataAndType(Uri.fromFile(new File(fileName)), 
    "application/vnd.android.package-archive");   
  4. startActivity(intent);  

  Android安装卸载程序的操作中要想卸载一个程序;

  1. Uri packageURI = Uri.parse("package:com.android.myapp");   
  2. Intent uninstallIntent = new Intent
    (Intent.ACTION_DELETE, packageURI);   
  3. startActivity(uninstallIntent);  

  默认是不支持安装非市场程序的 因此判断一下

  1. int result = Settings.Secure.getInt(getContentResolver(),
     Settings.Secure.INSTALL_NON_MARKET_APPS, 0);   
  2. if (result == 0) {   
  3. // show some dialog here   
  4. // ...   
  5. // and may be show application settings dialog manually   
  6. Intent intent = new Intent();   
  7. intent.setAction(Settings.ACTION_APPLICATION_SETTINGS);   
  8. startActivity(intent);   

  Android安装卸载程序的具体实现方法就为大家介绍到这里  。