Is it possible to execute a service in Android only if I have an particular app that is open? -


is there way execute service (start or stop) when particular app open? case have "bubble" service (similar facebook) , want appear when open game minecraft pe. , when change or open application want put invisible bubble. possible?

use code.

public class checkrunningapplicationreceiver extends broadcastreceiver {      @override     public void onreceive(context acontext, intent anintent) {         try {                         activitymanager = (activitymanager) acontext                     .getsystemservice(context.activity_service);             list<activitymanager.runningtaskinfo> alltasks =                     .getrunningtasks(1);             (activitymanager.runningtaskinfo atask : alltasks) {                  if (atask.topactivity.getclassname().equals("com.android.phone.incallscreen")                     || atask.topactivity.getclassname().equals("com.android.contacts.dialtactsactivity"))                 {                     toast.maketext(acontext, "phone call screen.", toast.length_long).show();                    }                 string packagename = "com.example.checkcurrentrunningapplication";                  if (atask.topactivity.getclassname().equals(                         packagename + ".main"))                 {                    // when opens example screen show alert message                    toast.maketext(acontext, "check current running application example screen.",                                     toast.length_long).show();                    }             }          } catch (throwable t) {             log.i("throw", "throwable caught: "                         + t.getmessage(), t);         }     } } 

add in manifest:

<receiver android:name = ".checkrunningapplicationreceiver"/> <uses-permission android:name="android.permission.get_tasks" /> 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -