I would like to get USB Mass Storage activity to turn on or off the usb mode when device is connected to pc.I have implemented an application as follows.
public class USB_ConnectActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final String state = Environment.getExternalStorageState();
((Button)findViewById(R.id.onButton)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!(Environment.MEDIA_SHARED.equals(state))) {
//How to navigate android USB Mass Storage page
}
}
});
((Button)findViewById(R.id.offButton)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if ((Environment.MEDIA_SHARED.equals(state))) {
//How to navigate android USB Mass Storage page
}
}
});
}
}
from the above code I have used two buttons for turn off and on usb mass storage.But I don't have more information about it to navigate android in built USB Mass Storage page. Please any body help me.
If you only want to launch the USB mass storage
Activity
, then your question is an exact duplicate of: Android Intent to open "Mass Storage Activity" and should be closed.If you actually want to change the status of the USB mode, which is what it looks like, then this isn't a duplicate (as far as I can tell), but the answer is still: you can't do it.
Maybe there's a better way, but when I want to know what Intents are available for launching system Activities, I look at the Android SDK documentation for Intent and search for "activity action". That shows you many system Activities you can launch, such as the "battery use"
Activity
and the uninstallationActivity
. There's nothing there showing the USB modeActivity
as a publicIntent
. Excusing the pun, this was probably intentional.And there's certainly no documentation I can find about any way to programmatically turn USB mode on or off, and this is also presumably intentional.