安卓APP的安装和卸载

调用App安装的两个方法:

    方法一:

    

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



    方法二:

    


  1. Intent intent = new Intent(Intent.ACTION_VIEW);
  2. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  3. intent.setDataAndType(Uri.parse( "file://" + filePath),
  4. "application/vnd.android.package-archive");
  5. getApplicationContext().startActivity(intent);

卸载App的方法:

   

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


以上还涉及到一个安装包的下载,在此就不上代码了,请诸君自行储备.

猜你喜欢

转载自blog.csdn.net/qq_40837613/article/details/80922456
今日推荐