Last active
December 14, 2015 05:29
-
-
Save tsmsogn/5036070 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <?xml version="1.0" encoding="utf-8"?> | |
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
| package="com.tsmsogn.samplereceiver" android:versionCode="4" | |
| android:versionName="1.3"> | |
| <uses-sdk android:minSdkVersion="7" /> | |
| <application android:icon="@drawable/icon" android:label="@string/app_name"> | |
| <receiver android:name=".Receiver"> | |
| <intent-filter> | |
| <action android:name="android.intent.action.BOOT_COMPLETED" /> | |
| <action android:name="com.android.vending.INSTALL_REFERRER" /> | |
| </intent-filter> | |
| </receiver> | |
| <receiver android:name=".Echo"></receiver> | |
| </application> | |
| <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> | |
| </manifest> |
This file contains hidden or 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
| package com.tsmsogn.samplereceiver; | |
| import android.app.Notification; | |
| import android.app.NotificationManager; | |
| import android.app.PendingIntent; | |
| import android.content.BroadcastReceiver; | |
| import android.content.Context; | |
| import android.content.Intent; | |
| import android.widget.Toast; | |
| public class Echo extends BroadcastReceiver { | |
| @Override | |
| public void onReceive(Context context, Intent intent) { | |
| Toast.makeText(context, "Echo", Toast.LENGTH_SHORT).show(); | |
| } | |
| } |
This file contains hidden or 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
| package com.tsmsogn.samplereceiver; | |
| import android.app.AlarmManager; | |
| import android.app.PendingIntent; | |
| import android.content.BroadcastReceiver; | |
| import android.content.Context; | |
| import android.content.Intent; | |
| import android.os.SystemClock; | |
| import android.widget.Toast; | |
| public class Receiver extends BroadcastReceiver { | |
| @Override | |
| public void onReceive(Context context, Intent intent) { | |
| Toast.makeText(context, "Receiver", Toast.LENGTH_SHORT).show(); | |
| PendingIntent operation = PendingIntent.getBroadcast(context, 0, | |
| new Intent(context, Echo.class), 0); | |
| AlarmManager alarmManager = (AlarmManager) context | |
| .getSystemService(Context.ALARM_SERVICE); | |
| // delay | |
| long triggerAtTime = SystemClock.elapsedRealtime() + 20 * 1000; | |
| // interval | |
| long interval = 10 * 1000; | |
| alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, | |
| triggerAtTime, interval, operation); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment