Programmatically install an apk in Android 7 / api24

后端 未结 8 1774
夕颜
夕颜 2020-12-31 07:39

I am trying to get my app to automatically install an apk. This works fine for api<24. But for 24, it is failing. Android has implemented extra security:

8条回答
  •  隐瞒了意图╮
    2020-12-31 08:31

    Add file in res/xml -> provider_paths.xml

    
    
        
    
    

    Add this code in AndroidManifest.xml

         
            
        
    

    run this code for install your app or open

        public void installApk(String file) {
            Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".provider",new File(file));
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(uri, "application/vnd.android.package-archive");
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            context.startActivity(intent);
        }
    

提交回复
热议问题