当前位置:网站首页>Android 72021 latest Android interview written test questions sharing
Android 72021 latest Android interview written test questions sharing
2022-06-24 00:07:00 【Ordinary netizens】
android.os.FileUriExposedException: file:///storage/emulated/0/Download/xxxAppName.apk exposed beyond app through Intent.getData()
The code called by the mobile terminal is as follows :
Intent intentUpdate = new Intent(“android.intent.action.VIEW”);
intentUpdate.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri apkUri = Uri.fromFile(new File(upgradeMsg.apkpath));
intentUpdate.setDataAndType(apkUri, “application/vnd.android.package-archive”);
startActivity(intentUpdate);
This error is mainly reported as google stay 6.0 Later versions have made permission restrictions , Applications Not directly through **file://Uri Share resources with another , Need to pass through content://Uris ** To share resources , So that the platform can extend the temporary permission of the receiving application to access resources . however N The previous version can still pass file:// To share resources .
The main reasons are summarized as follows :
- Suppose the shared file is private , receive file://Uri Of App Unable to access file
- stay Android6.0 After that, the runtime permissions are introduced , If file://Uri Of app No application Manifest.permission.READ_EXTERNAL_STORAGE jurisdiction , When the file is read Will cause a crash
The solution to this mistake google The plan is also given , use FileProvider, It is a file establish content://Uri instead of file://Uri To share files securely .
FileProvider Main steps :
- Definition FileProvider
- Specify available files
- To retrieve the contents of a file URI
- to grant authorization URI Temporary authority
- Providing content to another application URI
stay AndroidManifest.xml Add the following code to
Be careful : authorities:app The package name .fileProvider grantUriPermissions: Must be true, Indicates grant URI Temporary access rights exported: Must be false resource: Medium @xml/file_paths It's the file we're going to add next
stay res Create a new one in the directory xml Folder , And build a new file_paths Of xml file
path: Path requiring temporary authorization to access (. For all paths ) name: It's you who give this access path a name
It's almost time to modify the installation code , The code is as follows :
private void installApk() { // Erection sequence
Intent intentUpdate = new Intent(“android.intent.action.VIEW”);
intentUpdate.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { // Yes Android N And above
Uri apkUriN = FileProvider.getUriForFile(MainActivity2.this,
MainActivity2.this.getApplicationContext().getPackageName() + “.FileProvider”, new File(upgradeMsg.apkpath));
intentUpdate.addCategory(“android.intent.category.DEFAULT”);
intentUpdate.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // Day off. Flag Indicates what permissions we need
intentUpdate.setDataAndType(apkUriN, “application/vnd.android.package-archive”);
} else {
Uri apkUri = Uri.fromFile(new File(upgradeMsg.apkpath));
intentUpdate.setDataAndType(apkUri, “application/vnd.android.package-archive”);
}
startActivity(intentUpdate);
}
The code is written , Do you think it's ok ? When you are happy in 6.0 perhaps 7.0 ~ 8.0 When updating and installing , There is nothing wrong with it , But when you are 8.0 When installing versions and above , Click Update It will flash by , Or there is an error parsing the package . Why? ?
Because in Aandroid 8.0 When Google Some restrictions have been made
Android 8.0 Oreo in ,Google Removed easily abused “ Allow location source ” Switch for application , In the installation Play Store Third party sources other than Android When applied , It's gone “ Allow unknown sources ” Check box for , If you still want to install a developer you trust app, You need to grant... Manually every time “ Install unknown app ” Permission of .
We have to fit 8.0 And above .
The first thing you need to do is AandroidManifest.xml Add permission in
Secondly, when clicking update, you need to judge the mobile phone version information :
private static final
《Android Summary of learning notes + Latest mobile architecture video + Big Android interview questions + Project actual combat source code handout 》
【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 Full content open source sharing
int INSTALL_PACKAGES_REQUESTCODE = 10011;
private static final int GET_UNKNOWN_APP_SOURCES = 10012;
private void checkAndroidO() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { // System Android O And above
// Need to handle unknown application source permissions . true Install the package for user trust false You need to obtain authorization
boolean canRequestPackageInstalls = getPackageManager().canRequestPackageInstalls();
if (canRequestPackageInstalls) {
installApk();
边栏推荐
- Index principle and filling factor in database
- 跟着CTF-wiki学pwn——ret2text
- Detailed process from CPU fetching to sending control and microprogram control principle
- [leetcode notes] no118 Yanghui triangle
- Tiktok practice ~ password retrieval
- Total number of combinations ii[each element can only be solved by + once]
- 依赖倒置原则
- Startup process analysis of APP performance optimization
- SAVE: 软件分析验证和测试平台
- 组合总数II[每个元素只能用一次 + 去重复解集]
猜你喜欢

extern、struct等关键字
![Total number of combinations ii[each element can only be solved by + once]](/img/06/a40e28a1882a4278883202bc9c72d3.png)
Total number of combinations ii[each element can only be solved by + once]

【红绿灯识别】基于matlab GUI红绿灯识别【含Matlab源码 1908期】

The easycvr program started abnormally as a service, but the process started normally. What is the reason?

迷茫的测试/开发程序员,不同人有着不同的故事、有着不同的迷茫......

Learn PWN from CTF wiki - ret2text

Taylor formula and common expansion

CPU取指到发出控制、微程序控制原理详细过程

Three types of transactions in EF core (saveChanges, dbcontexttransaction, transactionscope)

Six complete open source projects, learning enough at a time
随机推荐
微信小程序中three.js的canvas非全屏情况下射线检测不准确问题解决方案
[leetcode notes] no118 Yanghui triangle
How to ensure reliable power supply of Expressway
点乘和叉乘
Easycvr implementation of adding preset point position function of Dahua equipment
Don't miss | Huawei's internal data - Successful Project Management PPT (page 123)
Six necessary open source projects for private activities
WPF效果之Expander+ListBox
Leetcode - linked list written test questions
Drag and drop report design - new features of jimureport 1.4.0
List<? Extensions T > and list <? Super T > difference
Wechat applet picture verification code display
Shutter control layout
Recommend 4 flutter heavy open source projects
What is medical treatment? AI medical concept analysis AI
Complete open source project poetry bar app
docker 部署redis
Kubernetes basic concept
合成大西瓜小游戏微信小程序源码/微信游戏小程序源码
Dependency Inversion Principle