Created
February 7, 2014 11:41
-
-
Save deanpanayotov/8861248 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A simple example. Receiver is declared as inner class of MainActivity. "receiver" block should be added within the "application" block. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<receiver android:name="com.example.test.MainActivity$AlarmReceiver" > | |
</receiver> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final void setAlarm(int seconds) { | |
Intent intent = new Intent(MainActivity.this, AlarmReceiver.class); | |
pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, | |
intent, 0); | |
((AlarmManager) getSystemService(ALARM_SERVICE)).set(AlarmManager.RTC, | |
System.currentTimeMillis() + seconds * 1000, pendingIntent); | |
Toast.makeText(MainActivity.this, | |
"Timer set to " + seconds + " seconds.", Toast.LENGTH_SHORT) | |
.show(); | |
} | |
public static class AlarmReceiver extends BroadcastReceiver { | |
public void onReceive(Context context, Intent intent) { | |
Log.d("-", "Receiver4"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment