返回 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);
}
网友评论