正常获取Binder对象的几种方式

2022-05-30  本文已影响0人  fsdffdaga

返回 Binder 对象:

IBinder iBinder = ServiceManager.getService(Context.NOTIFICATION_SERVICE)

返回 Binder 接口对象(即Service接口):

INotificationManager sINM = INotificationManager.Stub.asInterface(ServiceManager.getService(Context.NOTIFICATION_SERVICE));
    public static IActivityManager getService() {
        return (IActivityManager)IActivityManagerSingleton.get();
    }

返回 封装的 XxxManager 对象:

ActivityManager mActivityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
StorageManager mStorageManager = mContext.getSystemService(StorageManager.class);
StorageManager storageManager = StorageManager.from(mContext);

public static StorageManager from(Context context) {
    return context.getSystemService(StorageManager.class);
}
上一篇下一篇

猜你喜欢

热点阅读