بروز خطا
[message]
اشتراک در سوال
رای ها
[dataList]
مشکل نمایش نوتیفیکیشن در اندروید 2.2
زمانی که برنامه رو روی اندروید 2.2 اجرا می کنم با ارور زیر مواجه میشم در صورتی که 4.0.3 این مشکل وجود ندارد
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final int notifyID = 1;
final NotificationManager mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
final Builder mBuilder = new NotificationCompat.Builder(this);
mBuilder.setContentTitle("Picture Download")
.setContentText("Download in progress")
.setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true);
// Start a lengthy operation in a background thread
new Thread(
new Runnable() {
@Override
public void run() {
int incr;
// Do the "lengthy" operation 20 times
for (incr = 0; incr <= 100; incr += 5) {
// Sets the progress indicator to a max value, the
// current completion percentage, and "determinate"
// state
mBuilder.setProgress(100, incr, false);
// Displays the progress bar for the first time.
mNotifyManager.notify(1, mBuilder.build());
// Sleeps the thread, simulating an operation
mBuilder.setOngoing(true);
// that takes time
try {
// Sleep for 5 seconds
Thread.sleep(500);
}
catch (InterruptedException e) {}
}
// When the loop is finished, updates the notification
mBuilder.setContentText("Download complete")
// Removes the progress bar
.setProgress(0, 0, false).setOngoing(false);
mNotifyManager.cancel(notifyID);
mNotifyManager.notify(notifyID, mBuilder.build());
}
}
// Starts the thread by calling the run() method in its Runnable
).start();
}
11-17 12:18:28.945: E/AndroidRuntime(21296): FATAL EXCEPTION: Thread-8
11-17 12:18:28.945: E/AndroidRuntime(21296): java.lang.IllegalArgumentException: contentIntent required:
pkg=com.uncocoder.course.notifi id=1 notification=Notification(vibrate=null,sound=null,defaults=0x0)
11-17 12:18:28.945: E/AndroidRuntime(21296): at android.os.Parcel.readException(Parcel.java:1251)
11-17 12:18:28.945: E/AndroidRuntime(21296): at android.os.Parcel.readException(Parcel.java:1235)
11-17 12:18:28.945: E/AndroidRuntime(21296): at android.app.INotificationManager$Stub$Proxy.enqueueNotificationWithTag(INotificationManager.java:274)
11-17 12:18:28.945: E/AndroidRuntime(21296): at android.app.NotificationManager.notify(NotificationManager.java:110)
11-17 12:18:28.945: E/AndroidRuntime(21296): at android.app.NotificationManager.notify(NotificationManager.java:90)
11-17 12:18:28.945: E/AndroidRuntime(21296): at com.uncocoder.course.notifi.notifiActivity$1.run(notifiActivity.java:38)
11-17 12:18:28.945: E/AndroidRuntime(21296): at java.lang.Thread.run(Thread.java:1096)
برای این سوال 1 پاسخ وجود دارد.
پاسخ به سوال
سپهر
11 سال پیش
0
0
کد رو به این صورت تغییر دادم مشکلم حل شد
Intent intent = new Intent(this, ActivityTest.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
finalBuilder mBuilder = newNotificationCompat.Builder(this);
mBuilder.setContentTitle("Picture Download")
.setContentText("Download in progress")
.setSmallIcon(R.drawable.ic_launcher)
.setAutoCancel(true)
.setContentIntent(pendingIntent);
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .