Android报错

报错

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" />
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值