2012-07-13 1 views
0

Je télécharge un fichier sous Android à partir d'un serveur utilisant AsyncTask. Je veux que la boîte de dialogue de progression s'affiche sous forme de barre de notification (comme lorsque vous téléchargez une application à partir d'AndroidMarket). que je fais ce qui suit:Erreur Android: java.lang.IllegalArgumentException: contentIntent requis

EDIT

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

Mais j'obtiens l'erreur:

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) 

Qu'est-ce que je fais mal?

+0

après plus sortie logcat – AAnkit

Répondre

0

Votre approche est erronée.

Dans cette ligne

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

vous passez new Intent();

vous devriez faire comme ci-dessous, créer une intention, et définir ce que vous voulez afficher dans la notification:

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

Je ne marchait pas, je vais modifier ma question au nouveau code et montrer mon logcat. –

+0

S'il vous plaît jeter un oeil sur ma question éditée. –

0

un de vos mauvais est sous la ligne

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

changement à

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

J'ai le même mais ne fonctionne pas encore, obtenant la même exception. – swiftBoy

Questions connexes