首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >挂载/卸载卷的unmount服务在4.4 Android上不起作用

挂载/卸载卷的unmount服务在4.4 Android上不起作用
EN

Stack Overflow用户
提问于 2014-07-09 14:55:10
回答 1查看 1.7K关注 0票数 0

我使用反射挂载/卸载外部storage.it的版本低于4.4 Api。代码如下

代码语言:javascript
复制
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;            
import android.os.storage.IMountService; 


private static final String MOUNT_POINT = "/mnt/ext_usb" or "/mnt/sdcard/" ...
private IMountService mMountService = null;

private synchronized IMountService getMountService() {
    if (mMountService == null) {
        IBinder service = ServiceManager.getService("mount");
        if (service != null) {
            mMountService = IMountService.Stub.asInterface(service);
        } else {
            Log.e(TAG, "Can't get mount service");
        }
    }
    return mMountService;
}

private void mount() {
    IMountService mountService = getMountService();
    try {
        if (mountService != null) {
            mountService.mountVolume(MOUNT_POINT);
        } else {
            //
        }
    } catch (RemoteException ex) {
        // Not much can be done
    }
}

private void unmount() {
    StorageManager sm = (StorageManager) getSystemService(Context.STORAGE_SERVICE);
    String state = sm.getVolumeState(MOUNT_POINT);
    if (!Environment.MEDIA_MOUNTED.equals(state) &&
            !Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        //
        return;
    }

    IMountService mountService = getMountService();
    try {
        if (mountService != null) {
            mountService.unmountVolume(MOUNT_POINT, true, false);
        } else {
            Log.e(TAG, "Mount service is null, can't unmount");
        }
    } catch (RemoteException ex) {
        // Not much can be done
    }
}

任何获得它的解决方法都会抛出安全保护要求。我已经在清单中声明了这一点。我向谷歌了解了这个问题,我发现权限有working.As |signature Exception.android.permission.mount_unmount_filesystems level.Thanks。

EN

回答 1

Stack Overflow用户

发布于 2014-08-22 21:15:00

为了使用具有signature | system权限的东西,您的包必须由平台的签名密钥签名。除非您正在创建自己的自定义ROM或具有根设备,否则您将无法做到这一点。

如果你的应用程序是一个常规的第三方应用程序(在Play商店发布),那么你应该只使用公共API,而不是依赖于反射。只有公开的Android API被认为是稳定和公开的。另一些则是隐藏的,因为它们仅供系统内部使用。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24647143

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档