2012-10-19 85 views
4

我想生成一個通知欄顯示通過構建器方法的進展通知,但我不知道我要去的地方wrong.if人誰可以告訴我,我錯了,並幫助我,我將是感謝.....沒有得到來自NotificationCompat.Builder

public class DownloadReceiver extends ResultReceiver{ 
    private final static String TAG = "DownloadReceiver"; 
    public Context context; 
    public DownloadReceiver(Handler handler,Context context) { 
     super(handler); 
     this.context = context; 
     Log.d(TAG,handler.getLooper().getThread().getName()); 
    } 

    @Override 
    protected void onReceiveResult(int resultCode, Bundle resultData) { 
     super.onReceiveResult(resultCode, resultData); 
     Log.d(TAG,"in download receiver"); 

     NotificationManager notificationManager = (NotificationManager) context.getSystemService(Service.NOTIFICATION_SERVICE); 
     Intent notifyIntent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse("http://www.android.com")); 
     PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notifyIntent, 0); 

    if(resultCode == DownloadService.COMPLETED){ 
      Log.d(TAG,resultCode + ""); 
      Builder notificationBuilder = new NotificationCompat.Builder(context) 
              .setProgress(100, 20, false) 
              .addAction(R.drawable.ic_action_search, "title", pendingIntent) 
              .setWhen(System.currentTimeMillis()); 
    //  notification.flags = Notification.FLAG_ONGOING_EVENT; 
      //  notification.setLatestEventInfo(context, "contentTitle", "contentText", pendingIntent); 
      notificationManager.notify(50, notificationBuilder.build()); 
     }else if(resultCode == DownloadService.ALLCOMPLETED){ 

     } 
    } 
} 

回答

11

我只是剛纔來解決這個問題,我的解決方案是必須添加的通知圖像

.setSmallIcon(R.drawable.launcher)

否則將無法什麼都顯示。最老的通知方法並不需要你這種自己設定的,因爲它會默認爲應用程序的圖標。的答覆

+0

感謝,我會嘗試你的解決方案 – user1361425

相關問題