设置闹钟提醒时在华为手机上报了以下错误。
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.SET_ALARM cmp=com.android.deskclock/.HandleSetAlarm (has extras) } from ProcessRecord{8845118 32102:com.xxx.xxx.xx/u0a83} (pid=32102, uid=10083) requires com.android.alarm.permission.SET_ALARM
at android.os.Parcel.readException(Parcel.java:1602)
at android.os.Parcel.readException(Parcel.java:1555)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2659)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1518)
at android.app.Activity.startActivityForResult(Activity.java:4030)
at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:676)
at android.app.Activity.startActivityForResult(Activity.java:3984)
at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:663)
at android.app.Activity.startActivity(Activity.java:4314)
at android.app.Activity.startActivity(Activity.java:4282)
at com.todo.list.gao.activity.CreateATodoActivity.createAlarm(CreateATodoActivity.java:791)
at com.todo.list.gao.activity.CreateATodoActivity.onViewClicked(CreateATodoActivity.java:593)
at com.todo.list.gao.activity.CreateATodoActivity_ViewBinding$8.doClick(CreateATodoActivity_ViewBinding.java:138)
at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:18)
at android.view.View.performClick(View.java:5264)
at android.view.View$PerformClick.run(View.java:21297)
at android.os.Handler.handleCallback(Handler.java:743)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5621)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)
从提示看是缺少com.android.alarm.permission.SET_ALARM权限,清单文件中已经添加了 <uses-permission android:name="android.permission.SET_ALARM" />
权限,原因可能是华为手机对Android系统修改了原原有的权限定义,添加上以下两个权限后,问题修复。
<uses-permission android:name="android.permission.SET_ALARM" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>