2016-03-16 31 views
-2
This condition is for gcm notification get activity 



public class GCMNotificationIntentService extends IntentService { 
    // Sets an ID for the notification, so it can be updated 
    public static final int notifyID = 9001; 
    NotificationCompat.Builder builder; 

    int count, i; 

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

    @Override 
    protected void onHandleIntent(Intent intent) { 
     Bundle extras = intent.getExtras(); 
     GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); 

     String messageType = gcm.getMessageType(intent); 

     if (!extras.isEmpty()) { 
      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()); 
      } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE 
        .equals(messageType)) { 
       sendNotification("Message Received from Google GCM Server:\n\n" 
         + extras.get(ApplicationConstants.MSG_KEY)); 
      } 
     } 
     GcmBroadcastReceiver.completeWakefulIntent(intent); 
    } 

    private void sendNotification(String msg) { 

     Log.d("Notification-msssg", msg); 
     Log.d("Notification-msssg", msg); 

     if (msg.equals("Property")) { 

      Log.d("Notification-msssg", msg + "chat"); 
      Log.d("Notification-msssgchat", msg); 

      Intent resultIntent = new Intent(this, MessageListActivity.class); 
      resultIntent.putExtra("msg", msg); 
      PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 
        0, resultIntent, PendingIntent.FLAG_ONE_SHOT); 

      NotificationCompat.Builder mNotifyBuilder; 
      NotificationManager mNotificationManager; 

      mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

      mNotifyBuilder = new NotificationCompat.Builder(this) 
        .setContentTitle("CPO") 
        .setContentText("You've received new message.") 
        .setSmallIcon(R.drawable.iconnotifi); 
      // Set pending intent 
      mNotifyBuilder.setContentIntent(resultPendingIntent); 

      // Set Vibrate, Sound and Light 
      int defaults = 0; 
      defaults = defaults | Notification.DEFAULT_LIGHTS; 
      defaults = defaults | Notification.DEFAULT_VIBRATE; 
      defaults = defaults | Notification.DEFAULT_SOUND; 

      mNotifyBuilder.setDefaults(defaults); 

      // Set the content for Notification 
      mNotifyBuilder 
        .setContentText("New message on your property, Check it"); 
      // Set autocancel 
      mNotifyBuilder.setAutoCancel(true); 
      // Post a notification 

      mNotificationManager.notify(notifyID, mNotifyBuilder.build()); 

      // mNotifyBuilder.build().sound = Uri 
      // .parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" 
      // + getPackageName() + "/raw/kalimba"); 

      // Uri uri = 
      // RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); 
      // 
      // builder.setSound(uri); 

     } else { 

      Log.d("Notification-msssg", msg + "property"); 
      Log.d("Notification-msssgproperty", msg); 

      Intent resultIntent = new Intent(this, ResidencialActivity.class); 
      resultIntent.putExtra("msg", msg); 
      PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 
        0, resultIntent, PendingIntent.FLAG_ONE_SHOT); 

      NotificationCompat.Builder mNotifyBuilder; 
      NotificationManager mNotificationManager; 

      mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

      mNotifyBuilder = new NotificationCompat.Builder(this) 
        .setContentTitle("CPO") 
        .setContentText("You've new Property to check") 
        .setSmallIcon(R.drawable.iconnotifi); 
      // Set pending intent 
      mNotifyBuilder.setContentIntent(resultPendingIntent); 

      // Set Vibrate, Sound and Light 
      int defaults = 0; 
      defaults = defaults | Notification.DEFAULT_LIGHTS; 
      defaults = defaults | Notification.DEFAULT_VIBRATE; 
      defaults = defaults | Notification.DEFAULT_SOUND; 

      mNotifyBuilder.setDefaults(defaults); 

      // Set the content for Notification 
      mNotifyBuilder.setContentText("New Property Added, Check it"); 
      // Set autocancel 
      mNotifyBuilder.setAutoCancel(true); 
      // Post a notification 

      mNotificationManager.notify(notifyID, mNotifyBuilder.build()); 

     } 

    } 
} 

如果條件不能正常工作,我不知道什麼問題,它總是在條件else部分去,校驗值是正確的,但如果沒有部分PIC ..但是當我把它改成msg.equals(味精),比它圖片的部分..如果條件不能正常工作總是挑別人的一部分

這個檢查是爲了改變開始活動的通知獲取,我必須活動通知獲取活動..

針對此問題的任何解決方案...

+0

我將值更改爲1或2也不過它仍然不起作用 –

+0

什麼是你的味精串? –

+0

@FebiMathew msg string是來自通知的消息,它是「Property」或其他消息是「Message」... –

回答

0

您是c alling方法爲sendNotification(「Send error:」+ extras.toString());.所以msg字符串包含「發送錯誤:......」。那麼它如何等於「財產」?

+0

thanx先生...我的問題現在解決了... –

0

你認爲msg應該等於「Property」在哪裏?

您發送以下3個消息:

sendNotification("Send error: " + extras.toString()); 
sendNotification("Deleted messages on server: + extras.toString()); 
sendNotification("Message Received from Google GCM Server:\n\n" 
         + extras.get(ApplicationConstants.MSG_KEY)); 

有您發送值「屬性」像這樣沒有任何一行代碼:

sendNotification("Property");