Java 通知gcm 公共类gcminentservice扩展了IntentService{ 公共静态最终整数通知_ID=1; 私有静态最终字符串TAG=“gcminentservice”; 私人通知经理通知经理; 通知建筑商; 公共GCMinentService(

Java 通知gcm 公共类gcminentservice扩展了IntentService{ 公共静态最终整数通知_ID=1; 私有静态最终字符串TAG=“gcminentservice”; 私人通知经理通知经理; 通知建筑商; 公共GCMinentService(,java,android,notifications,Java,Android,Notifications,通知gcm 公共类gcminentservice扩展了IntentService{ 公共静态最终整数通知_ID=1; 私有静态最终字符串TAG=“gcminentservice”; 私人通知经理通知经理; 通知建筑商; 公共GCMinentService(){ 超级(“GCMinentService”); } @凌驾 受保护的手部内容无效(意图){ Bundle extras=intent.getExtras(); GoogleCloudMessaging gcm=GoogleCloudMess

通知gcm
公共类gcminentservice扩展了IntentService{
公共静态最终整数通知_ID=1;
私有静态最终字符串TAG=“gcminentservice”;
私人通知经理通知经理;
通知建筑商;
公共GCMinentService(){
超级(“GCMinentService”);
}
@凌驾
受保护的手部内容无效(意图){
Bundle extras=intent.getExtras();
GoogleCloudMessaging gcm=GoogleCloudMessaging.getInstance(this);
//getMessageType()意图参数必须是您收到的意图
//在你的收音机里。
字符串messageType=gcm.getMessageType(intent);
如果(!extras.isEmpty()){//具有解包的效果
/*
*根据消息类型筛选消息。因为GCM可能
*将来将使用新的消息类型进行扩展,只需忽略
*任何您不感兴趣或不感兴趣的消息类型
*承认。
*/
如果(谷歌云通讯)。
消息类型发送错误。等于(消息类型)){
sendNotification(“发送错误:+extras.toString());
}否则如果(谷歌云信息)。
消息类型已删除。等于(消息类型)){
sendNotification(“服务器上已删除的邮件:”+
附加的toString());
//如果是常规GCM消息,请执行一些操作。
}否则如果(谷歌云信息)。
MESSAGE_TYPE_MESSAGE.equals(messageType)){
//此循环表示正在执行某些工作的服务。

对于(int i=0;i检查远程mysql是否在服务器上正确连接,或者chk srvices logscreate browser key而不是服务器key。只需创建它而不插入任何内容,并在项目中使用该key。
public class GcmIntentService extends IntentService {
public static final int NOTIFICATION_ID = 1;
 private static final String TAG = "GcmIntentService";
private NotificationManager mNotificationManager;
NotificationCompat.Builder builder;

public GcmIntentService() {
    super("GcmIntentService");
}

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    // The getMessageType() intent parameter must be the intent you received
    // in your BroadcastReceiver.
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) {  // has effect of unparcelling Bundle
        /*
         * Filter messages based on message type. Since it is likely that GCM
         * will be extended in the future with new message types, just ignore
         * any message types you're not interested in, or that you don't
         * recognize.
         */
        if (GoogleCloudMessaging.
                MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            sendNotification("Send error: " + extras.toString());
        } else if (GoogleCloudMessaging.
                MESSAGE_TYPE_DELETED.equals(messageType)) {
            sendNotification("Deleted messages on server: " +
                    extras.toString());
        // If it's a regular GCM message, do some work.
        } else if (GoogleCloudMessaging.
                MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            // This loop represents the service doing some work.
            for (int i=0; i<5; i++) {
                Log.i(TAG, "Working... " + (i+1)
                        + "/5 @ " + SystemClock.elapsedRealtime());
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                }
            }
            Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
            // Post notification of received message.
            sendNotification(extras.getString("Notice"));
            Log.i(TAG, "Received: " + extras.toString());
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

// Put the message into a notification and post it.
// This is just one simple example of what you might choose to do with
// a GCM message.
private void sendNotification(String msg) {
    mNotificationManager = (NotificationManager)
            this.getSystemService(Context.NOTIFICATION_SERVICE);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, Notification.class),PendingIntent.FLAG_UPDATE_CURRENT );
    //PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(),
            //0, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
   // .setSmallIcon(R.drawable.ic_stat_gcm)
    .setContentTitle("MobileHealth")
    .setSmallIcon(R.drawable.ic_launcher)
    .setStyle(new NotificationCompat.BigTextStyle()
    .bigText(msg))
    .setContentText(msg);

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}