0

立ち往生しています。カメラから写真を取得して保存する私の方法は次のとおりです。

> > @Override
>     public File createImageFile() throws IOException {
>         String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
>         String imageFileName = "JPEG_" + timeStamp + "_";
>         File storageDir = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
>         File imageFile = File.createTempFile(imageFileName, ".jpg", storageDir);
>         model.currentPhotoPath = imageFile.getAbsolutePath();
>         return imageFile;
>     }

@Override
public Intent getCameraPictureIntent(PackageManager packageManager) {
    Intent pictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (pictureIntent.resolveActivity(packageManager) != null) {
        try {
            model.userPicFile = createImageFile();
        } catch (IOException e) {
            Log.i(TAG, "Can't create file!");
        }
        if (model.userPicFile != null) {
            model.userPicFileUri = FileProvider.getUriForFile(context,
                    "com.internship.droidz.talkin.fileprovider",
                    model.userPicFile);
            pictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, model.userPicFileUri);
        }
    }
    return pictureIntent;
}

tempfile を作成してから、uri を取得し、intent に設定します。そして、結果のstartActivity。写真を撮って送信すると、アプリがクラッシュします。Logcat は何も言いません。

ここに保存されたファイルとURIがあります:

    public class RegistrationModel implements RegistrationContract.RegistrationModel {

    String currentPhotoPath;
    Uri userPicFileUri;
    File userPicFile;
}

Manifest.xml のアクセス許可は次のとおりです。

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

<uses-feature android:name="android.hardware.camera"
    android:required="false" />

API 19+ 向けのコンパイル

それは Log.i の言うことです:

01-30 14:39:18.721 3265-3265/com.android.camera E/AndroidRuntime: FATAL EXCEPTION: main
                                                              Process: com.android.camera, PID: 3265
                                                              java.lang.IllegalStateException: Could not execute method of the activity
                                                                  at android.view.View$1.onClick(View.java:3823)
                                                                  at android.view.View.performClick(View.java:4438)
                                                                  at android.view.View$PerformClick.run(View.java:18422)
                                                                  at android.os.Handler.handleCallback(Handler.java:733)
                                                                  at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                  at android.os.Looper.loop(Looper.java:136)
                                                                  at android.app.ActivityThread.main(ActivityThread.java:5001)
                                                                  at java.lang.reflect.Method.invokeNative(Native Method)
                                                                  at java.lang.reflect.Method.invoke(Method.java:515)
                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
                                                                  at dalvik.system.NativeStart.main(Native Method)
                                                               Caused by: java.lang.reflect.InvocationTargetException
                                                                  at java.lang.reflect.Method.invokeNative(Native Method)
                                                                  at java.lang.reflect.Method.invoke(Method.java:515)
                                                                  at android.view.View$1.onClick(View.java:3818)
                                                                  at android.view.View.performClick(View.java:4438) 
                                                                  at android.view.View$PerformClick.run(View.java:18422) 
                                                                  at android.os.Handler.handleCallback(Handler.java:733) 
                                                                  at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                  at android.os.Looper.loop(Looper.java:136) 
                                                                  at android.app.ActivityThread.main(ActivityThread.java:5001) 
                                                                  at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                  at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
                                                                  at dalvik.system.NativeStart.main(Native Method) 
                                                               Caused by: java.lang.SecurityException: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{52a0a5b0 3265:com.android.camera/u0a36} (pid=3265, uid=10036) that is not exported from uid 10058
                                                                  at android.os.Parcel.readException(Parcel.java:1465)
                                                                  at android.os.Parcel.readException(Parcel.java:1419)
                                                                  at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:2848)
                                                                  at android.app.ActivityThread.acquireProvider(ActivityThread.java:4399)
                                                                  at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2208)
                                                                  at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1425)
                                                                  at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:906)
                                                                  at android.content.ContentResolver.openOutputStream(ContentResolver.java:669)
                                                                  at android.content.ContentResolver.openOutputStream(ContentResolver.java:645)
                                                                  at com.android.camera.Camera.doAttach(Camera.java:1385)
                                                                  at com.android.camera.Camera.onReviewDoneClicked(Camera.java:1362)
                                                                  at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                  at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                  at android.view.View$1.onClick(View.java:3818) 
                                                                  at android.view.View.performClick(View.java:4438) 
                                                                  at android.view.View$PerformClick.run(View.java:18422) 
                                                                  at android.os.Handler.handleCallback(Handler.java:733) 
                                                                  at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                  at android.os.Looper.loop(Looper.java:136) 
                                                                  at android.app.ActivityThread.main(ActivityThread.java:5001) 
                                                                  at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                  at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
                                                                  at dalvik.system.NativeStart.main(Native Method) 
4

1 に答える 1

0

ありがとうございます!answer Android - file provider - Permission Denialを使用して、この問題を解決しました

    List<ResolveInfo> resInfoList = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
    String packageName = resolveInfo.activityInfo.packageName;
    context.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
于 2017-01-30T21:27:23.597 に答える