admin管理员组文章数量:1567012
AndroidManifest.xml
在<application 里添加
android:networkSecurityConfig="@xml/fileproviderpath"
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.example.silentinstallation.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/fileproviderpath"
/>
</provider>
res/xml/fileproviderpath
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android/apk/res/android">
<root-path name="root" path="."></root-path>
<files-path
name="file"
path="."></files-path>
<files-path
name="files"
path="."></files-path>
<cache-path
name="cache"
path="."></cache-path>
<external-path
name="external"
path="."></external-path>
<external-cache-path
name="external_cache"
path="."></external-cache-path>
<external-files-path
name="external_file"
path="."></external-files-path>
<external-path name="external_files" path="."/>
</paths>
安装APK代码
String path = "/sdcard/youku.apk";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra("ISSILENT",1);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri;
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
uri = FileProvider.getUriForFile(this,"com.example.silentinstallation.fileprovider",new File(path));
intent.setDataAndType(uri,"application/vnd.android.package-archive");
}else{
uri = Uri.parse("file://" + path);
}
intent.setDataAndType(uri, "application/vnd.android.package-archive");
startActivity(intent);
}
本文标签: 报错exposedandroidgetDataIntent
版权声明:本文标题:Android报错: exposed beyond app through Intent.getData() 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dongtai/1725805616a1043993.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论