大家好, 我是Android开发的新手,目前正在研究谷歌云消息,一切都运行正常,但问题是我无法获得应用程序在锁定屏幕上定义的通知图标和颜色,就像其他应用程序一样,提供了什么样的应用程序锁定屏幕上显示的绿色和图标类似于主屏幕上显示的红色和图标,所以任何人都可以告诉我如何实现它我非常感谢你。
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.");
}
答案 0 :(得分:0)
@Component
public class MyEventRouteBuilder extends SpringRouteBuilder {
@Autowired
MyEventProcessor processor;
@Autowired
PlatformTransactionManager transactionManager;
@Override
public void configure() throws Exception {
from("direct:myRoute")
.onException(MySQLIntegrityConstraintViolationException.class)
.maximumRedeliveries(0)
.useOriginalMessage()
.handled(true)
.to("seda:deadletter")
.markRollbackOnly()
.end()
.transacted()
.process(processor);
from("seda:deadletter")
.choice()
.when(simple("${body} == null"))
.stop()
.end()
.choice()
.when(simple("${exchangeProperty.redilveryAttemptCount} == null"))
.setProperty("redilveryAttemptCount", constant(1))
.when(simple("${exchangeProperty.redilveryAttemptCount} < 3"))
.setProperty("redilveryAttemptCount", simple("${exchangeProperty.redilveryAttemptCount}++"))
.otherwise()
.stop()
.end()
.to("direct:myRoute");
}
}
答案 1 :(得分:0)
在您的代码中,它是通过setSmallIcon
设置的图标。代码中的值R.drawable.ic_launcher
是指Android项目的 res / drawable 目录中的图像。只要该图像已放置在可绘制文件夹中,您就可以将其更改为R.drawable.<name of the icon you want to use>
。