求帮组,我的应用程序为啥mount不了sd卡?
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mText = (TextView) findViewById(R.id.textView);
b_mount = (Button)findViewById(R.id.button1);
b_umount = (Button)findViewById(R.id.button2);
if (mMountService == null)
{
IBinder service = ServiceManager.getService("mount");
if(service != null)
{
Log.i(TAG, "success to get service_mount");
mMountService = IMountService.Stub.asInterface(service);
}
else
{
Log.e(TAG, "Can't get mount service");
}
}
if (mStorageManager == null)
{
mStorageManager = (StorageManager) getSystemService(Context.STORAGE_SERVICE);
if(mStorageManager == null){
Log.e(TAG, "Failed to get StorageManager");
}
Log.i(TAG, "success to get StorageManager");
mStorageManager.registerListener(mStorageListener);
}
/*
try
{
String state = mMountService.getVolumeState(MOUNTPOINT);
mText.setText("Media state " + state);
if (state.equals(Environment.MEDIA_MOUNTED))
mMountService.unmountVolume(MOUNTPOINT, true, true);
else if (state.equals(Environment.MEDIA_UNMOUNTED))
mMountService.mountVolume(MOUNTPOINT);
} catch (RemoteException e)
{
e.printStackTrace();
}
*/
b_mount.setOnClickListener(new OnClickListener(){
public void onClick(View v){
try{
Log.i(TAG, "mount button click");
mMountService.mountVolume(MOUNTPOINT);
}catch(RemoteException e)
{
Log.e(TAG, "mount click Exception");
e.printStackTrace();
}
}
});
b_umount.setOnClickListener(new OnClickListener(){
public void onClick(View v){
try{
Log.i(TAG, "unmount button click");
mMountService.unmountVolume(MOUNTPOINT, true, false);
}catch(RemoteException e)
{
Log.e(TAG, "unmount click Exception");
e.printStackTrace();
}
}
});
}
protected void onDestroy()
{
if(mStorageManager != null && mStorageListener != null)
mStorageManager.unregisterListener(mStorageListener);
super.onDestroy();
}
}
是用按钮实现的,奇怪为啥手机里setting里可以通过mount方法来挂载,为什么我的应用里操作不了呢??