외부 저장소를 마운트/마운트 해제하기 위해 리플렉션을 사용했습니다. 4.4 API 이하에서 작동합니다. 코드는이 문제에 대해 구글이4.4 안드로이드에서 작동하지 않는 볼륨을 마운트/마운트 해제 할 Imountservice
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
}
}
아래 그것이 보안 Exception.android.permission.mount_unmount_filesystems requires.I가 manifest.I이를 decleared 한 던져 working.As 얻을 수있는 모든 해결 방법입니다 내가 권한이있는 것을 발견 시스템 | 시그니처 보호 수준입니다. 미리 감사드립니다.