Android Question alarm

catyinwong

Active Member
Licensed User
Longtime User
Trying to start an alarm with the following code

B4X:
 Sub SetAlarm(Hour As Int, Minutes As Int)
   Dim i As Intent
   i.Initialize("android.intent.action.SET_ALARM", "")
   i.PutExtra("android.intent.extra.alarm.HOUR", Hour)
   i.PutExtra("android.intent.extra.alarm.MINUTES", Minutes)
   i.PutExtra("android.intent.extra.alarm.SKIP_UI", False)
   StartActivity(i)
End Sub

And a request for permission is also added in the manifest editor:
B4X:
AddPermission(com.android.alarm.permission.SET_ALARM )

But when it runs, it still comes with a Permission Denial error. How to solve it?
 

catyinwong

Active Member
Licensed User
Longtime User
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Error occurred on line: 42 (Main)
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.SET_ALARM flg=0x20000 cmp=com.sec.android.app.clockpackage/.alarm.activity.AlarmCTSHandleActivity (has extras) } from ProcessRecord{34aa975 9974:b4a.example/u0a321} (pid=9974, uid=10321) requires com.android.alarm.permission.SET_ALARM
at android.os.Parcel.readException(Parcel.java:1959)
at android.os.Parcel.readException(Parcel.java:1905)
at android.app.IActivityManager$Stub$Proxy.startActivity(IActivityManager.java:4894)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1618)
at android.app.Activity.startActivityForResult(Activity.java:4564)
at android.app.Activity.startActivityForResult(Activity.java:4522)
at android.app.Activity.startActivity(Activity.java:4883)
at android.app.Activity.startActivity(Activity.java:4851)
at anywheresoftware.b4a.keywords.Common.StartActivity(Common.java:848)
at b4a.example.main._activity_click(main.java:400)
at b4a.example.main._activity_resume(main.java:431)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:735)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:357)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
 
Upvote 0
Top