FileDocCategorySizeDatePackage
UsbStorageActivity.javaAPI DocAndroid 1.5 API4012Wed May 06 22:41:56 BST 2009com.android.internal.app

UsbStorageActivity

public class UsbStorageActivity extends AlertActivity implements DialogInterface.OnClickListener
This activity is shown to the user for him/her to enable USB mass storage on-demand (that is, when the USB cable is connected). It uses the alert dialog style. It will be launched from a notification.

Fields Summary
private static final int
POSITIVE_BUTTON
private android.content.BroadcastReceiver
mBatteryReceiver
Used to detect when the USB cable is unplugged, so we can call finish()
Constructors Summary
Methods Summary
private voidhandleBatteryChanged(android.content.Intent intent)

        int pluggedType = intent.getIntExtra("plugged", 0);
        if (pluggedType == 0) {
            // It was disconnected from the plug, so finish
            finish();
        }
    
private voidmountAsUsbStorage()

        IMountService mountService = IMountService.Stub.asInterface(ServiceManager
                .getService("mount"));
        if (mountService == null) {
            showSharingError();
            return;
        }

        try {
            mountService.setMassStorageEnabled(true);
        } catch (RemoteException e) {
            showSharingError();
            return;
        }
    
public voidonClick(android.content.DialogInterface dialog, int which)
{@inheritDoc}


        if (which == POSITIVE_BUTTON) {
            mountAsUsbStorage();
        }

        // No matter what, finish the activity
        finish();
    
protected voidonCreate(android.os.Bundle savedInstanceState)

    
    
        
        super.onCreate(savedInstanceState);

        // Set up the "dialog"
        final AlertController.AlertParams p = mAlertParams;
        p.mIconId = com.android.internal.R.drawable.ic_dialog_usb;
        p.mTitle = getString(com.android.internal.R.string.usb_storage_title);
        p.mMessage = getString(com.android.internal.R.string.usb_storage_message);
        p.mPositiveButtonText = getString(com.android.internal.R.string.usb_storage_button_mount);
        p.mPositiveButtonListener = this;
        p.mNegativeButtonText = getString(com.android.internal.R.string.usb_storage_button_unmount);
        p.mNegativeButtonListener = this;
        setupAlert();
    
protected voidonPause()

        super.onPause();
        
        unregisterReceiver(mBatteryReceiver);
    
protected voidonResume()

        super.onResume();

        registerReceiver(mBatteryReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
    
private voidshowSharingError()

        Toast.makeText(this, com.android.internal.R.string.usb_storage_error_message,
                Toast.LENGTH_LONG).show();