Java Code Examples for android.content.Intent.resolveActivity()
The following are Jave code examples for showing how to use
resolveActivity() of the
android.content.Intent
class.
You can vote up the examples you like. Your votes will be used in our system to get
more good examples.
+ Save this method
Example 1
Project: 2017.2-codigo File: LocationActivity.java View Source Code | 8 votes |
@Override protected void onListItemClick(ListView l, View v, int position, long id) { Location loc = (Location) l.getAdapter().getItem(position); Toast.makeText(this, loc.getLatitude() + " " + loc.getLongitude(), Toast.LENGTH_SHORT).show(); //simplesmente centraliza o mapa na latitude/longitude escolhida //nao amarra com google maps String locData = "geo:"+loc.getLatitude()+","+loc.getLongitude(); //locData = "geo:"+loc.getLatitude()+","+loc.getLongitude()+"(AQUI)"; //abre streetview //locData = "google.streetview:cbll="+loc.getLatitude()+","+loc.getLongitude(); //abre navigation //locData = "google.navigation:q="+loc.getLatitude()+","+loc.getLongitude(); Uri locationURI = Uri.parse(locData); Intent i = new Intent(Intent.ACTION_VIEW, locationURI); if (i.resolveActivity(getPackageManager()) != null) { startActivity(i); } }
Example 2
Project: rebase-android File: WebActivity.java View Source Code | 7 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_refresh) { refresh(); return true; } else if (id == R.id.action_copy_url) { ClipBoards.copyToClipBoard(this, webView.getUrl()); makeText(this, R.string.web_tip_copy_done, Toast.LENGTH_SHORT).show(); return true; } else if (id == R.id.action_open_url) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } else { makeText(this, R.string.web_tip_open_fail, Toast.LENGTH_LONG).show(); } return true; } return super.onOptionsItemSelected(item); }
Example 3
Project: Farmacias File: MainActivity.java View Source Code | 7 votes |
private void sendFeedbackSharingIntent(){ Intent shareIntent= ShareCompat.IntentBuilder.from(this) .setType("text/plain") //.setType("application/txt") with this flag filters much better, but not as good as sendFeedBabck .addEmailTo(getString(R.string.mailto)) .setSubject(getString(R.string.subject)) .setText(Constants.EMPTY_STRING) .setChooserTitle(R.string.sendchooser_text) .createChooserIntent() .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); if (shareIntent.resolveActivity(getPackageManager()) != null) { startActivity(shareIntent); } }
Example 4
Project: android-dev-challenge File: MainActivity.java View Source Code | 7 votes |
/** * Uses the URI scheme for showing a location found on a map in conjunction with * an implicit Intent. This super-handy Intent is detailed in the "Common Intents" page of * Android's developer site: * * @see "http://developer.android.com/guide/components/intents-common.html#Maps" * <p> * Protip: Hold Command on Mac or Control on Windows and click that link to automagically * open the Common Intents page */ private void openPreferredLocationInMap() { double[] coords = SunshinePreferences.getLocationCoordinates(this); String posLat = Double.toString(coords[0]); String posLong = Double.toString(coords[1]); Uri geoLocation = Uri.parse("geo:" + posLat + "," + posLong); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(geoLocation); if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } else { Log.d(TAG, "Couldn't call " + geoLocation.toString() + ", no receiving apps installed!"); } }
Example 5
Project: BeautifulGirls File: WebActivity.java View Source Code | 7 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); switch (id) { case R.id.action_refresh: mWebView.reload(); return true; case R.id.action_copy_url: String copyDone = getString(R.string.tip_copy_done); Util.copyToClipBoard(this, mWebView.getUrl(), copyDone); return true; case R.id.action_open_url: Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); Uri uri = Uri.parse(mUrl); intent.setData(uri); if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } else { showToast(getResources().getString(R.string.tip_open_fail)); } return true; } return super.onOptionsItemSelected(item); }
Example 6
Project: android-dev-challenge File: MainActivity.java View Source Code | 7 votes |
/** * Uses the URI scheme for showing a location found on a map in conjunction with * an implicit Intent. This super-handy Intent is detailed in the "Common Intents" page of * Android's developer site: * * @see "http://developer.android.com/guide/components/intents-common.html#Maps" * <p> * Protip: Hold Command on Mac or Control on Windows and click that link to automagically * open the Common Intents page */ private void openPreferredLocationInMap() { double[] coords = SunshinePreferences.getLocationCoordinates(this); String posLat = Double.toString(coords[0]); String posLong = Double.toString(coords[1]); Uri geoLocation = Uri.parse("geo:" + posLat + "," + posLong); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(geoLocation); if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } else { Log.d(TAG, "Couldn't call " + geoLocation.toString() + ", no receiving apps installed!"); } }
Example 7
Project: linkedout_procon File: EmployerRegisterActivity.java View Source Code | 6 votes |
public void onClickGallery(View view) { //Create new intent for selection on photo Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); if (intent.resolveActivity(getPackageManager()) != null) { // Bring up gallery to select a photo startActivityForResult(intent, PICK_PHOTO_CODE); } }
Example 8
Project: SuspendNotification File: OpenUtil.java View Source Code | 6 votes |
public static void alipayDonate(Context context) { Intent intent = new Intent(); intent.setAction("android.intent.action.VIEW"); //intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); String payUrl = "https://qr.alipay.com/FKX06496G2PCRYR0LXR7BC"; intent.setData(Uri.parse("alipayqr://platformapi/startapp?saId=10000007&clientVersion=3.7.0.0718&qrcode=" + payUrl)); if (intent.resolveActivity(context.getPackageManager()) != null) { context.startActivity(intent); } else { intent.setData(Uri.parse(payUrl)); context.startActivity(intent); } }
Example 9
Project: Google-Developer-Challenge-Scholarship-Android-Basics File: MainActivity.java View Source Code | 6 votes |
/** * This method is called when the order button is clicked. */ public void submitOrder(View view) { EditText nameField = findViewById(R.id.name_field); String name = nameField.getText().toString(); Log.v("MainActivity", "Name: " + name); // Figure out if the user wants whipped cream topping CheckBox whippedCreamCheckBox = findViewById(R.id.whipped_cream_checkbox); boolean hasWhippedCream = whippedCreamCheckBox.isChecked(); // Figure out if the user wants chocolate topping CheckBox chocolateCheckBox = findViewById(R.id.chocolate_checkbox); boolean hasChocolate = chocolateCheckBox.isChecked(); // Calculate the price int price = calculatePrice(hasWhippedCream, hasChocolate); String priceMessage = createOrderSummary(name, price, hasWhippedCream, hasChocolate); Intent intent = new Intent(Intent.ACTION_SENDTO); intent.setData(Uri.parse("mailto:")); // only email apps should handle this intent.putExtra(Intent.EXTRA_SUBJECT, "Just Java order for " + name); intent.putExtra(Intent.EXTRA_TEXT, priceMessage); if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } }
Example 10
Project: nfkita-mobile File: CampustReportActivity.java View Source Code | 6 votes |
@OnClick(R.id.btn_take_picture) public void onBtnTakePictureClicked() { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getPackageManager()) != null) { startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); } }
Example 11
Project: underlx File: MainActivity.java View Source Code | 6 votes |
@Override public void onMailtoLinkClicked(String address) { Intent intent = new Intent(Intent.ACTION_SENDTO); intent.setData(Uri.parse("mailto:")); // only email apps should handle this intent.putExtra(Intent.EXTRA_EMAIL, new String[]{address}); if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } }
Example 12
Project: Simpler File: CommonUtils.java View Source Code | 6 votes |
/** * 分享文本 * * @param context * @param text 分享的文本 */ public static void shareText(Context context, String text) { Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.setType("text/*"); shareIntent.putExtra(Intent.EXTRA_TEXT, text); ComponentName componentName = shareIntent.resolveActivity(context.getPackageManager()); if (componentName != null) { context.startActivity(Intent.createChooser(shareIntent, context.getString(R.string.share_to))); } else { AppToast.showToast("无法分享。"); } }
Example 13
Project: Ghost-Android File: PostEditFragment.java View Source Code | 6 votes |
@SuppressLint("InlinedApi") // suppressed because PermissionsDispatcher handles API levels for us @NeedsPermission(Manifest.permission.READ_EXTERNAL_STORAGE) public void onInsertImageUploadClicked(Action1<String> uploadDoneAction) { mImageUploadDoneAction = uploadDoneAction; Intent imagePickIntent = new Intent(Intent.ACTION_GET_CONTENT); imagePickIntent.addCategory(Intent.CATEGORY_OPENABLE); imagePickIntent.setType("image/*"); if (imagePickIntent.resolveActivity(mActivity.getPackageManager()) != null) { startActivityForResult(imagePickIntent, REQUEST_CODE_IMAGE_PICK); } else { Toast.makeText(mActivity, R.string.intent_no_apps, Toast.LENGTH_SHORT).show(); } }
Example 14
Project: Ghost-Android File: AppUtils.java View Source Code | 6 votes |
public static void openUri(@NonNull Context context, @NonNull String uri) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); if (intent.resolveActivity(context.getPackageManager()) != null) { context.startActivity(intent); } else { Toast.makeText(context, R.string.intent_no_apps, Toast.LENGTH_SHORT).show(); } }
Example 15
Project: Simpler File: ImageSelectFragment.java View Source Code | 6 votes |
private void showCameraAction() { if (config.maxNum <= Global.imageList.size()) { AppToast.showToast(String.format(getString(R.string.max_num), config.maxNum)); return; } if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { requestPermissions(new String[]{Manifest.permission.CAMERA}, CAMERA_REQUEST_CODE); return; } Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (cameraIntent.resolveActivity(getActivity().getPackageManager()) != null) { tempFile = new File(FileUtils.getRootPath(getActivity()) + File.separator + getActivity().getString(R.string.app_name) + "_" + System.currentTimeMillis() + ".jpg"); // 创建临时照片文件 FileUtils.createFile(tempFile); Uri uri = FileProvider.getUriForFile(getActivity(), FileUtils.getApplicationId(getActivity()) + ".provider", tempFile); List<ResolveInfo> resInfoList = getActivity().getPackageManager() .queryIntentActivities(cameraIntent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resInfoList) { String packageName = resolveInfo.activityInfo.packageName; getActivity().grantUriPermission(packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); } cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri); startActivityForResult(cameraIntent, REQUEST_CAMERA); } else { AppToast.showToast(R.string.open_camera_failure); } }
Example 16
Project: COEP-Moodle-via-Webview File: Moodle.java View Source Code | 6 votes |
public boolean onShowFileChooser(WebView view, ValueCallback<Uri[]> filePath, WebChromeClient.FileChooserParams fileChooserParams) { // Double check that we don't have any existing callbacks if (mFilePathCallback != null) { mFilePathCallback.onReceiveValue(null); } mFilePathCallback = filePath; Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath); } catch (IOException ex) { // Error occurred while creating the File Log.e(TAG, "Unable to create Image File", ex); } // Continue only if the File was successfully created if (photoFile != null) { mCameraPhotoPath = "file:" + photoFile.getAbsolutePath(); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); } else { takePictureIntent = null; } } Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT); contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE); contentSelectionIntent.setType("*/*"); Intent[] intentArray; if (takePictureIntent != null) { intentArray = new Intent[]{takePictureIntent}; } else { intentArray = new Intent[0]; } Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER); chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent); chooserIntent.putExtra(Intent.EXTRA_TITLE, "File Chooser"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray); startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE); return true; }
Example 17
Project: file.io-app File: AboutActivity.java View Source Code | 6 votes |
private void openIntent(Intent intent) { if (intent != null && intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } else { Toast.makeText(this, getString(R.string.error_no_app_on_device), Toast.LENGTH_SHORT).show(); } }
Example 18
Project: Google-Developer-Challenge-Scholarship-Android-Basics File: MainActivity.java View Source Code | 6 votes |
/** * This method is called when the order button is clicked. */ public void submitOrder(View view) { EditText nameField = findViewById(R.id.name_field); String name = nameField.getText().toString(); Log.v("MainActivity", "Name: " + name); // Figure out if the user wants whipped cream topping CheckBox whippedCreamCheckBox = findViewById(R.id.whipped_cream_checkbox); boolean hasWhippedCream = whippedCreamCheckBox.isChecked(); // Figure out if the user wants chocolate topping CheckBox chocolateCheckBox = findViewById(R.id.chocolate_checkbox); boolean hasChocolate = chocolateCheckBox.isChecked(); // Calculate the price int price = calculatePrice(hasWhippedCream, hasChocolate); String priceMessage = createOrderSummary(name, price, hasWhippedCream, hasChocolate); Intent intent = new Intent(Intent.ACTION_SENDTO); intent.setData(Uri.parse("mailto:")); // only email apps should handle this intent.putExtra(Intent.EXTRA_SUBJECT, "Just Java order for " + name); intent.putExtra(Intent.EXTRA_TEXT, priceMessage); if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } }
Example 19
Project: VanGogh File: VanConfig.java View Source Code | 6 votes |
public void dispatchCaptureIntent(Activity activity, int requestCode) { Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); captureIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); if (captureIntent.resolveActivity(activity.getPackageManager()) == null) { return; } File photoFile = null; try { photoFile = createImageFile(); } catch (IOException e) { e.printStackTrace(); } if (photoFile == null) { return; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //添加这一句表示对目标应用临时授权该Uri所代表的文件 captureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); //通过FileProvider创建一个content类型的Uri uriImage = FileProvider.getUriForFile(activity, packageName + ".fileProvider", photoFile); } else { uriImage = Uri.parse("file://" + photoFile.getAbsolutePath()); } // 默认情况下,即不需要指定intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); // 照相机有自己默认的存储路径,拍摄的照片将返回一个缩略图。如果想访问原始图片, // 可以通过dat extra能够得到原始图片位置。即,如果指定了目标uri,data就没有数据, // 如果没有指定uri,则data就返回有数据! captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriImage); activity.startActivityForResult(captureIntent, requestCode); }
Example 20
Project: LikeGank File: MainActivity.java View Source Code | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); switch (id) { case R.id.action_gank_link: Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); Uri uri = Uri.parse(getString(R.string.gank_link)); intent.setData(uri); if (intent.resolveActivity(getPackageManager()) != null) startActivity(intent); return true; } return super.onOptionsItemSelected(item); }