美文网首页工作生活
android targetSdkVersion 改成28以后出

android targetSdkVersion 改成28以后出

作者: Solang | 来源:发表于2019-07-03 14:23 被阅读0次

1 找不到网络
在res/xml 新建立
network_security_config.xml文件
内容

<?xml version ="1.0" encoding ="utf-8"?><!--  Learn More about how to use App Actions: https://developer.android.com/guide/actions/index.html -->
<network-security-config>
    <base-config cleartextTrafficPermitted="true" />
</network-security-config>

在androidManifest.xml application 添加
android:networkSecurityConfig="@xml/network_security_config"

在application下边添加

 <meta-data
            android:name="com.google.android.actions"
            android:resource="@xml/network_security_config" />

========================================================
问题

Failed resolution of: Lorg/apache/http/ProtocolVersion;
1
解决
在application下边添加

<uses-library
android:name="org.apache.http.legacy"
android:required="false" />

=======================

3 添加拍照
在res/xml/ 建立provider_paths.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <paths>
        <external-path
            name="camera_photos"
            path="" />
    </paths>
</resources>

在manifests application 添加

 <!-- FileProvider配置访问路径,适配7.0及其以上 -->
        <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="包名.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths" />
        </provider>

打开相机

   public static void getByCamera(Activity act, String path, int requestCode) {
        String state = Environment.getExternalStorageState();
        if (state.equals(Environment.MEDIA_MOUNTED)) {
            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            Uri uri = getUri(act, new File(path));
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
            takePictureIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
            //Android7.0添加临时权限标记,此步千万别忘了
            takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            act.startActivityForResult(takePictureIntent, requestCode);

        }  
    }

public static Uri getUri(Context context, File file) {
        Uri fileUri;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            fileUri =  FileProvider.getUriForFile(context.getApplicationContext(), BuildConfig.APPLICATION_ID+".fileprovider",file);
        } else {
            fileUri = Uri.fromFile(file);
        }

        return fileUri;
    }

相关文章

网友评论

    本文标题:android targetSdkVersion 改成28以后出

    本文链接:https://www.haomeiwen.com/subject/devqhctx.html