在systemserver中,audioservice是这么加的:
            if (!"0".equals(SystemProperties.get("system_init.startaudioservice"))) {
                try {
                    Slog.i(TAG, "Audio Service");
                    ServiceManager.addService(Context.AUDIO_SERVICE, new AudioService(context));
                } catch (Throwable e) {
                    reportWtf("starting Audio Service", e);
                }
            }在调节音量的时候会get  AUDIO_SERVICE 这个service 
对应的代码是:
        final AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);这里就很不明白,我查了下代码,这里并没有AudioManager和Context.AUDIO_SERVICE的联系啊为什么这个getSystemService返回的却是 AudioManager  呢???why?  谁可以指点下么? 非常不解啊

解决方案 »

  1.   

    强制转换我知道 但是为什么不是转换成AudioService呢???
      

  2.   

    你总得有个联系吧,不然为什么不强制转换为其他的manager呢?? 
      

  3.   

    你去查AudioManager,Android Developers,
    AudioManager provides access to volume and ringer mode control.Use Context.getSystemService(Context.AUDIO_SERVICE) to get an instance of this class.这是获得它的控制类啊,就跟ServiceManager.addService添加服务一样,也是再控制类中
      

  4.   

    建议LZ去看看Binder机制 , AudioService类是服务端 , AudioManager是管理AudioService代理类的一个类 。 
      对用户来说,只能通过AudioManager去操作音频对象 。  至于为什么返回的是 :final AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
       你可以去看看ContextImpl.java类 。它返回的就是AudioManager类。