android listen for app launch

后端 未结 2 922
抹茶落季
抹茶落季 2020-12-19 07:33

I need to develop a service which listen for every activity start. Must I do something like this?

ActivityManager am = (ActivityManager) getSystemService(Con         


        
2条回答
  •  难免孤独
    2020-12-19 08:08

    As far as I know there is a class IActivityController.Stub in android.app package. But this is an {@hide} interface (as someone said there have some method to access @hide api).

    We can set a Listener to listen Activity switch like this:

    mAm = ActivityManagerNative.getDefault();          
        try {
            mAm.setActivityController(new ActivityController());
    
       } catch (RemoteException e) {
            System.err.println("** Failed talking with activity manager!");}
    

    and Class ActivityManagerNative is @hide also. ActivityController is a class extends IActivityController.Stub .

    How to access @hide Api:

    1. you can get the android source code to build an have-@hide-api Android.jar to use.
    2. by reflection.

提交回复
热议问题