Android实现用代码简单安装和卸载APK的方法

 更新时间:2016年08月13日 11:51:15   作者:llyofdream  
这篇文章主要介绍了Android实现用代码简单安装和卸载APK的方法,涉及Android针对APK文件及package的相关操作技巧,需要的朋友可以参考下

本文实例讲述了Android实现用代码简单安装和卸载APK的方法。分享给大家供大家参考,具体如下:

public class TestInstallAPK extends Activity {
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 // TODO Auto-generated method stub
 super.onCreate(savedInstanceState);
 // this.unInstallFile();
 installFile();
 }
 /**
 * install APK code
 */
 private void installFile(){
 Intent intent = new Intent(Intent.ACTION_VIEW);
  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  intent.setAction(android.content.Intent.ACTION_VIEW);
//  String type = getMIMEType(f);
//  intent.setDataAndType(Uri.fromFile(f), type);
 intent.setDataAndType(Uri.parse("file://" + "/sdcard/Android_gc.apk"),
  "application/vnd.android.package-archive");
 this.startActivity(intent);
 }
 /**
 * uninstall APK code
 */
 private void unInstallFile(){
 Uri uri=Uri.parse("package:com.gameclient");
 Intent intent = new Intent(Intent.ACTION_DELETE,uri);
 this.startActivity(intent);
 }
}

更多关于Android相关内容感兴趣的读者可查看本站专题:《Android开发入门与进阶教程》、《Android调试技巧与常见问题解决方法汇总》、《Android多媒体操作技巧汇总(音频,视频,录音等)》、《Android基本组件用法总结》、《Android视图View技巧总结》、《Android布局layout技巧总结》及《Android控件用法总结

希望本文所述对大家Android程序设计有所帮助。

相关文章

最新评论