UsbAccessoryUriActivitypublic class UsbAccessoryUriActivity extends com.android.internal.app.AlertActivity implements DialogInterface.OnClickListenerIf the attached USB accessory has a URL associated with it, and that URL is valid,
show this dialog to the user to allow them to optionally visit that URL for more
information or software downloads.
Otherwise (no valid URL) this activity does nothing at all, finishing immediately. |
Fields Summary |
---|
private static final String | TAG | private android.hardware.usb.UsbAccessory | mAccessory | private android.net.Uri | mUri |
Methods Summary |
---|
public void | onClick(android.content.DialogInterface dialog, int which)
if (which == AlertDialog.BUTTON_POSITIVE) {
// launch the browser
Intent intent = new Intent(Intent.ACTION_VIEW, mUri);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
startActivityAsUser(intent, UserHandle.CURRENT);
} catch (ActivityNotFoundException e) {
Log.e(TAG, "startActivity failed for " + mUri);
}
}
finish();
| public void | onCreate(android.os.Bundle icicle)
super.onCreate(icicle);
Intent intent = getIntent();
mAccessory = (UsbAccessory)intent.getParcelableExtra(UsbManager.EXTRA_ACCESSORY);
String uriString = intent.getStringExtra("uri");
mUri = (uriString == null ? null : Uri.parse(uriString));
// sanity check before displaying dialog
if (mUri == null) {
Log.e(TAG, "could not parse Uri " + uriString);
finish();
return;
}
String scheme = mUri.getScheme();
if (!"http".equals(scheme) && !"https".equals(scheme)) {
Log.e(TAG, "Uri not http or https: " + mUri);
finish();
return;
}
final AlertController.AlertParams ap = mAlertParams;
ap.mTitle = mAccessory.getDescription();
if (ap.mTitle == null || ap.mTitle.length() == 0) {
ap.mTitle = getString(R.string.title_usb_accessory);
}
ap.mMessage = getString(R.string.usb_accessory_uri_prompt, mUri);
ap.mPositiveButtonText = getString(R.string.label_view);
ap.mNegativeButtonText = getString(android.R.string.cancel);
ap.mPositiveButtonListener = this;
ap.mNegativeButtonListener = this;
setupAlert();
|
|