Android Google Maps API API23 上的安全异常

2023-12-05

这是我得到的例外:

java.lang.SecurityException
:com.google.android.gms.DynamiteModulesB line 50297 in az.c()
my location requires permission ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION


az : android.support.transition.TransitionIcs
c() : android.support.transition.TransitionIcs$CompatListener mCompatListener

com.google.maps.api.android.lib6.impl
:com.google.android.gms.DynamiteModulesB line 50297 in az.c()
com.google.android.gms.maps.internal
:com.google.android.gms.DynamiteModulesB line 274 in l.onTransact()
android.os
Binder.java line 387 in Binder.transact()
com.google.android.gms.maps.internal
line -1 IGoogleMapDelegate$zza$a.setMyLocationEnabled()
com.google.android.gms.maps
line -1 GoogleMap.setMyLocationEnabled()
SourceFile line 214 in MapsActivity.onMapReady()
com.google.android.gms.maps
line -1 MapFragment$a$1.zza()
com.google.android.gms.maps.internal
line -1 zzo$zza.onTransact()
android.os
Binder.java line 387 in Binder.transact()
com.google.android.gms.maps.internal
:com.google.android.gms.DynamiteModulesB line 82 in bw.a()
com.google.maps.api.android.lib6.impl
:com.google.android.gms.DynamiteModulesB line 1805 in bf.run()
android.os
Handler.java line 739 in Handler.handleCallback()
android.os
Handler.java line 95 in Handler.dispatchMessage()
android.os
Looper.java line 234 in Looper.loop()
android.app
ActivityThread.java line 5526 in ActivityThread.main()
java.lang.reflect
Method.java line -2 in Method.invoke()
com.android.internal.os
ZygoteInit.java line 726 in ZygoteInit$Method

我有一个使用 getMap 方法的地图片段,如果在设备中启用了位置,则显示用户的当前位置,但有时它会给我上述异常,我在代码中添加了一些位置权限检查,但我不知道是什么我错过了...

感谢帮助

这是一些附加数据:

compileSdkVersion 25
minSdkVersion 15
targetSdkVersion 25

    @Override
public void onMapReady(final GoogleMap map) {
    map.setMyLocationEnabled(true);
}

将这些添加到您的AndroidManifest.xml before application tag

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

另外对于Android版本> = 23,您需要在运行时请求位置权限

     if (ContextCompat.checkSelfPermission(YourActivity.this,
                            Manifest.permission.ACCESS_FINE_LOCATION)
                            != PackageManager.PERMISSION_GRANTED
                            &&
                            ContextCompat.checkSelfPermission(YourActivity.this,
                                    Manifest.permission.ACCESS_COARSE_LOCATION)
                                    != PackageManager.PERMISSION_GRANTED) {
                        askForLocationPermissions();
      } else {
          //do your work
     }

And

private void askForLocationPermissions() {

        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.ACCESS_FINE_LOCATION)) {

            new android.support.v7.app.AlertDialog.Builder(this)
                    .setTitle("Location permessions needed")
                    .setMessage("you need to allow this permission!")
                    .setPositiveButton("Sure", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            ActivityCompat.requestPermissions(YourActivity.this,
                                    new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                                    LOCATION_PERMISSION_REQUEST_CODE);
                        }
                    })
                    .setNegativeButton("Not now", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
//                                        //Do nothing
                        }
                    })
                    .show();

            // Show an expanation to the user *asynchronously* -- don't block
            // this thread waiting for the user's response! After the user
            // sees the explanation, try again to request the permission.

        } else {

            // No explanation needed, we can request the permission.
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                    LOCATION_PERMISSION_REQUEST_CODE);

            // MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION is an
            // app-defined int constant. The callback method gets the
            // result of the request.
        }
    }

Also

@Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
        switch (requestCode) {
            case LOCATION_PERMISSION_REQUEST_CODE:
                if (isPermissionGranted(permissions, grantResults, Manifest.permission.ACCESS_FINE_LOCATION)) {
                    //Do you work
                } else {
                    Toast.makeText(this, "Can not proceed! i need permission" , Toast.LENGTH_SHORT).show();
                }
                break;
        }
    }

