大家好, 我是新來的android開發,目前在谷歌雲消息工作一切工作正常,但問題是,我無法獲得通知圖標和應用程序鎖定屏幕上的應用程序定義像其他應用程序給出像什麼是應用程序綠色和圖標顯示在鎖定屏幕上類似gmail的紅色和圖標顯示在主屏幕上,所以任何人都可以告訴我如何實現它我非常感謝你。如何在屏幕鎖定時通知推送通知?
private void sendNotification(String msg) {
Log.d(TAG, "Preparing to send notification...: " + msg);
mNotificationManager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, MainActivity.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)
.setColor(
getResources().getColor(
R.color.abc_primary_text_material_dark))
.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 })
.setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
.setContentInfo("hi")
.setTicker("hi")
.setPriority(Notification.PRIORITY_HIGH)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setLights(0x0000FF, 1000, 4000)
;
PowerManager pm = (PowerManager) getApplicationContext()
.getSystemService(Context.POWER_SERVICE);
WakeLock wakeLock = pm
.newWakeLock(
(PowerManager.SCREEN_BRIGHT_WAKE_LOCK
| PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP),
"TAG");
wakeLock.acquire(15000);
// Settings.System.putString(getApplicationContext().getContentResolver(),
// Settings.System.NEXT_ALARM_FORMATTED, "hi");
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
Log.d(TAG, "Notification sent successfully.");
}
請提供您的嘗試代碼。 – Dan
均勻燈不工作。 – androidLover