notifications - Intent.setClass in android -
i'm developing android app create notification programmatically :
public void createnotification() { intent intent=new intent().setclass(incomingcallscreen.this,incomingcallscreen.class); intent.setflags(intent.flag_activity_new_task); intent.addflags(intent.flag_activity_reorder_to_front); pendingintent contentintent = pendingintent.getactivity(incomingcallscreen.this, 0, intent,0); notification notification = new notificationcompat.builder(this) .setcontenttitle("incoming call") .setcontenttext("there call running") .setsmallicon(r.drawable.answer) .setautocancel(true) .addaction(r.drawable.reject, "hangup", contentintent) .setcontentintent(contentintent) .build(); notificationmanager notificationmanager = (notificationmanager) getsystemservice(notification_service); notificationmanager.notify(1, notification); }
this function called in onpause state want when activity in onpause , user click on notification activity can in front again whatsapp when accept call , if go or press home notification presed bring call screen again. happens when press on notification app closed!
note : context same class want go (may issue) lunchmode:sinletop exist activity
try this,
private static void generatenotification(context context, string message) { int icon = r.drawable.ic_launcher; long when = system.currenttimemillis(); notificationmanager notificationmanager = (notificationmanager) context .getsystemservice(context.notification_service); notification notification = new notification(icon, message, when); string title = context.getstring(r.string.app_name); intent notificationintent = new intent(context, second.class); notificationintent.setflags(intent.flag_activity_clear_top | intent.flag_activity_single_top); pendingintent intent = pendingintent.getactivity(context, 0, notificationintent, 0); notification.setlatesteventinfo(context, title, message, intent); notification.flags |= notification.flag_auto_cancel; // play default notification sound notification.defaults |= notification.default_sound; // notification.defaults |= notification.default_lights; // // notification.ledargb = 0xff00ff00; // notification.ledonms = 300; // notification.ledoffms = 1000; // notification.defaults |= notification.flag_show_lights; // vibrate if vibrate enabled // notification.defaults |= notification.default_vibrate; powermanager pm = (powermanager) context .getsystemservice(context.power_service); boolean isscreenon = pm.isscreenon(); log.e("screen on.................................", "" + isscreenon); if (isscreenon == false) { wakelock wl = pm.newwakelock(powermanager.full_wake_lock | powermanager.acquire_causes_wakeup | powermanager.on_after_release, "mylock"); wl.acquire(10000); wakelock wl_cpu = pm.newwakelock(powermanager.partial_wake_lock, "mycpulock"); wl_cpu.acquire(10000); } notificationmanager.notify(0, notification); }
Comments
Post a Comment