| package ${packageName}; |
| |
| 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; |
| <#if applicationPackage??>import ${applicationPackage}.R;</#if> |
| |
| public class ${receiverClass} extends BroadcastReceiver { |
| public static final String CONTENT_KEY = "contentText"; |
| |
| public ${receiverClass}() { |
| } |
| |
| @Override |
| public void onReceive(Context context, Intent intent) { |
| Intent displayIntent = new Intent(context, ${displayActivityClass}.class); |
| String text = intent.getStringExtra(CONTENT_KEY); |
| Notification notification = new Notification.Builder(context) |
| .setSmallIcon(R.drawable.ic_launcher) |
| .setContentTitle(text) |
| .extend(new Notification.WearableExtender() |
| .setDisplayIntent(PendingIntent.getActivity(context, 0, displayIntent, |
| PendingIntent.FLAG_UPDATE_CURRENT))) |
| .build(); |
| ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(0, notification); |
| |
| Toast.makeText(context, context.getString(R.string.notification_posted), Toast.LENGTH_SHORT).show(); |
| } |
| } |