The import android.os.ServiceManager cannot be resolved

后端 未结 3 1566
生来不讨喜
生来不讨喜 2020-12-06 08:18

I\'m using aidl to answer call automagically, code as following:

ITelephony.Stub.asInterface(ServiceManager.getService(\"phone\"))
    .answerRingingCall();
         


        
3条回答
  •  没有蜡笔的小新
    2020-12-06 09:04

    Though it is old one, but no one has answered it yet. Any hidden classes can be used using reflection APIs. Here is an example to acquire a service using Service Manager via reflection APIs:

    if(mService == null) {
                Method method = null;
                try {
                    method = Class.forName("android.os.ServiceManager").getMethod("getService", String.class);
                    IBinder binder = (IBinder) method.invoke(null, "My_SERVICE_NAME");
                    if(binder != null) {
                        mService = IMyService.Stub.asInterface(binder);
                    }
    
                    if(mService != null)
                        mIsAcquired = true;
    
                } catch (NoSuchMethodException e) {
                    e.printStackTrace();
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                }
    
            } else {
                Log.i(TAG, "Service is already acquired");
            }
    

提交回复
热议问题