2016-09-26 47 views
-3

1)我可以在android中添加apk文件作爲擴展文件。 2)我試圖直接從外部存儲啓動應用程序,但出現錯誤。如何添加apk文件作爲擴展文件並直接在android中從外部存儲啓動?

代碼: -

Intent intent = new Intent(Intent.ACTION_VIEW); 
    intent.setDataAndType(Uri.fromFile(new File("storage/emulated/0/Android/obb/devui1.example.com.testing/main.98376.devui1.example.com.testing.obb/app-debug.apk")), "application/vnd.android.package-archive"); 
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // without this flag android returned a intent error! 
    startActivity(intent); 

回答

0

使用此代碼提取或編程安裝APK。

Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/download/" + "app.apk")), "application/vnd.android.package-archive"); 
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
startActivity(intent); 

使用此鏈接: https://stackoverflow.com/a/4969421/1223291

這將是從下載管理器下載的APK,並自動安裝。

相關問題