應 K.Top 站長領航大大的提議,公開 Java code 的部分讓大家共襄盛舉...
package com.winton.gcm; import android.content.BroadcastReceiver; import android.content.Intent; import android.content.Context; import android.app.Activity; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.R; import android.net.Uri; import android.app.Notification.Builder; import android.provider.Settings; public class ActivityReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent receivedIntent) { Notification.Builder builder; String newMessage = receivedIntent.getExtras().getString("message"); int icon = R.drawable.stat_notify_chat; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(); notificationIntent.setClassName(context, "com.embarcadero.firemonkey.FMXNativeActivity"); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); Notification.Builder mBuilder = new Notification.Builder(context) .setAutoCancel(true) .setWhen(when) .setSmallIcon(icon) .setContentTitle("GCM Notification") .setContentText(newMessage) .setContentIntent(pendingIntent) .setSound(Settings.System.DEFAULT_NOTIFICATION_URI); notificationManager.notify(0, mBuilder.build()); } } |
to be continued..
文章標籤
全站熱搜
留言列表