2012-07-13 69 views
0

我正在使用AsyncTask從服務器下載Android中的文件。我希望進度對話框顯示爲通知欄(例如從AndroidMarket下載應用程序時)。 我做了以下內容:Android錯誤:java.lang.IllegalArgumentException:contentIntent需要

編輯

@Override 
protected void onProgressUpdate(Integer... progress) { 
super.onProgressUpdate(progress); 
// show a notification bar. 
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
Notification notification = new Notification(android.R.drawable.btn_star, "test",System.currentTimeMillis()); 
notification.flags |= Notification.FLAG_AUTO_CANCEL; 
notification.flags |= Notification.FLAG_NO_CLEAR; 
Intent notificationIntent = new Intent(AsynctaskActivity.this, AsynctaskActivity.class); 
notificationIntent.addFlags(Notification.FLAG_ONGOING_EVENT); 
PendingIntent contentIntent = PendingIntent.getActivity(AsynctaskActivity.this, 0, notificationIntent, 0); 
notification.setLatestEventInfo(AsynctaskActivity.this, "test","test", contentIntent); 
notification.number += 1; 
notification.contentView.setProgressBar(progress[0], 100, 42, false); 
notificationManager.notify(1, notification);} 

但我得到的錯誤:

07-13 10:37:16.039: E/AndroidRuntime(27190): FATAL EXCEPTION: main 
07-13 10:37:16.039: E/AndroidRuntime(27190): android.app.RemoteServiceException: Bad notification posted from package s.s: Couldn't expand RemoteViews for: StatusBarNotification(package=s.s id=1 tag=null notification=Notification(vibrate=null,sound=null,defaults=0x0,flags=0x30)) 
07-13 10:37:16.039: E/AndroidRuntime(27190): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1056) 
07-13 10:37:16.039: E/AndroidRuntime(27190): at android.os.Handler.dispatchMessage(Handler.java:99) 
07-13 10:37:16.039: E/AndroidRuntime(27190): at android.os.Looper.loop(Looper.java:130) 
07-13 10:37:16.039: E/AndroidRuntime(27190): at android.app.ActivityThread.main(ActivityThread.java:3701) 
07-13 10:37:16.039: E/AndroidRuntime(27190): at java.lang.reflect.Method.invokeNative(Native Method) 
07-13 10:37:16.039: E/AndroidRuntime(27190): at java.lang.reflect.Method.invoke(Method.java:507) 
07-13 10:37:16.039: E/AndroidRuntime(27190): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 
07-13 10:37:16.039: E/AndroidRuntime(27190): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624) 
07-13 10:37:16.039: E/AndroidRuntime(27190): at dalvik.system.NativeStart.main(Native Method) 

我做錯了嗎?

+0

後更logcat的輸出 – AAnkit 2012-07-13 07:05:50

回答

0

你的方法是錯誤的。

在這一行

PendingIntent act = PendingIntent.getActivity(MY_ACTIVITY, 0, new Intent(), 0); 

你逝去new Intent();

你應該做如下,創建一個Intent,並設置要在通知中顯示的內容:

Intent notificationIntent = new Intent(this, PlayTrack.class); 
notificationIntent.addFlags(Notification.FLAG_ONGOING_EVENT); 
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, 
    notificationIntent, 0); 
+0

我沒有工作,我將編輯我的問題,以新的代碼,並顯示我的logcat。 – 2012-07-13 07:33:56

+0

請看看我編輯的問題。 – 2012-07-13 07:42:21

0

你的錯之一是線下

Notification notification = new Notification(android.R.drawable.btn_star, "test",System.currentTimeMillis()); 

將其更改爲

Notification notification = new Notification(R.drawable.btn_star, "test",System.currentTimeMillis()); 
+0

我有同樣的,但仍然沒有工作,得到同樣的例外。 – swiftBoy 2013-11-28 09:17:02