gpt4 book ai didi

android - 没有静态方法 canDrawOverlays

转载 作者:行者123 更新时间:2023-11-29 01:15:36 27 4
gpt4 key购买 nike

我注意到有人在使用我的应用程序时报告了 Google Developer Console 记录的崩溃:

java.lang.NoSuchMethodError: No static method canDrawOverlays(Landroid/content/Context;)Z in class Landroid/provider/Settings; or its super classes (declaration of 'android.provider.Settings' appears in /system/framework/framework.jar)
at com.pack.MainActivity.checkDrawOverlayPermission(MainActivity.java:311)
at com.pack.MainActivity.onCreate(MainActivity.java:127)
at android.app.Activity.performCreate(Activity.java:6033)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2288)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2397)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1310)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5268)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697)

canDrawOverlays 是一种 API 23+ 方法,我是这样使用它的:

 /** code to post/handler request for permission */
public final static int REQUEST_CODE = 100; /*(see edit II)*/

@SuppressLint("NewApi")
public void checkDrawOverlayPermission() {
/** check if we already have permission to draw over other apps */
if (!Settings.canDrawOverlays(this)) {
/** if not construct intent to request permission */
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
/** request permission via start activity for result */
startActivityForResult(intent, REQUEST_CODE);
}
}

我的 MainActivity 中有这个:

checkDrawOverlayPermission();

Android 5.1 崩溃的设备

如何确保我的应用程序可以在 Android 5.1 上运行? (API 22 及以下)谁没有 API 23 及更高版本提供的这种方法?

最佳答案

检查运行代码的设备的当前 API。如果它 >= 23,你可以使用代码

if(Build.VERSION.SDK_INT >= 23) {
// if (!Settings.canDrawOverlays(this)) {
//
} else {
// another similar method that supports device have API < 23
}

关于android - 没有静态方法 canDrawOverlays,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39911130/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com