2016-04-04 43 views
0

我想在鎖定屏幕中顯示包含標題,消息和大圖標的GCM通知。圖像和標題將來自我的應用,標題是我的應用的名稱,通知屬於一個信號服務。鎖定屏幕中的GCM通知標題和消息(Android)

我想讓圖片中的通知與下面的通知相同。

enter image description here

這是我的代碼:

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

    String messageType = gcm.getMessageType(intent); 



    GcmBroadcastReceiver.completeWakefulIntent(intent); 
    mNotificationManager = (NotificationManager) this 
      .getSystemService(Context.NOTIFICATION_SERVICE); 

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


    Bitmap small_Icon = getBitmapFromURL((String) extras.get(Config.SMALLICON_KEY)); 
    Bitmap large_Icon = getBitmapFromURL((String) extras.get(Config.LARGEICON_KEY)); 
    Bitmap Poster = getBitmapFromURL((String) extras.get(Config.BIGPICTURE_KEY)); 
    String title = (String) extras.get(Config.TITLE_KEY); 
    String message = (String) extras.get(Config.MESSAGE_KEY); 

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
      this).setSmallIcon((R.drawable.ic_launcher)) 
      .setStyle(new NotificationCompat.BigPictureStyle() 
        .bigPicture(Poster) 
        .setBigContentTitle(title) 
        .setSummaryText(message)) 
      .setContentTitle(title) 
      .setContentText(message) 
      .setLargeIcon(large_Icon); 

    //////// Play Defult Notification Sound //////// 
    Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
    Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); 
    r.play(); 
    //////// End Play Defult Notification Sound //////// 


    mBuilder.setContentIntent(contentIntent); 
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); 
    Log.d(TAG, "Notification sent successfully."); 
} 

任何想法?

回答

1

你打算做的是一個可見的Lock Screen Notification。按照文檔:

設置能見度

您的應用程序可以控制細節在一個安全的鎖屏上顯示通知可見的水平。您致電setVisibility()並指定下列其中一個值:VISIBILITY_PUBLIC,VISIBILITY_SECRET,VISIBILITY_PRIVATE

也找到這個Simple Tutorial on Lollipop Notifications這可能是有幫助的你。希望這可以幫助。祝你好運。