我有这个getPath
方法,它有效,但我想摆脱警告,因为它说该managedQuery
方法已被弃用。如何getPath
在没有警告的情况下实施这种确切的方法?谢谢你。
public String getPath(Uri uri) {
System.out.println("IM IN getPath");
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
编辑:我现在收到这个 logcat 错误:
10-23 07:19:14.080: E/ActivityThread(594): Activity com.android.internal.app.ChooserActivity has leaked IntentReceiver com.android.internal.app.ResolverActivity$1@416c9560 that was originally registered here. Are you missing a call to unregisterReceiver()?
10-23 07:19:14.080: E/ActivityThread(594): android.app.IntentReceiverLeaked: Activity com.android.internal.app.ChooserActivity has leaked IntentReceiver com.android.internal.app.ResolverActivity$1@416c9560 that was originally registered here. Are you missing a call to unregisterReceiver()?
10-23 07:19:14.080: E/ActivityThread(594): at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:763)
10-23 07:19:14.080: E/ActivityThread(594): at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:567)
10-23 07:19:14.080: E/ActivityThread(594): at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1043)
10-23 07:19:14.080: E/ActivityThread(594): at android.app.ContextImpl.registerReceiver(ContextImpl.java:1030)
10-23 07:19:14.080: E/ActivityThread(594): at android.app.ContextImpl.registerReceiver(ContextImpl.java:1024)
10-23 07:19:14.080: E/ActivityThread(594): at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:341)
10-23 07:19:14.080: E/ActivityThread(594): at com.android.internal.content.PackageMonitor.register(PackageMonitor.java:65)
10-23 07:19:14.080: E/ActivityThread(594): at com.android.internal.app.ResolverActivity.onCreate(ResolverActivity.java:99)
10-23 07:19:14.080: E/ActivityThread(594): at com.android.internal.app.ChooserActivity.onCreate(ChooserActivity.java:53)
10-23 07:19:14.080: E/ActivityThread(594): at android.app.Activity.performCreate(Activity.java:4465)
10-23 07:19:14.080: E/ActivityThread(594): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
10-23 07:19:14.080: E/ActivityThread(594): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
10-23 07:19:14.080: E/ActivityThread(594): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
10-23 07:19:14.080: E/ActivityThread(594): at android.app.ActivityThread.access$600(ActivityThread.java:123)
10-23 07:19:14.080: E/ActivityThread(594): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
10-23 07:19:14.080: E/ActivityThread(594): at android.os.Handler.dispatchMessage(Handler.java:99)
10-23 07:19:14.080: E/ActivityThread(594): at android.os.Looper.loop(Looper.java:137)
10-23 07:19:14.080: E/ActivityThread(594): at android.app.ActivityThread.main(ActivityThread.java:4424)
10-23 07:19:14.080: E/ActivityThread(594): at java.lang.reflect.Method.invokeNative(Native Method)
10-23 07:19:14.080: E/ActivityThread(594): at java.lang.reflect.Method.invoke(Method.java:511)
10-23 07:19:14.080: E/ActivityThread(594): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-23 07:19:14.080: E/ActivityThread(594): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-23 07:19:14.080: E/ActivityThread(594): at dalvik.system.NativeStart.main(Native Method)