Android notification from service does not open activity -
Android notification from service does not open activity -
updated myservice @commonsware
i have service if started set alarm triggers notification.
this works fine , alarms canceled if service stopped.
i trying notification open new activity class can not done
my service class following:
bundle com.example.andtip; import android.app.notification; import android.app.notificationmanager; import android.app.pendingintent; import android.content.broadcastreceiver; import android.content.context; import android.content.intent; import android.support.v4.app.notificationcompat; public class breceiver extends broadcastreceiver { private static final int my_notification_id=1; notificationmanager notificationmanager; notification mynotification; public void onreceive(context context, intent intent) { intent myintent = new intent(context, dosomething.class); pendingintent pi = pendingintent.getbroadcast(context, 0, new intent("com.example.andtip"),0 ); pendingintent pi2 = pendingintent.getactivity(context, 0, myintent,0 ); mynotification=new notificationcompat.builder(context) .setcontenttitle("this notification illustration alarm application.") .setcontenttext("notification") .setticker("notification!") .setwhen(system.currenttimemillis()) .setcontentintent(pi) .setdefaults(notification.default_sound) .setautocancel(true) .setsmallicon(r.drawable.ic_launcher) .build(); notificationmanager = (notificationmanager)context.getsystemservice(context.notification_service); notificationmanager.notify(my_notification_id, mynotification); } }
how should link intent pi2 notification?
i trying notification open new activity class can not done
you using getbroadcast()
create pendingintent
. utilize getactivity()
create pendingintent
starts activity. create sure intent
set in pendingintent
activity, , create sure activity has entry in manifest.
android android-activity service notifications launch
Comments
Post a Comment