2014-09-05 25 views
0

我試圖重構gcmRegisterer從一個活動到一個類。PendingIntent可以得到一個類作爲參數嗎?

但現在我看到了sendPushMessage方法。

請問GcmRegisterer必須是活動嗎?

爲了發送PendingIntent?

private void sendNotification(String msg) { 
    mNotificationManager = (NotificationManager) this 
      .getSystemService(Context.NOTIFICATION_SERVICE); 

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, 
      new Intent(this, GcmRegisterer.class), 0); 

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

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

回答

0

。但是您也可以選擇使用PendingIntent.getBroadcast發送廣播,您可以使用BroadcastReceiverPendingIntent.getService來收聽廣播以啓動服務。

使用哪一個取決於用戶點擊通知時想要發生的情況。

0

是的,你必須做的一類GcmRegisterer的這是因爲你使用PendingIntent.getActivity是的,它需要有一個活動延伸活動

相關問題