And

   public static boolean isPermissionGranted(@NonNull String[] grantPermissions, @NonNull int[] grantResults,
                                              @NonNull String permission) {
        for (int i = 0; i < grantPermissions.length; i++) {
            if (permission.equals(grantPermissions[i])) {
                return grantResults[i] == PackageManager.PERMISSION_GRANTED;
            }
        }
        return false;
    }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android Google Maps API API23 上的安全异常 的相关文章

  • Phonegap(应用程序错误...发生网络错误)

    我已经使用phonegap 创建了一个版本 在index html 文件中 我编写了一个简单的iframe 用于加载网站 当我从phonegap获取本地url时它就起作用了 但如果我将整个构建作为 zip 文件上传到 PhoneGap 中
  • ndk-build error.opencv2/core/core.hpp:没有这样的文件或目录

    我在 Android 中使用 OpenCV Nonfree 模块时遇到问题 我读了这个教程https sites google com site wghsite technical notes sift surf opencv androi
  • 如何从Slog中查看日志

    如何查看 Slog API 生成的日志 是否有任何选项可以查看系统缓冲区中的日志 我的意思是查看我们使用的无线电缓冲区的日志 adb logcat b 无线电 而这个日志是由Android的Log类生成的 Slog API 的输出在哪里 怎
  • 与通用地图相比,MapView 的分辨率较差

    我刚刚收到 HTC Desire 进行测试 我注意到 残留在小于整个屏幕的框架中的地图视图不如通用地图应用程序那么清晰 有什么办法解决这个问题吗 您应该使用 API 级别 4 或更高级别编译应用程序 然后在 AndroidManifest
  • Android,如何从 XML 布局添加 Google 地图选项?

    我有一个包含 MapView 的片段 我已将此视图添加到 XML 文件中 如下所示
  • Android 中图像字节表示的每像素字节数

    我目前正在编写一个Android应用程序 需要在其中使用OCR 为了实现这一点 我将 Tesseract 与tesseract android tools 项目 http code google com p tesseract androi
  • 突出显示列表视图项目

    我需要在触摸列表视图项目时突出显示它并保持突出显示状态 我尝试了我发现的一切 但没有任何效果 这是我的代码 这是列表视图
  • 如何连接到Google Play服务并加载排行榜

    我想将我的游戏与 Google Play 服务连接 我已阅读有关 Android 开发人员的文档 并尝试遵循输入数字示例 但仍然无法加载排行榜 我有导入baseGameUtils 但我使用andengine 所以我没有使用来自谷歌的exte
  • 将清除会话标志设置为 FALSE 后,我丢失了已发布的值

    有人有一个合乎逻辑的解释为什么尽管我有clear session flage false当我未连接到经纪商时 我没有收到我订阅的更新的已发布消息 将 aore提到的标志设置为 false 后 我运行了我的应用程序 并且我不断向主题发布一些值
  • Android Studio APK META-INF/BCKEY.DSA 中复制的重复文件

    我的代码构建得很好 但是当我尝试在调试中运行它时 出现以下错误 Error Execution failed for task app transformResourcesWithMergeJavaResForDebug com andro
  • 通过配置更改保留 CoroutineScope 的干净方法,无需 ViewModel

    我知道建议是在我们的 Activity 中使用 ViewModel 这样我们就可以使用它viewModelScope 由于 ViewModel 的寿命比 Activity 的寿命长 因此我们不必取消以下作业activity onDestro
  • DialogFragment 关闭事件

    我需要处理 DialogFragment 的结尾 在调用 dismiss 之后 例如 我会在关闭后 包含 片段的活动内显示一个 toast 我该如何处理该事件 覆盖onDismiss 在你的DialogFragment中 或者使用setOn
  • Android:从 PhoneGap 应用打开 Play 商店链接

    我想从我的phonegap 3 4 应用程序打开一个指向Google Play 商店的链接 呼唤market details id com google android apps maps导致 ActivityNotFoundExcepti
  • 用户通过 firebase 动态链接安装应用程序并在应用程序抽屉上打开应用程序后,如何获得深层链接?

    我正在使用 firebase 动态链接邀请朋友使用我的应用程序 一切都很好 单击邀请链接会将我带到 Playstore 当我安装应用程序并等待其完成时 Playstore 会向我显示 继续 按钮 当我单击此按钮时 应用程序将打开 并且我会收
  • 活动中列表视图中的粘滞行

    我的列表视图中只有一行应该是粘性的 而不是粘性标题中带有字母的部分或部分 我真的很感激任何关于列表视图在活动中粘性一行而不是片段的帮助 我该怎么做 我真的很感谢任何帮助 提前致谢 使用如下代码 class MyAsyncTask exten
  • Android - 检测视图上的双击和三次点击

    我一直在尝试构建一个可以检测双敲击和三敲击的敲击检测器 在我的努力失败后 我在网上搜索了很长时间以找到可以使用的东西 但没有运气 奇怪的是 像这样的图书馆如此稀缺 有什么帮助吗 你可以尝试这样的事情 尽管我通常建议不要使用三次点击作为一种模
  • 带有工具提示的搜索栏 android

    Hi All 我正在尝试使用工具提示自定义 android 搜索栏 如给定的图像 有没有办法在搜索栏中添加带有拇指的文本视图 或任何其他想法 Thanks 我们可以通过拇指的界限来做到这一点 并在seekbar的progressChange
  • 致命异常:GoogleApiHandler

    在我的项目中 我使用货币化服务 Vungle AppLovin 当我尝试加载广告时 出现此异常 E AndroidRuntime 致命异常 GoogleApiHandler 进程 kz ikar PID 3673 java lang NoS
  • AndroidAnnotations 和 Dagger

    我正在尝试使用 Dagger 注入 Android 带注释的 Activity java lang IllegalArgumentException No inject registered for members com app serv
  • 将主题应用到 v7 支持操作栏

    我正在使用support v7库来实现ActionBar在我的应用程序中 我的styles xml file

随机推荐