int permissionCheck = ContextCompat.checkSelfPermission(getActivity(),Manifest.permission.READ_SMS); if (permissionCheck != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),Manifest.permission.READ_SMS)) { // 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(getActivity(),new String[]{Manifest.permission.READ_SMS},REQUEST_SMS); // REQUEST_SMS is an // app-defined int constant. The callback method gets the // result of the request. } }else { tMgr = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE); }
现在我的应用程序启动,很快我的软件包安装程序崩溃了.这是日志
03-23 12:12:13.618 8949-8949/com.androID.packageinstaller E/AndroIDRuntime: FATAL EXCEPTION: main Process: com.androID.packageinstaller,PID: 8949 theme: themes:{default=overlay:system,iconPack:system,FontPkg:system,com.androID.systemUI=overlay:system} java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androID.packageinstaller/com.androID.packageinstaller.permission.ui.GrantPermissionsActivity}: java.lang.NullPointerException: Attempt to get length of null array at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:2450) at androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2520) at androID.app.ActivityThread.-wrap11(ActivityThread.java) at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:1363) at androID.os.Handler.dispatchMessage(Handler.java:102) at androID.os.Looper.loop(Looper.java:148) at androID.app.ActivityThread.main(ActivityThread.java:5466) at java.lang.reflect.Method.invoke(Native Method) at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.NullPointerException: Attempt to get length of null array at com.androID.packageinstaller.permission.ui.GrantPermissionsActivity.computePermissionGrantState(GrantPermissionsActivity.java:293) at com.androID.packageinstaller.permission.ui.GrantPermissionsActivity.updateDefaultResults(GrantPermissionsActivity.java:343) at com.androID.packageinstaller.permission.ui.GrantPermissionsActivity.onCreate(GrantPermissionsActivity.java:100) at androID.app.Activity.performCreate(Activity.java:6251) at androID.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:2403) at androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2520) at androID.app.ActivityThread.-wrap11(ActivityThread.java) at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:1363) at androID.os.Handler.dispatchMessage(Handler.java:102) at androID.os.Looper.loop(Looper.java:148) at androID.app.ActivityThread.main(ActivityThread.java:5466) at java.lang.reflect.Method.invoke(Native Method) at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:616)
我认为当应用程序尝试显示用于请求权限的UI时,程序包安装程序会崩溃.
我已经添加了< uses-permission androID:name =“androID.permission.READ_SMS”/>在我的清单中
<uses-permission androID:name="androID.permission.READ_SMS" androID:maxsdkVersion="22" />
正如我在评论中提到的,除了运行时请求之外,Marshmallow及以上版本仍然需要此清单权限.从权限元素中删除maxsdkVersion属性.
总结以上是内存溢出为你收集整理的请求权限READ_SMS后,包安装程序在Android M中崩溃全部内容,希望文章能够帮你解决请求权限READ_SMS后,包安装程序在Android M中崩溃所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)