应用程序运行时不要创建通知

时间:2015-03-09 16:35:19

标签: android

当我收到GCM的通知时,我怎么知道应用正在运行? 因为如果我的应用程序正在运行,请不要创建通知。

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_MESSAGE.equals(messageType)) {
            // if app not running 
            sendNotification();
            // if app is running 
            Intent intent2 = new Intent(
                    Constants.BroadcastAction.DISPLAY_REQUEST);
            sendBroadcast(intent2);

        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

0 个答案:

没有答案