누우 트에서이 기능이 작동하지 않습니다. IllegalArgumentException : '_data'열이 없습니다.
String path = getRealPathFromURI(this, getIntent().getParcelableExtra(Intent.EXTRA_STREAM));
public String getRealPathFromURI(Context context, Uri contentUri) {
Cursor cursor = null;
try {
String[] proj = {MediaStore.Images.Media.DATA};
cursor = context.getContentResolver().query(contentUri, proj, null, null, null);
if (cursor == null) return contentUri.getPath();
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} finally {
if (cursor != null) {
cursor.close();
}
}
}
충돌 로그 :이 기능은 내가 기사 file:// scheme is now not allowed to be attached with Intent on targetSdkVersion 24 (Android Nougat)를 읽을 안드로이드 N. 전에 장치에서 제대로 작동
java.lang.RuntimeException: Unable to start activity ComponentInfo{class path}: java.lang.IllegalArgumentException: column '_data' does not exist
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2659)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2724)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
Caused by java.lang.IllegalArgumentException: column '_data' does not exist
at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:333)
at android.database.CursorWrapper.getColumnIndexOrThrow(CursorWrapper.java:87)
at com.package.SaveImageActivity.getRealPathFromURI()
at com.package.SaveImageActivity.onCreate()
at android.app.Activity.performCreate(Activity.java:6672)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1140)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2612)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2724)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
. 그러나 어떤 해결책도 찾을 수 없었습니다. 그러니 도와주세요.
왜 URI에서 파일 경로를 가져 오려고합니까? 일반적으로 모든 URI가 경로가있는 로컬 파일로 백업되지 않으므로 URI로 스트림을 사용하여 작업해야합니다. Exif 데이터를 읽으려는 목적으로 파일에 대한 액세스를 시도하는 경우이를 스트림으로 열고이 지원 라이브러리를 사용하여 exif 데이터를 읽을 수 있습니다. https://android-developers.googleblog.com/2016/12/introducing-the-exifinterface-support-library.html – startoftext