i want to mount sdcard programmatic,how can i check?
Asked
Active
Viewed 4,208 times
0
-
1there will be a tick mark near each answer that you have received for the question that you have asked. Select appropriate answer that you find to be right. The user will get 10 points and you will get 2. Accepted rate is calculated based on the number of questions that you have asked to the number of questions for which you have accepted an answer. – DeRagan Sep 15 '10 at 09:05
-
@ok Rahul,i follow that..Thank you very much – sivaraj Sep 15 '10 at 09:52
2 Answers
1
If you are writing an ordinary SDK application, you cannot mount the SD card yourself.
If you work for a device manufacturer, or you are otherwise building an application that you can sign with the firmware signing key, you can use USB_MASS_STORAGE_ENABLED
.

CommonsWare
- 986,068
- 189
- 2,389
- 2,491
-
Hey Mark, do you have an idea how doubleTwist Player does it? Plaer doesn't require phone to be rooted. http://answers.oreilly.com/topic/1617-how-to-disable-android-usb-auto-mount/ – Maxim Jul 12 '11 at 21:30
-
1
In order to make it works you need to add user library classes-full-debug.jar
(from an aosp or cm build) BEFORE android.jar
(there is a panel in the build path to sort jars) or StorageManager
will not resolve registerListener()
You also need android.permission.MOUNT_UNMOUNT_FILESYSTEMS
package x.y.z;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Environment;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.storage.IMountService;
import android.os.storage.StorageEventListener;
import android.os.storage.StorageManager;
import android.os.ServiceManager;
import android.widget.TextView;
public class MyActivity extends Activity
{
private static final String MOUNTPOINT = "/mnt/sdcard";
private IMountService mMountService;
private StorageManager mStorageManager;
private TextView mText;
private final StorageEventListener mStorageListener = new StorageEventListener()
{
@Override
public void onStorageStateChanged(String path, String oldState, String newState)
{
String text = mText.getText() + "\n";
text += "state changed notification that " + path + " changed state from " + oldState + " to " + newState;
mText.setText(text);
}
};
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mText = (TextView) findViewById(R.id.textView);
if (mMountService == null)
{
IBinder service = ServiceManager.getService("mount");
mMountService = IMountService.Stub.asInterface(service);
}
if (mStorageManager == null)
{
mStorageManager = (StorageManager) getSystemService(Context.STORAGE_SERVICE);
mStorageManager.registerListener(mStorageListener);
}
try
{
String state = mMountService.getVolumeState(MOUNTPOINT);
mText.setText("Media state " + state);
if (state.equals(Environment.MEDIA_MOUNTED))
mMountService.unmountVolume(MOUNTPOINT, false);
else if (state.equals(Environment.MEDIA_UNMOUNTED))
mMountService.mountVolume(MOUNTPOINT);
} catch (RemoteException e)
{
e.printStackTrace();
}
}
@Override
protected void onDestroy()
{
if (mStorageManager != null && mStorageListener != null)
mStorageManager.unregisterListener(mStorageListener);
super.onDestroy();
}
}

sherpya
- 4,890
- 2
- 34
- 50