Thebestshoot
Thebestshoot

Reputation: 208

Permission denied while trying to call alarm clock

I was trying to write an app which needs the user to set an alarm. I tried to call the alarm clock with the intent using following code

    Intent i = new Intent(AlarmClock.ACTION_SET_ALARM);
    i.putExtra(AlarmClock.EXTRA_MESSAGE, "MMTS train to catch rush up ...");
    i.putExtra(AlarmClock.EXTRA_HOUR, d.getHours());
    i.putExtra(AlarmClock.EXTRA_MINUTES, d.getMinutes());
    activity.startActivity(i);

exception is

    Permission Denial: starting Intent { act=android.intent.action.SET_ALARM
    cmp=com.android.deskclock/.HandleSetAlarm (has extras) } from
    ProcessRecord{414d1210 812:com.arjun.android.mmts/10041} (pid=812, uid=10041)
    requires com.android.alarm.permission.SET_ALARM

I am working on Android 4.0 API version 14.

I added the line

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

in my manifest file, even after that it was not working.

Upvotes: 1

Views: 5766

Answers (1)

Mark Allison
Mark Allison

Reputation: 21909

You need to declare the offending permission in your manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="you.package"
    android:versionCode="1"
    android:versionName="1.0" >

    .
    .
    .
    <uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
    .
    .
    .
</manifest>

Upvotes: 10

Related Questions