报错
1、android9.0使用volley进行网络请求
原因:Android 9.0是默认禁止所有http请求的,需要在代码中设置如以下代码才可以正常进行网络请求
2、java.lang.NoClassDefFoundError:failedresolutionof:Lorg/apache/http/ProtocolVersion
在AndroidManifest.xml文件的application标签里面加入
<uses-library android:name="org.apache.http.legacy" android:required="false" />
3、安装app的时候报错
报错代码:
原因:
这个问题是由于 Android 7.0 权限更改导致,确切的讲是 Android 对权限的进一步管理,从 Android 6.0 的动态权限申请
解决:
https://blog.csdn.net/weixin_41896508/article/details/94570194
1、application中加
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.example.administrator.myview.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths" />
</provider>
2、res/xml下新建filepaths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<!--<external-cache-path-->
<!--name="cache/"-->
<!--path="download"/>-->
<root-path name="cache" path="" />
</paths>
3、代码部分:
Intent intent = new Intent(Intent.ACTION_VIEW);
// intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri;
System.out.println("aaaaa"+getExternalCacheDir());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
Toast.makeText(this, "aaa", Toast.LENGTH_SHORT).show();
// intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
uri = FileProvider.getUriForFile(this,"com.example.administrator.myview.fileprovider",apkPath);
}else {
Toast.makeText(this, "bbb", Toast.LENGTH_SHORT).show();
uri = Uri.parse("file://" + apkPath.toString());
}
intent.setDataAndType(uri,"application/vnd.android.package-archive");
startActivity(intent);
4、Android8.0和9.0要加权限:
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
4、java.lang.NoClassDefFoundError:failedresolutionof:Lorg/apache/http/ProtocolVersion
在AndroidManifest.xml文件的application标签里面加入
<uses-library android:name="org.apache.http.legacy" android:required="false" />