您的位置:首页 > 移动开发 > Android开发

Android实现安装和卸载APK

2013-03-28 18:39 253 查看
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);

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: