2013-05-01 35 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