返回 Binder 对象:
IBinder iBinder = ServiceManager.getService(Context.NOTIFICATION_SERVICE)
返回 Binder 接口对象(即Service接口):
INotificationManager sINM = INotificationManager.Stub.asInterface(ServiceManager.getService(Context.NOTIFICATION_SERVICE));
- 有些 XxxManager 中有 getService() 方法,也可以获取到 Binder 接口对象:
- android.app.ActivityManager
public static IActivityManager getService() {
return (IActivityManager)IActivityManagerSingleton.get();
}
返回 封装的 XxxManager 对象:
ActivityManager mActivityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
StorageManager mStorageManager = mContext.getSystemService(StorageManager.class);
- 有些通过 XxxManager from( ) 的方式:
StorageManager storageManager = StorageManager.from(mContext);
public static StorageManager from(Context context) {
return context.getSystemService(StorageManager.class);
}
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。