service - Android: How to restrict specific apps -
in app, need block sms, email , phone. not detecting incoming or outgoing calls or sms
. simply, have service run in background , check if of 3 processes running. if running activity open when user clicks on dialer or sms app. far, have tried, posting below:
service class
public class dialerservice extends service { activitymanager am; list<runningappprocessinfo> mappprocessinfoslist; private runnable myrunnable; boolean threaddone = true; handler mhandler; boolean islockedapprunning = false; @override public ibinder onbind(intent arg0) { return null; } public void oncreate() { = (activitymanager) getsystemservice(context.activity_service); mappprocessinfoslist = new arraylist<activitymanager.runningappprocessinfo>(); mhandler = new handler(); log.v("dialer service", "oncreate called"); } @override public int onstartcommand(intent intent, int flags, int startid) { myrunnable = new runnable() { @override public void run() { isrestrictedapprunning(); } }; new thread(new runnable() { public void run() { while (threaddone) { try { mhandler.post(myrunnable); } catch (exception e) { } } } }).start(); return start_sticky; } private void isrestrictedapprunning() { mappprocessinfoslist = am.getrunningappprocesses(); (int = 0; < mappprocessinfoslist.size(); i++) { if (mappprocessinfoslist.get(i).processname .equals("com.android.phone") || mappprocessinfoslist.get(i).processname .equals("com.android.email") || mappprocessinfoslist.get(i).processname .equals("com.android.mms")) { islockedapprunning = true; intent dialogintent = new intent(getbasecontext(), testactivity.class); dialogintent.addflags(intent.flag_activity_new_task); getapplication().startactivity(dialogintent); } } } @override public void ondestroy() { super.ondestroy(); this.threaddone = false; } }
this code working has following issue:
it blocks apps, while requirement restrict apps have listed block. e.g., if blocking phone , sms, activity should open on click of dialer , sms app, , not when click on maps.
i not getting how this.
when detect blacklisted app coming up, need bring down running activity. background service/thread best handle activity monitor. there other internal methods using iactivitywatcher internal interface , related hidden apis subject deprecation. believe deprecated in jb.