通知:Sony设备未显示任何通知

时间:2013-05-01 08:25:51

标签: android push-notification android-notifications sony

我使用这些代码行在我的应用中显示通知,但sony设备(xperia p,sola,acro s)没有显示任何通知。我对其他Android设备没有任何问题。

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);

我用Google搜索但未找到任何答案。

1 个答案:

答案 0 :(得分: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但