我的java代码:我正在使用下面的代码,但它不起作用。
Intent intent = new Intent(context, LiveFeedScreen.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
final int not_nu = generateRandom();
PendingIntent pendingIntent = PendingIntent.getActivity(context,
not_nu, intent, PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
context)
.setSmallIcon(R.drawable.notificationbig_icon)
.setColor(context.getResources().getColor(R.color.header_blue))
.setContentTitle(context.getString(R.string.app_name))
.setContentText(mMessage)
.setAutoCancel(true)
.setStyle(
new NotificationCompat.BigTextStyle().bigText(mMessage))
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(not_nu, notificationBuilder.build());
它仅在棒棒糖下面工作但是它的显示非常小。
答案 0 :(得分:0)
你可以尝试下面的一个:`private void Notify(String notificationMessage,String pushFullMessage){
Intent intent = new Intent(this, GCMNotificationActivity.class);
intent.putExtra("pushNotification", pushFullMessage);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
final int not_nu = generateRandom();
PendingIntent pendingIntent = PendingIntent.getActivity(this,
not_nu, intent, PendingIntent.FLAG_ONE_SHOT);
android.support.v4.app.NotificationCompat.Builder notificationBuilder = new android.support.v4.app.NotificationCompat.Builder(
this)
.setSmallIcon(R.drawable.app_logo) //Small Icon from drawable
.setContentTitle(this.getString(R.string.app_name))
.setContentText(notificationMessage)
.setAutoCancel(true)
.setLocalOnly(true)
.setColor(this.getResources().getColor(R.color.green))
.setStyle(
new android.support.v4.app.NotificationCompat.BigTextStyle().bigText(notificationMessage))
// .setLargeIcon( // BitmapFactory.decodeResource(this.getResources(), // R.drawable.ic_launcher))//来自drawable的大图标 .setContentIntent(的PendingIntent);
notificationBuilder.setPriority(Notification.PRIORITY_HIGH);
notificationBuilder.setDefaults(Notification.DEFAULT_SOUND);
notificationBuilder.setVibrate(new long[]{0, 100, 200, 300});
NotificationManager notificationManager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(not_nu, notificationBuilder.build());
}
public static int generateRandom() {
Random random = new Random();
return random.nextInt(9999 - 1000) + 1000;
}
`
答案 1 :(得分:0)
它是Android L的一个已知问题,你要做的就是非常简单
在运行期间检查设备操作系统版本和
如果它下面的Lollipop使用你已经使用的方法,
否则如果上面的Lollipop创建一个新的轮廓图标并使用它代替你的notificationbig_icon