| 1 |
package ${packageName}; |
| 2 |
|
| 3 |
import android.app.Notification; |
| 4 |
import android.app.NotificationManager; |
| 5 |
import android.app.PendingIntent; |
| 6 |
import android.content.BroadcastReceiver; |
| 7 |
import android.content.Context; |
| 8 |
import android.content.Intent; |
| 9 |
import android.widget.Toast; |
| 10 |
<#if applicationPackage??> |
| 11 |
import ${applicationPackage}.R; |
| 12 |
</#if> |
| 13 |
|
| 14 |
public class ${receiverClass} extends BroadcastReceiver { |
| 15 |
public static final String CONTENT_KEY = "contentText"; |
| 16 |
|
| 17 |
public ${receiverClass}() { |
| 18 |
} |
| 19 |
|
| 20 |
@Override |
| 21 |
public void onReceive(Context context, Intent intent) { |
| 22 |
Intent displayIntent = new Intent(context, ${displayActivityClass}.class); |
| 23 |
String text = intent.getStringExtra(CONTENT_KEY); |
| 24 |
Notification notification = new Notification.Builder(context) |
| 25 |
.setSmallIcon(R.mipmap.ic_launcher) |
| 26 |
.setContentTitle(text) |
| 27 |
.extend(new Notification.WearableExtender() |
| 28 |
.setDisplayIntent(PendingIntent.getActivity(context, 0, displayIntent, |
| 29 |
PendingIntent.FLAG_UPDATE_CURRENT))) |
| 30 |
.build(); |
| 31 |
((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(0, notification); |
| 32 |
|
| 33 |
Toast.makeText(context, context.getString(R.string.notification_posted), Toast.LENGTH_SHORT).show(); |
| 34 |
} |
| 35 |
} |