求帮组,我的应用程序为啥mount不了sd卡?

yaya_lucky 2013-05-30 12:54:56
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方法来挂载,为什么我的应用里操作不了呢??
...全文
70 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

80,359

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