android 10 问题汇总

1、因为deviceid的限制,所有各大三方sdk需要更新,比如个推、微信支付、环信、友盟,Basesdk

2、Using WebView from more than one process at once with the same data directory is not supported

这个错误是webview多进程使用导致,在api28以上,需要对webview  目录进行控制

@RequiresApi(api = 28)
public static void webviewSetPath(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
        String processName = getProcessName(context);
        if (!packageNameocessName)) {//判断不等于默认进程名称
            WebView.setDataDirectorySuffix(processName);
        }
    }
}

public static String getProcessName(Context context) {
    if (context == null) return null;
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) {
        if (processInfo.pid == android.os.Process.myPid()) {
            return processInfo.processName;
        }
    }
    return null;
}

3、文件系统:

获取本地根目录文件夹的适配:

public static  File getDiskCacheDir(String uniqueName) {
        File file = null;
        String cachePath = null;
        Context context = YokaApplication.context;
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q){
            cachePath = context.getExternalFilesDir(null).getAbsolutePath();
        }else{
            if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
                    || !Environment.isExternalStorageRemovable()) {
                if(context.getExternalCacheDir() != null){
                    cachePath = context.getExternalCacheDir().getPath(); //路径为:/mnt/sdcard//Android/data/< package name >/cach/…
                }else{
                    try {
                        cachePath  = Environment.getExternalStorageDirectory().getPath();   //SD根目录:/mnt/sdcard/ (6.0后写入需要用户授权)
                    }catch (Exception e){
                        cachePath = context.getCacheDir().getPath();  	//路径是:/data/data/< package name >/cach/…
                    }
                }
            } else {
                cachePath = context.getCacheDir().getPath();  	//路径是:/data/data/< package name >/cach/…
            }
        }
        file = new File(cachePath + File.separator + uniqueName);
        if(file.exists()){
            return file;
        }else {
            if(file.mkdir()){
               return file;
            }
        }
        return file;
    }

4、因为文件限制

BitmapFactory.decodeFile这一类的方法不能用了,下面提供方法获取本地图片的bitmap
//根据图片路径获取bitmap
    public static Bitmap getBitmapFormUrl(String url){
        Bitmap bitmap = null;
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q){
            File file = new File(url);
            File rootFile = YokaApplication.context.getExternalFilesDir(null);
            if(file.getAbsolutePath().contains(rootFile.getAbsolutePath())){
                bitmap = BitmapFactory.decodeFile(url);
            }else {
                Uri uri = getImageContentUri(url);
                bitmap = getBitmapFromUri(uri);
            }
        }else {
            bitmap = BitmapFactory.decodeFile(url);
        }
        return bitmap;
    }
public static Bitmap getBitmapFromUri( Uri uri) {
        try {
            ParcelFileDescriptor parcelFileDescriptor =
                    YokaApplication.context.getContentResolver().openFileDescriptor(uri, "r");
            FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
            Bitmap image = BitmapFactory.decodeFileDescriptor(fileDescriptor);
            parcelFileDescriptor.close();
            return image;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static Uri getImageContentUri(String path) {
        Cursor cursor = YokaApplication.context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                new String[] { MediaStore.Images.Media._ID }, MediaStore.Images.Media.DATA + "=? ",
                new String[] { path }, null);
        if (cursor != null && cursor.moveToFirst()) {
            int id = cursor.getInt(cursor.getColumnIndex(MediaStore.MediaColumns._ID));
            return Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "" + id);
        } else {
            // 如果图片不在手机的共享图片数据库,就先把它插入。
            if (new File(path).exists()) {
                ContentValues values = new ContentValues();
                values.put(MediaStore.Images.Media.DATA, path);
                return YokaApplication.context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
            } else {
                return null;
            }
        }
    }

 

 

你可能感兴趣的:(Android)