/** * Display a new browser with the specified URL. * * @param url The url to load. * @param usePhoneGap Load url in PhoneGap webview * @return "" if ok, or error message. */ public String openExternal(String url, boolean usePhoneGap) { try { Intent intent = null; if (usePhoneGap) { intent = new Intent().setClass(this.cordova.getActivity(), org.apache.cordova.DroidGap.class); intent.setData(Uri.parse(url)); // This line will be removed in future. intent.putExtra("url", url); // Timeout parameter: 60 sec max - May be less if http device timeout is less. intent.putExtra("loadUrlTimeoutValue", 60000); // These parameters can be configured if you want to show the loading dialog intent.putExtra("loadingDialog", "Wait,Loading web page..."); // show loading dialog intent.putExtra( "hideLoadingDialogOnPageLoad", true); // hide it once page has completely loaded } else { intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(url)); } this.cordova.getActivity().startActivity(intent); return ""; } catch (android.content.ActivityNotFoundException e) { Log.d(LOG_TAG, "ChildBrowser: Error loading url " + url + ":" + e.toString()); return e.toString(); } }
protected void onListItemClick(ListView l, View v, int position, long id) { ProfilerAudioAdapter profileAudioAdapter = (ProfilerAudioAdapter) getListAdapter(); String selectedValue = profileAudioAdapter.getItem(position); Toast.makeText(this, selectedValue, Toast.LENGTH_SHORT).show(); GetFile task = new GetFile(); String extStorageDirectory = Environment.getExternalStorageDirectory().toString(); File folder = new File(extStorageDirectory, "Audio"); folder.mkdir(); ArrayList<String> params = new ArrayList<String>(); params.add(fileLocation[position]); params.add(fileName[position]); params.add(String.valueOf(folder)); task.execute(new ArrayList[] {params}); try { Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); File fileToRead = new File(folder + "/" + fileName[position]); Uri uri = Uri.fromFile(fileToRead.getAbsoluteFile()); intent.setDataAndType(uri, "audio/mp3"); startActivity(intent); } catch (ActivityNotFoundException activityNotFoundException) { activityNotFoundException.printStackTrace(); Toast.makeText(this, "There doesn't seem to be an Audio player installed.", Toast.LENGTH_LONG) .show(); } catch (Exception ex) { ex.printStackTrace(); Toast.makeText(this, "Cannot open the selected file.", Toast.LENGTH_LONG).show(); } }
private void clickMasterIntent(Integer request) { EditText inputText = (EditText) findViewById(R.id.input_entry); String inputStr = inputText.getText().toString(); Intent i = new Intent(); i.putExtra(CryptoIntents.EXTRA_TEXT, inputStr); if (request == ENCRYPT_REQUEST) { i.setAction(CryptoIntents.ACTION_ENCRYPT); } else if (request == DECRYPT_REQUEST) { i.setAction(CryptoIntents.ACTION_DECRYPT); } else if (request == GET_PASSWORD_REQUEST) { i.putExtra(CryptoIntents.EXTRA_UNIQUE_NAME, inputStr); i.setAction(CryptoIntents.ACTION_GET_PASSWORD); } else if (request == SET_PASSWORD_REQUEST) { String uniqueNameStr = ((EditText) findViewById(R.id.unique_name_entry)).getText().toString(); String passwordStr = ((EditText) findViewById(R.id.password_entry)).getText().toString(); String usernameStr = ((EditText) findViewById(R.id.username_entry)).getText().toString(); i.putExtra(CryptoIntents.EXTRA_UNIQUE_NAME, uniqueNameStr); i.putExtra(CryptoIntents.EXTRA_PASSWORD, passwordStr); i.putExtra(CryptoIntents.EXTRA_USERNAME, usernameStr); i.setAction(CryptoIntents.ACTION_SET_PASSWORD); } try { startActivityForResult(i, request); } catch (ActivityNotFoundException e) { Log.e(TAG, "failed to invoke intent: " + e.toString()); } }
protected void doTakePhoto() { try { Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(cameraIntent, CAMERA_WITH_DATA); } catch (ActivityNotFoundException e) { e.printStackTrace(); } }
private void actZooper() { Uri zooperuriString = Uri.parse(getString(R.string.zooper_link)); Intent zooperIntent = new Intent("android.intent.action.VIEW", zooperuriString); try { startActivity(zooperIntent); } catch (ActivityNotFoundException e2) { e2.printStackTrace(); } };
public static void startActivityOrWarn(Context ctx, Intent intent, String errorMessage) { try { ctx.startActivity(intent); } catch (ActivityNotFoundException e) { L.w(e); new AbstractDialogFactory(ctx) .showToast((errorMessage != null) ? errorMessage : e.getMessage()); } }
/** * 调用系统的拍照界面去拍照,并获取结果 * * @param * @param filePath 保存相片的全路径 * @param requestCode */ public static void capturePhotoForResult(FragmentBase a, String filePath, int requestCode) { Intent it = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); it.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(filePath))); try { a.startActivityForResult(it, requestCode); } catch (ActivityNotFoundException e) { e.printStackTrace(); } }
public static void capturePhotoForResult(Activity a, Uri uri, int requestCode) { Intent it = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); it.putExtra(MediaStore.EXTRA_OUTPUT, uri); try { a.startActivityForResult(it, requestCode); } catch (ActivityNotFoundException e) { e.printStackTrace(); } }
public void showChooser(View view) { Intent target = FileUtils.createGetHtmlContentIntent(); Intent intent = Intent.createChooser(target, getString(R.string.choose_program)); try { startActivityForResult(intent, REQUEST_CODE); } catch (ActivityNotFoundException e) { e.printStackTrace(); } }
private void actUCCW() { Uri uccwuriString = Uri.parse(getString(R.string.uccw_link)); Intent uccwIntent = new Intent("android.intent.action.VIEW", uccwuriString); try { startActivity(uccwIntent); } catch (ActivityNotFoundException e2) { e2.printStackTrace(); } };
static boolean openUri(@Nonnull Activity activity, @Nonnull String uri) { try { activity.startActivity(new Intent(ACTION_VIEW, Uri.parse(uri))); return true; } catch (ActivityNotFoundException e) { Log.e("Checkout", e.getMessage(), e); } return false; }
// NOTE: Currently not reentrant / doesn't support concurrent requests @ReactMethod public void launchImageLibrary(final ReadableMap options, final Callback callback) { response = Arguments.createMap(); if (options.hasKey("noData")) { noData = options.getBoolean("noData"); } if (options.hasKey("maxWidth")) { maxWidth = options.getInt("maxWidth"); } if (options.hasKey("maxHeight")) { maxHeight = options.getInt("maxHeight"); } if (options.hasKey("aspectX")) { aspectX = options.getInt("aspectX"); } if (options.hasKey("aspectY")) { aspectY = options.getInt("aspectY"); } if (options.hasKey("quality")) { quality = (int) (options.getDouble("quality") * 100); } tmpImage = true; if (options.hasKey("storageOptions")) { tmpImage = false; } if (options.hasKey("allowsEditing")) { allowEditing = options.getBoolean("allowsEditing"); } forceAngle = false; if (options.hasKey("angle")) { forceAngle = true; angle = options.getInt("angle"); } if (options.hasKey("assetProperties")) { assetProperties = options.getBoolean("assetProperties"); } Intent libraryIntent = new Intent( Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); if (libraryIntent.resolveActivity(mMainActivity.getPackageManager()) == null) { response.putString("error", "Cannot launch photo library"); callback.invoke(response); return; } mCallback = callback; try { mMainActivity.startActivityForResult(libraryIntent, REQUEST_LAUNCH_IMAGE_LIBRARY); } catch (ActivityNotFoundException e) { e.printStackTrace(); } }
@Override public void openUri(Activity activity, Uri uri) { Toast.makeText(activity, R.string.custom_tabs_failed, Toast.LENGTH_SHORT).show(); try { activity.startActivity(new Intent(Intent.ACTION_VIEW, uri)); } catch (ActivityNotFoundException e) { e.printStackTrace(); Toast.makeText(activity, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); } }
/** * 拍照获取图片 * * @param cropImg */ private void doTakePhoto() { try { final Intent intent = getTakePickIntent(mCurrentPhotoFile); if (fragmentContext != null) fragmentContext.startActivityForResult(intent, CAMERA_WITH_DATA); else activityContext.startActivityForResult(intent, CAMERA_WITH_DATA); } catch (ActivityNotFoundException e) { e.printStackTrace(); Toast.makeText(activityContext, "图片获取失败", _2000).show(); } }
public static void startActivity(Context cxt, String user) { Uri uri = Uri.parse("query://"); Intent intent = new Intent(ACTION, uri); intent.putExtra("workercode", user); try { cxt.startActivity(intent); } catch (ActivityNotFoundException e) { e.printStackTrace(); } }
public static void openMarketDetails(final Context context, String packageName) { try { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("market://details?id=" + packageName)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } catch (final ActivityNotFoundException e) { e.printStackTrace(); } }
// 请求Gallery程序 private void doPickPhotoFromGallery() { try { // Launch picker to choose photo for selected contact final Intent intent = getPhotoPickIntent(); if (fragmentContext != null) fragmentContext.startActivityForResult(intent, PHOTO_PICKED); else activityContext.startActivityForResult(intent, PHOTO_PICKED); } catch (ActivityNotFoundException e) { e.printStackTrace(); Toast.makeText(activityContext, "图片获取失败", _2000).show(); } }
public static void startActivity(Context cxt) { // String action = "com.ccssoft.subsystem.KEY_LOGIN"; Uri uri = Uri.parse("query://"); Intent intent = new Intent(ACTION, uri); intent.putExtra("workercode", "gzadmin"); try { cxt.startActivity(intent); } catch (ActivityNotFoundException e) { e.printStackTrace(); } }
@Override public void onClick(View v) { // TODO Auto-generated method stub int id = v.getId(); if (id == R.id.button_camera) { String sdStatus = Environment.getExternalStorageState(); if (!sdStatus.equals(Environment.MEDIA_MOUNTED)) { // Log.d("MainActivity", "SD card is not avaiable/writeable right now."); return; } try { File dir = new File(Environment.getExternalStorageDirectory() + "/DCIM/Camera"); if (!dir.exists()) dir.mkdirs(); String name = DateFormat.format("yyyyMMdd_hhmmss", Calendar.getInstance(Locale.CHINA)) + ".jpg"; File f = new File(dir, name); Intent intent0 = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent0.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f)); intent0.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); Intent intent = Intent.createChooser(intent0, null); mCameraPicPath = f.getAbsolutePath(); startActivityForResult(intent, req_capture); } catch (ActivityNotFoundException e) { e.printStackTrace(); } } else if (id == R.id.button_op) { if (mIndex == view_all) { if (mViewAll.haveData()) mViewAll.setEditMode(true); } else if (mIndex == view_like) { if (mViewLike.haveData()) mViewLike.setEditMode(true); } } else if (id == R.id.button_menu) { { showSettingMenu(); } } else if (id == R.id.button_all) { mViewPager.setCurrentItem(view_all); } else if (id == R.id.button_dir) { mViewPager.setCurrentItem(view_dir); } else if (id == R.id.button_like) { mViewPager.setCurrentItem(view_like); } }
private void actPlay() { Uri marketuriString = Uri.parse(getString(R.string.play_link)); Intent playintent = new Intent(Intent.ACTION_VIEW, marketuriString); try { startActivity(playintent); } catch (ActivityNotFoundException e2) { e2.printStackTrace(); Toast.makeText( getActivity().getApplicationContext(), "Play Store not found!", Toast.LENGTH_LONG) .show(); } };
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param usePhoneGap Load url in PhoneGap webview * @return "" if ok, or error message. */ public String openExternal(String url) { try { Intent intent = null; intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(url)); this.cordova.getActivity().startActivity(intent); return ""; } catch (android.content.ActivityNotFoundException e) { Log.d(LOG_TAG, "InAppBrowser: Error loading url " + url + ":" + e.toString()); return e.toString(); } }
private void activateRecognize() { try { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra( RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Delon-kun Voice Recognition"); startActivityForResult(intent, REQUEST_CODE); } catch (ActivityNotFoundException e) { e.printStackTrace(); } }
private void actExtras2() { Uri extras2uriString = Uri.parse( getString( R.string.extras2_link)); // use this to link to your UCCW skins on Play or Website Intent extras2Intent = new Intent("android.intent.action.VIEW", extras2uriString); try { startActivity(extras2Intent); } catch (ActivityNotFoundException e2) { e2.printStackTrace(); } };
private void showFileChooser() { // Intent intent = new Intent(); Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); try { // startActivityForResult(Intent.createChooser(intent,"Complete action using"), UPDATE_PIC); startActivityForResult(intent, UPDATE_PIC); } catch (ActivityNotFoundException e) { e.printStackTrace(); Snackbar.make(profileImgView, "Activity not found", Snackbar.LENGTH_LONG) .setAction("Action", null) .show(); } }
@Override public void onClick(View v) { // Perform action on click switch (v.getId()) { case R.id.home: // Log.e("MyPagerAdapter", "home"); // ctx.setScrollX(0); break; case R.id.about: // Log.e("MyPagerAdapter", "about"); LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.about, null); break; case R.id.secret: // Log.e("MyPagerAdapter", "secret"); break; case R.id.anyproblemsemail: Intent emailIntent = new Intent(Intent.ACTION_SEND); emailIntent.setType("text/html"); emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); emailIntent.putExtra(Intent.EXTRA_EMAIL, email); emailIntent.putExtra(Intent.EXTRA_SUBJECT, "For testing............"); ctx.startActivity(Intent.createChooser(emailIntent, email)); break; case R.id.anyproblemsnum: try { Intent my_callIntent = new Intent(Intent.ACTION_CALL); my_callIntent.setData( Uri.parse( "tel:" + num)); // here the word 'tel' is important for making a call... // ctx.startActivityForResult(my_callIntent , 1); ctx.startActivity(my_callIntent); // finish(); } catch (ActivityNotFoundException e) { Toast.makeText(ctx, "Error in your phone call" + e.getMessage(), Toast.LENGTH_LONG) .show(); } break; } }
/** * 拨打指定号码的电话 * * @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; }
// Executed after a user inputs their email address and clicks the "OK" button // Thanks: // http://stackoverflow.com/questions/2197741/how-can-i-send-emails-from-my-android-application private void emailConsentForm(String email) { final Intent emailIntent = new Intent(Intent.ACTION_SEND); emailIntent .setType("text/html") .putExtra(Intent.EXTRA_EMAIL, new String[] {email}) .putExtra(Intent.EXTRA_SUBJECT, getString(R.string.email_subject)) .putExtra(Intent.EXTRA_TEXT, Html.fromHtml(getString(R.string.email_body))); try { startActivity(Intent.createChooser(emailIntent, "Send e-mail")); } catch (final android.content.ActivityNotFoundException e) { Toast.makeText(this, "There are no email clients installed.", Toast.LENGTH_SHORT).show(); Log.e(Common.LOG_TAG, "Could not open an email client. Original error: " + e.toString()); } installPython(); saveSharedBooleanPreference(CONSENT_COMPLETED, true); }
@Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); ApplicationInfo app = applist.get(position); try { Intent intent = packageManager.getLaunchIntentForPackage(app.packageName); if (null != intent) { startActivity(intent); } } catch (ActivityNotFoundException e) { Toast.makeText(AllAppsActivity.this, e.getMessage(), Toast.LENGTH_LONG).show(); } catch (Exception e) { Toast.makeText(AllAppsActivity.this, e.getMessage(), Toast.LENGTH_LONG).show(); } }
void configWifi() { Log.d(TAG, "show net config interface"); try { if (Utils.ANDROID_VERSION >= 16) { Intent in = new Intent(Settings.ACTION_WIFI_SETTINGS); startActivity(in); } else { Intent in = new Intent(Settings.ACTION_WIRELESS_SETTINGS); startActivity(in); } } catch (ActivityNotFoundException anf) { Log.d(TAG, "no activity for : Settings.ACTION_WIRELESS_SETTINGS" + anf.getMessage()); Intent in = new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK); startActivity(in); } }
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == RHelper.getId("menu_history_send")) { CharSequence history = historyManager.buildHistory(); Parcelable historyFile = HistoryManager.saveHistory(history.toString()); if (historyFile == null) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(RHelper.getString("msg_unmount_usb")); builder.setPositiveButton(RHelper.getString("button_ok"), null); builder.show(); } else { Intent intent = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:")); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); String subject = getResources().getString(RHelper.getString("history_email_title")); intent.putExtra(Intent.EXTRA_SUBJECT, subject); intent.putExtra(Intent.EXTRA_TEXT, subject); intent.putExtra(Intent.EXTRA_STREAM, historyFile); intent.setType("text/csv"); try { startActivity(intent); } catch (ActivityNotFoundException anfe) { Log.w(TAG, anfe.toString()); } } } else if (item.getItemId() == RHelper.getId("menu_history_clear_text")) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(RHelper.getString("msg_sure")); builder.setCancelable(true); builder.setPositiveButton( RHelper.getString("button_ok"), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int i2) { historyManager.clearHistory(); dialog.dismiss(); finish(); } }); builder.setNegativeButton(RHelper.getString("button_cancel"), null); builder.show(); } else { return super.onOptionsItemSelected(item); } return true; }