簡體   English   中英

API崩潰在19 API上的API 23 Multidex

[英]App crash on api 23 multidex on 19 api

FATAL EXCEPTION: main
                                                                        Process: com.location.abc.kharcha, PID: 2963
                                                                        java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=-1, data=Intent { dat=content://media/external/images/media/47 }} to activity {com.location.abc.kharcha/com.location.abc.kharcha.Expense_main}: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media/47 from pid=2963, uid=10057 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
                                                                            at android.app.ActivityThread.deliverResults(ActivityThread.java:3699)
                                                                            at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742)
                                                                            at android.app.ActivityThread.-wrap16(ActivityThread.java)
                                                                            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393)
                                                                            at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                            at android.os.Looper.loop(Looper.java:148)
                                                                            at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                            at java.lang.reflect.Method.invoke(Native Method)
                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                         Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media/47 from pid=2963, uid=10057 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
                                                                            at android.os.Parcel.readException(Parcel.java:1599)
                                                                            at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
                                                                            at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
                                                                            at android.content.ContentProviderProxy.query(ContentProviderNative.java:421)
                                                                            at android.content.ContentResolver.query(ContentResolver.java:491)
                                                                            at android.content.ContentResolver.query(ContentResolver.java:434)
                                                                            at com.location.abc.kharcha.Expense_main.onActivityResult(Expense_main.java:403)
                                                                            at android.app.Activity.dispatchActivityResult(Activity.java:6428)
                                                                            at android.app.ActivityThread.deliverResults(ActivityThread.java:3695)
                                                                            at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742) 
                                                                            at android.app.ActivityThread.-wrap16(ActivityThread.java) 
                                                                            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393) 
                                                                            at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                            at android.os.Looper.loop(Looper.java:148) 
                                                                            at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                            at java.lang.reflect.Method.invoke(Native Method) 
                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

在19 API上構建Gradle錯誤

Information:Gradle tasks [:app:assembleDebug]
:appreBuild UP-TO-DATE
:appreDebugBuild UP-TO-DATE
:app:checkDebugManifest
:appreReleaseBuild UP-TO-DATE
:apprepareComAndroidSupportAnimatedVectorDrawable2400Library UP-TO-DATE
:apprepareComAndroidSupportAppcompatV72400Library UP-TO-DATE
:apprepareComAndroidSupportMultidex101Library UP-TO-DATE
:apprepareComAndroidSupportSupportV42400Library UP-TO-DATE
:apprepareComAndroidSupportSupportVectorDrawable2400Library UP-TO-DATE
:apprepareComAndroidVolleyVolley100Library UP-TO-DATE
:apprepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:mergeDebugShaders UP-TO-DATE
:app:compileDebugShaders UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:approcessDebugManifest UP-TO-DATE
:approcessDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:incrementalDebugJavaCompilationSafeguard UP-TO-DATE
:app:compileDebugJavaWithJavac
None of the classes needs to be compiled! Analysis took 0.827 secs. 
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources
:apprePackageMarkerForDebug
:app:transformClassesWithJarMergingForDebug FAILED
Error:Execution failed for task ':app:transformClasses`enter code here`WithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/apache/http/MessageConstraintException.class
Information:BUILD FAILED
Information:Total time: 8.706 secs
Information:1 error
Information:0 warnings
Informationee complete output in console

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (requestCode == 1) {
                File f = new File(Environment.getExternalStorageDirectory().toString());
                for (File temp : f.listFiles()) {
                    if (temp.getName().equals("temp.jpg")) {
                        f = temp;
                        break;
                    }
                }
                try {
                    Bitmap bitmap;
                    BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();

                    bitmap = BitmapFactory.decodeFile(f.getAbsolutePath(),
                            bitmapOptions);

                   // viewImage.setImageBitmap(bitmap);
                    BitmapDrawable ob = new BitmapDrawable(getResources(), bitmap);
                   // viewImage.setBackgroundDrawable(ob);
                    viewImage.setImageBitmap(bitmap);
                    filePath = android.os.Environment
                            .getExternalStorageDirectory()
                            + File.separator
                            + "Phoenix" + File.separator + "default";
                    File_path_check=true;
                    f.delete();
                    OutputStream outFile = null;
                    File file = new File(filePath, String.valueOf(System.currentTimeMillis()) + ".jpg");
                    try {
                        outFile = new FileOutputStream(file);
                        bitmap.compress(Bitmap.CompressFormat.JPEG, 85, outFile);
                        outFile.flush();
                        outFile.close();
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            else if (requestCode == 2) {
                Uri selectedImage = data.getData();
                String[] FilePath = { MediaStore.Images.Media.DATA };
                Cursor c = getContentResolver().query(selectedImage,FilePath, null, null, null);
                c.moveToFirst();
                Log.e("file", DatabaseUtils.dumpCursorToString(c));
                int columnIndex = c.getColumnIndex(FilePath[0]);
                 filePath = c.getString(columnIndex);
                File_path_check=true;
                c.close();
                Bitmap thumbnail = (BitmapFactory.decodeFile(filePath));
                Log.e("path image from gallery", filePath+"");
               // viewImage.setImageBitmap(thumbnail);
                BitmapDrawable ob = new BitmapDrawable(getResources(), thumbnail);
                viewImage.setBackgroundDrawable(ob);
            }
        }
    }

如您的錯誤所說。

java.lang.SecurityException:權限拒絕:從pid = 2963讀取com.android.providers.media.MediaProvider uri content:// media / external / images / media,uid = 10057需要android.permission.READ_EXTERNAL_STORAGE或grantUriPermission()

您必須在Manifest.xml文件中添加此權限。

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

還有一件事情,如果您正在Api 23中進行測試,則必須以編程方式按以下方式進行檢查。

查看有關權限的文檔以了解更多信息: https : //developer.android.com/preview/features/runtime-permissions.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM