1

我使用这些代码行在我的应用程序中显示通知,但索尼设备(xperia p、sola、acro s)不显示任何通知。我对其他安卓设备没有任何问题。

Intent notificationIntent = new Intent(context, ActivityShowQuestion.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(context,
            Integer.parseInt(id), notificationIntent,
            PendingIntent.FLAG_ONE_SHOT);

    NotificationManager nm = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Notification.Builder builder = new Notification.Builder(context);

    builder.setContentIntent(contentIntent)
            .setSmallIcon(R.drawable.ic_launcher)
            .setWhen(System.currentTimeMillis())
            .setAutoCancel(true)
            .setContentTitle("title")
            .setContentText("text");
    Notification n = builder.build();

    nm.notify(id, n);

我用谷歌搜索但找不到任何答案。

4

1 回答 1

1

这是我从广播中收到的 onRecieve,它在 xperia 上发出通知,我没有任何设备问题,如果它适合你,你可以把它切碎

@Override
    public void onReceive(Context arg0, Intent arg1) {
        String key = LocationManager.KEY_PROXIMITY_ENTERING;

        Boolean entering = arg1.getBooleanExtra(key, false);
        String here = arg1.getExtras().getString("alert");
        String happy = arg1.getExtras().getString("type");



         NotificationManager notificationManager = 
                    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

                PendingIntent pendingIntent = PendingIntent.getActivity(arg0, 0, arg1, 0);        

                Notification notification = createNotification();

                notification.setLatestEventInfo(arg0, 
                    "Entering Proximity!", "You are approaching a " + here + " marker.", pendingIntent);

                notificationManager.notify(NOTIFICATION_ID, notification);


            }

            private Notification createNotification() {
                Notification notification = new Notification();

                notification.icon = R.drawable.icon;
                notification.when = System.currentTimeMillis();

                notification.flags |= Notification.FLAG_AUTO_CANCEL;
                notification.flags |= Notification.FLAG_SHOW_LIGHTS;

                notification.defaults |= Notification.DEFAULT_VIBRATE;
                notification.defaults |= Notification.DEFAULT_LIGHTS;

                notification.ledARGB = Color.WHITE;
                notification.ledOnMS = 1500;
                notification.ledOffMS = 1500;


                return notification;
            }
        //make actions



}

它没有使用 Builder idk 到底是什么导致了你的问题,我知道这在 xperia 上有效

于 2013-05-01T08:45:37.477 回答