List of usage examples for android.content Intent setData
public @NonNull Intent setData(@Nullable Uri data)
From source file:org.openremote.android.console.util.AsyncResourceLoader.java
/** * Finish downloading and forward to different view by result. * /*w ww . ja va2s.com*/ * @see android.os.AsyncTask#onPostExecute(java.lang.Object) */ @Override protected void onPostExecute(AsyncResourceLoaderResult result) { publishProgress("groups & screens"); Intent intent = new Intent(); switch (result.getAction()) { case TO_GROUP: intent.setClass(activity, GroupActivity.class); if (result.isCanUseLocalCache()) { intent.setData(Uri.parse(ControllerException.exceptionMessageOfCode(result.getStatusCode()))); } break; case TO_LOGIN: intent.setClass(activity, LoginViewActivity.class); intent.setData(Uri.parse(Main.LOAD_RESOURCE)); break; case TO_SETTING_SSL_PROTOCOL_ERROR: //If the host is in the keystore, delete it. It is obviously invalid. orKeyStore.deleteHost(AppSettingsModel.getCurrentServer(activity)); intent.setClass(activity, AppSettingsActivity.class); intent.putExtra("SSL_CLIENT_PROTOCOL", true); break; case TO_SETTING_SSL_ERROR: //If the host is in the keystore, delete it. It is obviously invalid. orKeyStore.deleteHost(AppSettingsModel.getCurrentServer(activity)); intent.setClass(activity, AppSettingsActivity.class); intent.putExtra("SSL_CLIENT", true); break; case SWITCH_TO_OTHER_CONTROLER: ORControllerServerSwitcher.doSwitch(activity); return; default: ViewHelper.showAlertViewWithTitle(activity, "Send Request Error", ControllerException.exceptionMessageOfCode(result.getStatusCode())); return; } activity.startActivity(intent); activity.finish(); }
From source file:com.polyvi.xface.extension.XAppExt.java
private void setIntentByUri(Intent intent, Uri uri) { if (!XConstant.FILE_SCHEME.contains(uri.getScheme())) { intent.setData(uri); } else {/*from ww w . j a v a 2s . c o m*/ String mimeType = XFileUtils.getMIMEType(uri.toString()); intent.setDataAndType(uri, XStringUtils.isEmptyString(mimeType) ? "*/*" : mimeType); } }
From source file:za.co.neilson.alarm.BaseActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { String url = null;//from w ww . j a v a 2s. com Intent intent = null; switch (item.getItemId()) { case R.id.menu_item_join: startDialog(); break; case R.id.menu_item_new: startAlarmPreferencesActivity(); break; case R.id.menu_item_rate: url = "market://details?id=" + getPackageName(); intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(url)); try { startActivity(intent); } catch (ActivityNotFoundException e) { Toast.makeText(this, "Couldn't launch the market", Toast.LENGTH_LONG).show(); } break; case R.id.menu_item_website: url = "http://www.neilson.co.za"; intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(url)); try { startActivity(intent); } catch (ActivityNotFoundException e) { Toast.makeText(this, "Couldn't launch the website", Toast.LENGTH_LONG).show(); } break; case R.id.menu_item_report: url = "https://github.com/SheldonNeilson/Android-Alarm-Clock/issues"; intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(url)); try { startActivity(intent); } catch (ActivityNotFoundException e) { Toast.makeText(this, "Couldn't launch the bug reporting website", Toast.LENGTH_LONG).show(); } /* Intent send = new Intent(Intent.ACTION_SENDTO); String uriText; String emailAddress = "dontusemyemailaddress@yourdomain.com"; String subject = R.string.app_name + " Bug Report"; String body = "Debug:"; body += "\n OS Version: " + System.getProperty("os.version") + "(" + android.os.Build.VERSION.INCREMENTAL + ")"; body += "\n OS API Level: " + android.os.Build.VERSION.SDK_INT; body += "\n Device: " + android.os.Build.DEVICE; body += "\n Model (and Product): " + android.os.Build.MODEL + " (" + android.os.Build.PRODUCT + ")"; body += "\n Screen Width: " + getWindow().getWindowManager().getDefaultDisplay().getWidth(); body += "\n Screen Height: " + getWindow().getWindowManager().getDefaultDisplay().getHeight(); body += "\n Hardware Keyboard Present: " + (getResources().getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS); uriText = "mailto:" + emailAddress + "?subject=" + subject + "&body=" + body; uriText = uriText.replace(" ", "%20"); Uri emalUri = Uri.parse(uriText); send.setData(emalUri); startActivity(Intent.createChooser(send, "Send mail...")); */ break; } return super.onOptionsItemSelected(item); }
From source file:com.entertailion.android.launcher.Dialogs.java
/** * Display dialog to the user for the browser bookmarks. Allow the user to add a * browser bookmark to an existing row or a new row. * //from ww w . j a va 2s . c om * @param context */ public static void displayAddBrowserBookmark(final Launcher context) { final Dialog dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.add_browser_bookmarks_list); final EditText nameEditText = (EditText) dialog.findViewById(R.id.rowName); final RadioButton currentRadioButton = (RadioButton) dialog.findViewById(R.id.currentRadio); currentRadioButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { // hide the row name edit field if the current row radio button // is selected nameEditText.setVisibility(View.GONE); } }); final RadioButton newRadioButton = (RadioButton) dialog.findViewById(R.id.newRadio); newRadioButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { // show the row name edit field if the new radio button is // selected nameEditText.setVisibility(View.VISIBLE); nameEditText.requestFocus(); } }); ListView listView = (ListView) dialog.findViewById(R.id.list); final ArrayList<BookmarkInfo> bookmarks = loadBookmarks(context); Collections.sort(bookmarks, new Comparator<BookmarkInfo>() { @Override public int compare(BookmarkInfo lhs, BookmarkInfo rhs) { return lhs.getTitle().toLowerCase().compareTo(rhs.getTitle().toLowerCase()); } }); listView.setAdapter(new BookmarkAdapter(context, bookmarks)); listView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { @Override public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) { // run in thread since network logic needed to get bookmark icon new Thread(new Runnable() { public void run() { // if the new row radio button is selected, the user must enter // a name for the new row String name = nameEditText.getText().toString().trim(); if (newRadioButton.isChecked() && name.length() == 0) { nameEditText.requestFocus(); displayAlert(context, context.getString(R.string.dialog_new_row_name_alert)); return; } boolean currentRow = !newRadioButton.isChecked(); try { BookmarkInfo bookmark = (BookmarkInfo) parent.getAdapter().getItem(position); int rowId = 0; int rowPosition = 0; if (currentRow) { rowId = context.getCurrentGalleryId(); ArrayList<ItemInfo> items = ItemsTable.getItems(context, rowId); rowPosition = items.size(); // in last // position // for selected // row } else { rowId = (int) RowsTable.insertRow(context, name, 0, RowInfo.FAVORITE_TYPE); rowPosition = 0; } Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(bookmark.getUrl())); Uri uri = Uri.parse(bookmark.getUrl()); Log.d(LOG_TAG, "host=" + uri.getScheme() + "://" + uri.getHost()); String icon = Utils.getWebSiteIcon(context, "http://" + uri.getHost()); Log.d(LOG_TAG, "icon1=" + icon); if (icon == null) { // try base host address int count = StringUtils.countMatches(uri.getHost(), "."); if (count > 1) { int index = uri.getHost().indexOf('.'); String baseHost = uri.getHost().substring(index + 1); icon = Utils.getWebSiteIcon(context, "http://" + baseHost); Log.d(LOG_TAG, "icon2=" + icon); } } ItemsTable.insertItem(context, rowId, rowPosition, bookmark.getTitle(), intent, icon, DatabaseHelper.SHORTCUT_TYPE); } catch (Exception e) { Log.e(LOG_TAG, "displayAddBrowserBookmark", e); } // need to do this on UI thread context.getHandler().post(new Runnable() { public void run() { context.showCover(false); dialog.dismiss(); context.reloadAllGalleries(); } }); if (currentRow) { Analytics.logEvent(Analytics.ADD_BROWSER_BOOKMARK); } else { Analytics.logEvent(Analytics.ADD_BROWSER_BOOKMARK_WITH_ROW); } } }).start(); } }); listView.setDrawingCacheEnabled(true); listView.setOnKeyListener(onKeyListener); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { context.showCover(false); } }); context.showCover(true); dialog.show(); Analytics.logEvent(Analytics.DIALOG_ADD_BROWSER_BOOKMARK); }
From source file:com.polyvi.xface.extension.telephony.XTelephonyExt.java
/** * ???/*w w w . j a v a2 s.co m*/ * * @param[in] phoneNumber ???? * @return ??? */ private boolean initiateVoiceCall(String phoneNumber) { try { if (isLegalPhoneNum(phoneNumber)) { Intent intent = new Intent(Intent.ACTION_CALL); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setData(Uri.parse(WebView.SCHEME_TEL + phoneNumber)); mContext.startActivity(intent); return true; } } catch (ActivityNotFoundException e) { XLog.e(CLASS_NAME, e.toString()); } catch (SecurityException e) { XLog.e(CLASS_NAME, e.toString()); } return false; }
From source file:bolts.AppLinkNavigation.java
/** * Performs the navigation./*ww w . j a v a 2 s . c om*/ * * @param context the Context from which the navigation should be performed. * @return the {@link NavigationResult} performed by navigating. */ public NavigationResult navigate(Context context) { PackageManager pm = context.getPackageManager(); Bundle finalAppLinkData = buildAppLinkDataForNavigation(context); Intent eligibleTargetIntent = null; for (AppLink.Target target : getAppLink().getTargets()) { Intent targetIntent = new Intent(Intent.ACTION_VIEW); if (target.getUrl() != null) { targetIntent.setData(target.getUrl()); } else { targetIntent.setData(appLink.getSourceUrl()); } targetIntent.setPackage(target.getPackageName()); if (target.getClassName() != null) { targetIntent.setClassName(target.getPackageName(), target.getClassName()); } targetIntent.putExtra(AppLinks.KEY_NAME_APPLINK_DATA, finalAppLinkData); ResolveInfo resolved = pm.resolveActivity(targetIntent, PackageManager.MATCH_DEFAULT_ONLY); if (resolved != null) { eligibleTargetIntent = targetIntent; break; } } Intent outIntent = null; NavigationResult result = NavigationResult.FAILED; if (eligibleTargetIntent != null) { outIntent = eligibleTargetIntent; result = NavigationResult.APP; } else { // Fall back to the web if it's available Uri webUrl = getAppLink().getWebUrl(); if (webUrl != null) { JSONObject appLinkDataJson; try { appLinkDataJson = getJSONForBundle(finalAppLinkData); } catch (JSONException e) { sendAppLinkNavigateEventBroadcast(context, eligibleTargetIntent, NavigationResult.FAILED, e); throw new RuntimeException(e); } webUrl = webUrl.buildUpon() .appendQueryParameter(AppLinks.KEY_NAME_APPLINK_DATA, appLinkDataJson.toString()).build(); outIntent = new Intent(Intent.ACTION_VIEW, webUrl); result = NavigationResult.WEB; } } sendAppLinkNavigateEventBroadcast(context, outIntent, result, null); if (outIntent != null) { context.startActivity(outIntent); } return result; }
From source file:com.polyvi.xface.extension.XTelephonyExt.java
/** * ???//from ww w . jav a 2s . c o m * * @param[in] phoneNumber ???? * @return ??? * */ private boolean initiateVoiceCall(String phoneNumber) { try { if (isLegalPhoneNum(phoneNumber)) { Intent intent = new Intent(Intent.ACTION_CALL); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setData(Uri.parse(WebView.SCHEME_TEL + phoneNumber)); getContext().startActivity(intent); return true; } } catch (ActivityNotFoundException e) { XLog.e(CLASS_NAME, e.toString()); } catch (SecurityException e) { XLog.e(CLASS_NAME, e.toString()); } return false; }
From source file:com.scrachx.foodfacts.checker.ui.main.MainActivity.java
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case PermissionUtils.MY_PERMISSIONS_REQUEST_CAMERA: { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { startActivity(ScannerActivity.getStartIntent(this)); } else {// ww w .j a va 2 s .co m new MaterialDialog.Builder(this).title(R.string.permission_title) .content(R.string.permission_denied).negativeText(R.string.txt_no) .positiveText(R.string.txt_yes).onPositive((dialog, which) -> { Intent intent = new Intent(); intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); Uri uri = Uri.fromParts("package", getPackageName(), null); intent.setData(uri); startActivity(intent); }).show(); } break; } } }
From source file:com.entertailion.android.launcher.Dialogs.java
/** * Display dialog to allow user to select which row to add the shortcut. For * TV channels let the user change the channel name. * //from w w w.j a v a 2 s .com * @see InstallShortcutReceiver * * @param context * @param name * @param icon * @param uri */ public static void displayShortcutsRowSelection(final Launcher context, final String name, final String icon, final String uri) { if (uri == null) { return; } final Dialog dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); final boolean isChannel = uri.startsWith("tv"); dialog.setContentView(R.layout.select_row); final TextView channelTextView = (TextView) dialog.findViewById(R.id.channelText); final EditText channelNameEditText = (EditText) dialog.findViewById(R.id.channelName); if (isChannel) { channelTextView.setVisibility(View.VISIBLE); channelNameEditText.setVisibility(View.VISIBLE); channelNameEditText.setText(name); } final TextView selectTextView = (TextView) dialog.findViewById(R.id.selectText); selectTextView.setText(context.getString(R.string.dialog_select_row, name)); final Spinner spinner = (Spinner) dialog.findViewById(R.id.spinner); final EditText nameEditText = (EditText) dialog.findViewById(R.id.rowName); final RadioButton currentRadioButton = (RadioButton) dialog.findViewById(R.id.currentRadio); currentRadioButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // hide the row name edit field if the current row radio button // is selected nameEditText.setVisibility(View.GONE); spinner.setVisibility(View.VISIBLE); } }); final RadioButton newRadioButton = (RadioButton) dialog.findViewById(R.id.newRadio); newRadioButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // show the row name edit field if the new radio button is // selected nameEditText.setVisibility(View.VISIBLE); nameEditText.requestFocus(); spinner.setVisibility(View.GONE); } }); List<String> list = new ArrayList<String>(); final ArrayList<RowInfo> rows = RowsTable.getRows(context); if (rows != null) { for (RowInfo row : rows) { list.add(row.getTitle()); } } ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(context, R.layout.simple_spinner_item, list); dataAdapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item); spinner.setAdapter(dataAdapter); Button buttonYes = (Button) dialog.findViewById(R.id.buttonOk); buttonYes.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String shortcutName = name; try { if (isChannel) { String channelName = channelNameEditText.getText().toString().trim(); if (channelName.length() == 0) { channelNameEditText.requestFocus(); displayAlert(context, context.getString(R.string.dialog_channel_name_alert)); return; } shortcutName = channelName; } // if the new row radio button is selected, the user must // enter a name for the new row String rowName = nameEditText.getText().toString().trim(); if (newRadioButton.isChecked() && rowName.length() == 0) { nameEditText.requestFocus(); displayAlert(context, context.getString(R.string.dialog_new_row_name_alert)); return; } boolean currentRow = !newRadioButton.isChecked(); int rowId = 0; int rowPosition = 0; if (currentRow) { if (rows != null) { String selectedRow = (String) spinner.getSelectedItem(); for (RowInfo row : rows) { if (row.getTitle().equals(selectedRow)) { rowId = row.getId(); ArrayList<ItemInfo> items = ItemsTable.getItems(context, rowId); rowPosition = items.size(); // in last // position // for selected // row break; } } } } else { rowId = (int) RowsTable.insertRow(context, rowName, 0, RowInfo.FAVORITE_TYPE); rowPosition = 0; } Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(uri)); ItemsTable.insertItem(context, rowId, rowPosition, shortcutName, intent, icon, DatabaseHelper.SHORTCUT_TYPE); Toast.makeText(context, context.getString(R.string.shortcut_installed, shortcutName), Toast.LENGTH_SHORT).show(); context.reloadAllGalleries(); if (currentRow) { Analytics.logEvent(Analytics.ADD_SHORTCUT); } else { Analytics.logEvent(Analytics.ADD_SHORTCUT_WITH_ROW); } } catch (Exception e) { Log.d(LOG_TAG, "onClick", e); } context.showCover(false); dialog.dismiss(); } }); Button buttonNo = (Button) dialog.findViewById(R.id.buttonCancel); buttonNo.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { context.showCover(false); dialog.dismiss(); } }); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { context.showCover(false); } }); context.showCover(true); dialog.show(); Analytics.logEvent(Analytics.DIALOG_ADD_SHORTCUT); }
From source file:com.javielinux.utils.Utils.java
public static void sendLastCrash(Activity cnt) { try {//from w ww . j av a2 s.c o m Intent gmail = new Intent(Intent.ACTION_VIEW); gmail.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail"); gmail.putExtra(Intent.EXTRA_EMAIL, new String[] { cnt.getString(R.string.email_send_errors) }); gmail.setData(Uri.parse(cnt.getString(R.string.email_send_errors))); gmail.putExtra(Intent.EXTRA_SUBJECT, "TweetTopics crash"); gmail.setType("plain/text"); gmail.putExtra(Intent.EXTRA_TEXT, ErrorReporter.getErrors(cnt)); cnt.startActivity(gmail); } catch (ActivityNotFoundException e) { Intent msg = new Intent(Intent.ACTION_SEND); msg.putExtra(Intent.EXTRA_EMAIL, new String[] { cnt.getString(R.string.email_send_errors) }); msg.putExtra(Intent.EXTRA_SUBJECT, "TweetTopics crash"); msg.setType("plain/text"); msg.putExtra(Intent.EXTRA_TEXT, ErrorReporter.getErrors(cnt)); cnt.startActivity(msg); } }