开发者

How can I show file in sdcard to user?

开发者 https://www.devze.com 2023-03-25 03:37 出处:网络
开发者_如何学PythonI want to show user my apk file using intents, here is the code: SDCardRoot = Environment.getExternalStorageDirectory();

开发者_如何学PythonI want to show user my apk file using intents, here is the code:

 SDCardRoot = Environment.getExternalStorageDirectory();
 File file = new File(SDCardRoot,fileName);
 if (file.exists()) {

Uri path = Uri.fromFile(file);
Intent intent = new    
Intent(Intent.ACTION_VIEW,path);                                
startActivity(intent);

but it is giving me ActivityNotFoundException,I want to start the apk file so that user can install it.


Try this?

Uri path = Uri.fromFile(file);
Intent intent = new    
Intent(Intent.ACTION_VIEW,path);
intent.setDataAndType(path, "application/vnd.android.package-archive");                    
startActivity(intent);
0

精彩评论

暂无评论...
验证码 换一张
取 消