当我使用 public @NonNull Bitmap loadThumbnail(@NonNull Uri uri, @NonNull Size size,@Nullable CancellationSignal signal)
方法时,
它总是显示此错误
2019-12-24 16:16:10.661 30299-30299/com.shaheen.filemanager E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.shaheen.filemanager, PID: 30299
java.lang.NoSuchMethodError: No virtual method loadThumbnail(Landroid/net/Uri;Landroid/util/Size;Landroid/os/CancellationSignal;)Landroid/graphics/Bitmap; in class Landroid/content/ContentResolver; or its super classes (declaration of 'android.content.ContentResolver' appears in /system/framework/framework.jar)
at com.shaheen.filemanager.activities.FileSelectActivity.onCreate(FileSelectActivity.kt:38)
at android.app.Activity.performCreate(Activity.java:7036)
at android.app.Activity.performCreate(Activity.java:7027)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6501)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
还有其他方法可以解决此错误吗?
我的代码如下:
val bitmap = applicationContext.contentResolver.loadThumbnail(uri,Size(5,5),null)
thumbnail_image_view.setImageBitmap(bitmap)
screenshot_image_view.setImageBitmap(bitmap)
答案 0 :(得分:1)
方法loadThumbnail()
仅在Android 10.0的API级别29中添加,因此它在较低版本中不起作用。
但是,您可以将图片加载器库(例如Picasso或glide)与uri
一起使用。
答案 1 :(得分:0)
您是否尝试过传递活动或片段的上下文而不是应用程序上下文?