I am making an alarm clock app and I wanted to test AlarmManager Class to schedule an event for me to perform when the app is closed not a regular OS alarm my own custom alarm thats why I'm not using AlarmClock class. for some reason OnReceive() method in my class that extends BroadcastReceiver is never getting called? I hope you guys can help. Also if there is a better tecnique to implement a scheduled interupt i would be glad to know, id like youre input. also note i have tried putting the receiver tag like this
<receiver android:name=".MyReciever"></receiver>
in between the application tags in my manifest but i get same results, also i Know that i mispelled Reciever in my Class definition but i kept in consistent throughout project.
here is my maifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="Alarm_clock_app.Alarm_clock_app" android:versionCode="1" android:versionName="1.0" android:installLocation="auto">
<uses-sdk android:minSdkVersion="16" />
<application android:label="Alarm_clock_app">
<activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:theme="@android:style/Theme.Translucent" />
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<uses-permission android:name="android.permission.VIBRATE" />
</manifest>
this is the method i call in my main activity inside onCreate(), this method is inside my main activity class
public void sched()
{
Intent intent = new Intent(this,typeof(MyReciever));//create an intent with our custom broadcast reciever
PendingIntent pIntent = PendingIntent.GetService(this,0,intent,PendingIntentFlags.UpdateCurrent);//get a pending intent made from our intent
AlarmManager alarM = (AlarmManager) GetSystemService(AlarmService);//get alarm manager
alarM.Set(AlarmType.RtcWakeup, DateTime.Now.Millisecond + 5 * 1000, pIntent);//schedule the alarm for 5,000 ms from now
}
this is my class that extends broadcast reciever
[BroadcastReceiver(Enabled = true, Process = ":remote")]
class MyReciever: BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
Console.WriteLine("alarm has occuered");
}
}
Try to change first argument of alarm. set method and/or to use Calendar date setting:
{Calendar cal = Calendar.getInstance();
cal.add(Calendar.SECOND, 5);
alarM.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pIntent);}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.