آموزش های این وب سایت به صورت رایگان در دسترس است. اطلاعات بیشتر
بروز خطا
   [message]
اشتراک در سوال
رای ها
[dataList]

نوتیفیکیشن در API 8

AhmadVB  11 سال پیش  11 سال پیش
+3 0

سلام

من برای نمایش پیام در نوار اعلان گوشی از کد های زیر استفاده کردم که اگر اشتباه نکنم توی API 8 کار نمی کنند.

Intent resultIntent = new Intent(this, ActivityMain.class);
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
this,
0,
resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
getApplicationContext()).setSmallIcon(R.drawable.logosmall)
.setContentTitle("My notification")
.setContentText("Hello World!")
.setContentIntent(resultPendingIntent);

NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(0, mBuilder.build());

در کد فوق از NotificationCompat  ایراد NotificationCompat cannot be resolved to a type می گیرد

و این هم روش دوم

// prepare intent which is triggered if the
// notification is selected
Intent intent = new Intent(this, ActivityMain.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
// build notification
// the addAction re-use the same intent to keep the example short
Notification n = new Notification.Builder(this)
.setContentTitle("New mail from " + "test@gmail.com")
.setContentText("Subject")
.setSmallIcon(R.drawable.logosmall)
.setContentIntent(pIntent)
.setAutoCancel(true)
.addAction(R.drawable.logosmall, "Call", pIntent)
.addAction(R.drawable.logosmall, "More", pIntent)
.addAction(R.drawable.logosmall, "And more", pIntent).build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, n);

در این روش هم از Notification.Builder ایراد Notification.Builder cannot be resolved to a type می گیرد

یک کد جایگزین برای نمایش تنها یک پیغام ساده چیست ؟ و یا مشکل کار من کجاست ؟

 برای این سوال 1 پاسخ وجود دارد.
پاسخ به سوال 
ajn91  11 سال پیش
+7 0

کدتونو بررسی نکردم ولی من از این کد قبلا استفاده کردم و به درستی عمل میکنه

 int requestID = (int) System.currentTimeMillis();
 NotificationManager notifManager =(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
 Notification notific = new Notification(R.drawable.icon, "Text To Show", System.currentTimeMillis());
 CharSequence title = "Title";
 CharSequence details = "Details";
 Intent intent = new Intent(context, Activity1.class);
 notific.defaults = Notification.DEFAULT_ALL;
 PendingIntent pendingIntent = PendingIntent.getActivity(context, requestID, intent, 0);
 notific.setLatestEventInfo(context, title, details, pendingIntent);
 notifManager.notify(0, notific);
+1 0
چطور میشه یک پروگرس (مثلا دانلود شدن یک فایل) رو در نوتیفیکشن نمایش داد ؟ (11 سال پیش)

پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .