2013-05-01 40 views
1

我使用这些代码行在我的应用程序中显示通知,但索尼设备(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搜索,但找不到任何答案。

+0

我有第一个体验和即时通讯与代码即时通讯使用,它有点不同,要我发布 – JRowan 2013-05-01 08:40:15

+0

是的谢谢,如果有可能 – 2013-05-01 08:42:32

回答

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 



} 

它不使用生成器IDK的你可以砍它到底是什么导致你的问题,我知道这对xperia虽然

+0

谢谢,我正在测试你的代码,但有一个问题,你在android 2.2上测试这个代码吗?另一件事是不推荐使用setLatestEventInfo()方法。 – 2013-05-01 13:07:03

+0

是我设置的minsdk是8,setLatestEventInfo()表示它的折旧,我现在在市场上,它应该仍然工作折旧方法仍然正常工作? – JRowan 2013-05-01 15:21:49

+0

非常感谢你解决了我的问题,但为什么? – 2013-05-01 20:07:27