android - How to know if phone app is closed -
please explain me how android call lock screen after closing emergency dialer. i've tried check every second if emergency call top activity if it's not lock device didn't it's job in android 5.0 , higher. so, need solution.
my code:
private static final long interval = timeunit.seconds.tomillis(1/100); private thread t = null; private context ctx = null; private boolean running = false; public myservice2() { } @override public ibinder onbind(intent intent) { return null; } @override public void oncreate() { super.oncreate(); } @override public int onstartcommand(intent intent, int flags, int startid) { final activitymanager activitymanager = (activitymanager) getsystemservice(context.activity_service); running = true; ctx = this; log.i("point","prerun"); t = new thread(new runnable() { @override public void run() { log.i("point","preloop"); { log.i("point", "prechech"); if (activitymanager.getrunningtasks(1).get(0).topactivity.getpackagename().equals("com.android.phone") || activitymanager.getrunningtasks(1).get(0).topactivity.getpackagename().equals("com.android.dialer")) { try { thread.sleep(interval); } catch (interruptedexception e) { log.i("point", "thread interrupted: 'kioskservice'"); } } else { running=false; log.i("task is",activitymanager.getrunningtasks(1).get(0).topactivity.getpackagename()); stopself(); } }while (running) ; } }); t.start(); log.i("point","done"); return super.onstartcommand(intent, flags, startid); } @override public void ondestroy() { super.ondestroy(); log.i("point","service stopped"); } }
and this:
public class myactivity extends activity{ @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); button button = (button) findviewbyid(r.id.button); button.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { intent intent = new intent("com.android.phone.emergencydialer.dial"); startactivity(intent); intent intent1 = new intent(myactivity.this,myservice2.class); startservice(intent1); } }); } }
you can launch emergency dialer this:
intent intent = new intent("android.intent.action.main"); intent.setcomponent(componentname.unflattenfromstring("com.android.phone/.emergencydialer")); intent.addflags(intent.flag_activity_new_task); startactivity(intent);
moreover please check if have declared service in manifest.
<service android:name=".myservice2"> </service>
Comments
Post a Comment