【问题标题】:GCM Notification Title and Message in LockScreen (Android)LockScreen (Android) 中的 GCM 通知标题和消息
【发布时间】:2016-07-24 14:11:03
【问题描述】:

我想在锁定屏幕中显示包含标题、消息和大图标的 GCM 通知。图片和标题将来自我的应用,其中标题是我的应用名称,通知属于一个信号服务。

我想让通知与图片中的以下通知相同。

这是我的代码:

    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.");
}

【问题讨论】:

    标签: notifications google-cloud-messaging push


    【解决方案1】:

    您的目标是可见的Lock Screen Notification。根据文档:

    设置可见性

    您的应用可以控制在安全锁定屏幕上显示的通知中可见的详细程度。您调用 setVisibility() 并指定以下值之一:VISIBILITY_PUBLICVISIBILITY_SECRETVISIBILITY_PRIVATE

    还发现此Simple Tutorial on Lollipop Notifications 可能对您有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多