ورود

View Full Version : مشکل با اعلان



asemaneiran
دوشنبه 22 شهریور 1395, 10:42 صبح
سلام
من برا نماش پوش نوتیفیکیشن از این کد استفاده کردم حالا میخوام کاربر روی اعلان که کلیک کرد اعلان حذف شه و یا به یه اکتیویتی خاص بره
ممنون میشم بگید چکار کنم؟؟



int icon = R.drawable.ic_launcher;
CharSequence tickerText = "This is a sample notification";
long when = System.currentTimeMillis();
Context context = getApplicationContext();
CharSequence contentTitle = "خوش آمدید";
String b= (String) txtfamil.getText();
CharSequence contentText = b ;
Intent notificationIntent = new Intent();
PendingIntent contentIntent = PendingIntent.getActivity(getBaseContext(), 0, notificationIntent, 0);



final Notification notification = new Notification(icon, tickerText, when);

notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);


String ns = Context.NOTIFICATION_SERVICE;
final NotificationManager mNotificationManager1 = (NotificationManager) getSystemService(ns);
mNotificationManager1.notify(NOTIFICATION_ID, notification);

asemaneiran
سه شنبه 23 شهریور 1395, 10:35 صبح
کسی نیست؟؟؟؟؟؟؟؟؟؟؟؟؟

tux-world
پنج شنبه 25 شهریور 1395, 11:27 صبح
یه مثال خیلی ساده که باید تغییرش بدی:


public static void createNotification(String title, String subject, int count_unread_message) {
//long[] pattern = {500, 500, 500, 500, 500, 500, 500, 500, 500};
Intent intent = new Intent(context, ActivityBootstrap.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK);

Notification notify = new NotificationCompat.Builder(context)
.setAutoCancel(true)
.setContentTitle(title)
.setContentText(subject)
.setSmallIcon(R.drawable.icon_launcher)
.setSubText(UC.getString(R.string.unread_message))
.setNumber(count_unread_message)
.setPriority(0)
.setSound(Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.reach_star))
.setLights(Color.BLUE, 500, 500)
.setContentIntent(pendingIntent)
.build();

notify.flags |= Notification.FLAG_AUTO_CANCEL;

NOTIFICATIONMANAGER.notify(NOTIFICATION_ID, notify);
}