本文實(shí)例講述了Android實(shí)現(xiàn)用代碼簡(jiǎn)單安裝和卸載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); }}更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《Android開(kāi)發(fā)入門(mén)與進(jìn)階教程》、《Android調(diào)試技巧與常見(jiàn)問(wèn)題解決方法匯總》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選