List of usage examples for android.content Intent resolveActivity
public ComponentName resolveActivity(@NonNull PackageManager pm)
From source file:com.cw.litenote.note_add.Note_addCameraVideo.java
private void takeVideoWithName() { Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); // Ensure that there's a camera activity to handle the intent if (takeVideoIntent.resolveActivity(getPackageManager()) != null) { // Create temporary image File where the photo will save in File tempFile = null;/*from w w w .j a v a 2 s. co m*/ try { tempFile = createTempVideoFile(); } catch (IOException ex) { // Error occurred while creating the File } // Continue only if the File was successfully created if (tempFile != null) { videoUri = Uri.fromFile(tempFile); // so far, file size is 0 takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, videoUri); // appoint Uri for captured image videoUriInDB = videoUri.toString(); startActivityForResult(takeVideoIntent, TAKE_VIDEO_ACT); } } }
From source file:com.freshdigitable.udonroad.StatusDetailFragment.java
private void setupTwitterCard(@NonNull final TwitterCard twitterCard) { this.twitterCard = twitterCard; if (!isValidForView(twitterCard)) { return;// ww w. j a va 2 s.com } final long statusId = getStatusId(); binding.sdTwitterCard.setVisibility(View.VISIBLE); binding.sdTwitterCard.bindData(twitterCard); final String imageUrl = twitterCard.getImageUrl(); if (!TextUtils.isEmpty(imageUrl)) { Picasso.with(getContext()).load(imageUrl) .resizeDimen(R.dimen.card_summary_image, R.dimen.card_summary_image).centerCrop().tag(statusId) .into(binding.sdTwitterCard.getImage()); } final Intent intent = new Intent(Intent.ACTION_VIEW); final String appUrl = twitterCard.getAppUrl(); if (!TextUtils.isEmpty(appUrl)) { intent.setData(Uri.parse(appUrl)); final ComponentName componentName = intent.resolveActivity(getContext().getPackageManager()); if (componentName == null) { intent.setData(Uri.parse(twitterCard.getUrl())); } } else { intent.setData(Uri.parse(twitterCard.getUrl())); } binding.sdTwitterCard.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { getContext().startActivity(intent); } }); }
From source file:io.mapsquare.osmcontributor.ui.activities.PhotoActivity.java
private void takePicture() { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getPackageManager()) != null) { try {/*from w w w . ja va2 s. c o m*/ photoFile = createImageFile(); } catch (IOException ex) { ex.printStackTrace(); } // Continue only if the File was successfully created if (photoFile != null) { Uri photoURI = FileProvider.getUriForFile(this, "io.mapsquare.osmcontributor.fileprovider", photoFile); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI); startActivityForResult(takePictureIntent, REQUEST_CAMERA); } } }
From source file:ca.ualberta.cs.swapmyride.View.AddInventoryActivity.java
/** * This calls the activity to take the photo. *//*from w w w. j a v a 2 s . c o m*/ private void dispatchTakePictureIntent() { // http://developer.android.com/training/permissions/requesting.html // Here, thisActivity is the current activity if (ContextCompat.checkSelfPermission(AddInventoryActivity.this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(AddInventoryActivity.this, Manifest.permission.CAMERA)) { // Show an explanation to the user *asynchronously* -- don't block // this thread waiting for the user's response! After the user // sees the explanation, try again to request the permission. } else { // No explanation needed, we can request the permission. ActivityCompat.requestPermissions(AddInventoryActivity.this, new String[] { Manifest.permission.CAMERA }, MY_PERMISSIONS_REQUEST_CAMERA); // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an // app-defined int constant. The callback method gets the // result of the request. } } else { Log.i("TakingPictureIntent", "Trying to take a photo"); Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getPackageManager()) != null && checkHasCamera(getApplicationContext())) { startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); } } }
From source file:com.mercandalli.android.apps.files.file.FileAddDialog.java
@SuppressWarnings("PMD.AvoidUsingHardCodedIP") public FileAddDialog(@NonNull final Activity activity, final int id_file_parent, @Nullable final IListener listener, @Nullable final IListener dismissListener) { super(activity, R.style.DialogFullscreen); mActivity = activity;//from www . ja v a 2 s . co m mDismissListener = dismissListener; mFileParentId = id_file_parent; mListener = listener; setContentView(R.layout.dialog_add_file); setCancelable(true); final View rootView = findViewById(R.id.dialog_add_file_root); rootView.startAnimation(AnimationUtils.loadAnimation(mActivity, R.anim.dialog_add_file_open)); rootView.setOnClickListener(this); findViewById(R.id.dialog_add_file_upload_file).setOnClickListener(this); findViewById(R.id.dialog_add_file_add_directory).setOnClickListener(this); findViewById(R.id.dialog_add_file_text_doc).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { DialogUtils.prompt(mActivity, mActivity.getString(R.string.dialog_file_create_txt), mActivity.getString(R.string.dialog_file_name_interrogation), mActivity.getString(R.string.dialog_file_create), new DialogUtils.OnDialogUtilsStringListener() { @Override public void onDialogUtilsStringCalledBack(String text) { //TODO create a online txt with content Toast.makeText(getContext(), getContext().getString(R.string.not_implemented), Toast.LENGTH_SHORT).show(); } }, mActivity.getString(android.R.string.cancel), null); FileAddDialog.this.dismiss(); } }); findViewById(R.id.dialog_add_file_scan).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(mActivity.getPackageManager()) != null) { // Create the File where the photo should go ApplicationActivity.sPhotoFile = createImageFile(); // Continue only if the File was successfully created if (ApplicationActivity.sPhotoFile != null) { if (listener != null) { ApplicationActivity.sPhotoFileListener = listener; } takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(ApplicationActivity.sPhotoFile.getFile())); mActivity.startActivityForResult(takePictureIntent, ApplicationActivity.REQUEST_TAKE_PHOTO); } } FileAddDialog.this.dismiss(); } }); findViewById(R.id.dialog_add_file_add_timer).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final Calendar currentTime = Calendar.getInstance(); DialogDatePicker dialogDate = new DialogDatePicker(mActivity, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, final int year, final int monthOfYear, final int dayOfMonth) { Calendar currentTime = Calendar.getInstance(); DialogTimePicker dialogTime = new DialogTimePicker(mActivity, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { Log.d("TIme Picker", hourOfDay + ":" + minute); final SimpleDateFormat dateFormatGmt = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss", Locale.US); dateFormatGmt.setTimeZone(TimeZone.getTimeZone("UTC")); final SimpleDateFormat dateFormatLocal = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss", Locale.US); String nowAsISO = dateFormatGmt.format(new Date()); final JSONObject json = new JSONObject(); try { json.put("type", "timer"); json.put("date_creation", nowAsISO); json.put("timer_date", "" + dateFormatGmt.format(dateFormatLocal.parse(year + "-" + (monthOfYear + 1) + "-" + dayOfMonth + " " + hourOfDay + ":" + minute + ":00"))); final SimpleDateFormat dateFormatGmtTZ = new SimpleDateFormat( "yyyy-MM-dd'T'HH-mm'Z'", Locale.US); dateFormatGmtTZ.setTimeZone(TimeZone.getTimeZone("UTC")); nowAsISO = dateFormatGmtTZ.format(new Date()); final List<StringPair> parameters = new ArrayList<>(); parameters.add(new StringPair("content", json.toString())); parameters.add(new StringPair("name", "TIMER_" + nowAsISO)); parameters.add( new StringPair("id_file_parent", "" + id_file_parent)); new TaskPost(mActivity, Constants.URL_DOMAIN + Config.ROUTE_FILE, new IPostExecuteListener() { @Override public void onPostExecute(JSONObject json, String body) { if (listener != null) { listener.execute(); } } }, parameters).execute(); } catch (JSONException | ParseException e) { Log.e(getClass().getName(), "Failed to convert Json", e); } } }, currentTime.get(Calendar.HOUR_OF_DAY), currentTime.get(Calendar.MINUTE), true); dialogTime.show(); } }, currentTime.get(Calendar.YEAR), currentTime.get(Calendar.MONTH), currentTime.get(Calendar.DAY_OF_MONTH)); dialogDate.show(); FileAddDialog.this.dismiss(); } }); findViewById(R.id.dialog_add_file_article).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { DialogCreateArticle dialogCreateArticle = new DialogCreateArticle(mActivity, listener); dialogCreateArticle.show(); FileAddDialog.this.dismiss(); } }); FileAddDialog.this.show(); }
From source file:io.jawg.osmcontributor.ui.activities.PhotoActivity.java
private void takePicture() { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getPackageManager()) != null) { try {/* ww w .j av a2 s. c o m*/ photoFile = createImageFile(); } catch (IOException ex) { ex.printStackTrace(); } // Continue only if the File was successfully created if (photoFile != null) { Uri photoURI = FileProvider.getUriForFile(this, this.getPackageName() + ".fileprovider", photoFile); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI); startActivityForResult(takePictureIntent, REQUEST_CAMERA); } } }
From source file:org.fs.galleon.presenters.ToolsFragmentPresenter.java
private void dispatchTakePictureIntent() { createIfNotExists().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()) .subscribe(file -> {//from ww w . j av a 2 s . c o m if (file.exists()) { log(Log.INFO, String.format(Locale.ENGLISH, "%s is temp file.", file.getAbsolutePath())); } if (view.isAvailable()) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (intent.resolveActivity(view.getContext().getPackageManager()) != null) { this.tempTakenPhoto = file;//set it in property Uri uri = FileProvider.getUriForFile(view.getContext(), GRANT_PERMISSION, file); intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); //fileProvider requires gran permission to others access that uri if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) { final Context context = view.getContext(); List<ResolveInfo> infos = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (infos != null) { StreamSupport.stream(infos).filter(x -> x.activityInfo != null) .map(x -> x.activityInfo.packageName).forEach(pack -> { context.grantUriPermission(pack, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); }); } } view.startActivityForResult(intent, REQUEST_TAKE_PHOTO); } else { view.showError("You need to install app that can capture photo."); } } }, this::log); }
From source file:io.syng.activity.BaseActivity.java
@Override public void onClick(View v) { switch (v.getId()) { case R.id.ll_contribute: String url = CONTRIBUTE_LINK; Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(url));//from w w w .j ava 2s.co m if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } closeDrawer(DRAWER_CLOSE_DELAY_LONG); break; case R.id.ll_settings: startActivity(new Intent(BaseActivity.this, SettingsActivity.class)); closeDrawer(DRAWER_CLOSE_DELAY_LONG); break; case R.id.drawer_header_item: if (isDrawerFrontViewActive()) { mDAppsDrawerAdapter.setEditModeEnabled(false); GeneralUtil.hideKeyBoard(mSearchTextView, BaseActivity.this); } else { mProfileDrawerAdapter.setEditModeEnabled(false); } flipDrawer(); break; } }
From source file:com.github.dfa.diaspora_android.activity.ShareActivity2.java
@SuppressLint("SetJavaScriptEnabled") @Override//from w w w . jav a 2s . c o m protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); progressBar = (ProgressBar) findViewById(R.id.progressBar); swipeView = (SwipeRefreshLayout) findViewById(R.id.swipe); swipeView.setEnabled(false); toolbar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (Helpers.isOnline(ShareActivity2.this)) { Intent intent = new Intent(ShareActivity2.this, MainActivity.class); startActivityForResult(intent, 100); overridePendingTransition(0, 0); } else { Snackbar.make(swipeView, R.string.no_internet, Snackbar.LENGTH_LONG).show(); } } }); podDomain = ((App) getApplication()).getSettings().getPodDomain(); fab = (com.getbase.floatingactionbutton.FloatingActionsMenu) findViewById(R.id.fab_expand_menu_button); fab.setVisibility(View.GONE); webView = (WebView) findViewById(R.id.webView); webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); WebSettings wSettings = webView.getSettings(); wSettings.setJavaScriptEnabled(true); wSettings.setBuiltInZoomControls(true); if (Build.VERSION.SDK_INT >= 21) wSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); /* * WebViewClient */ webView.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { Log.d(TAG, url); if (!url.contains(podDomain)) { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(i); return true; } return false; } public void onPageFinished(WebView view, String url) { Log.i(TAG, "Finished loading URL: " + url); } }); /* * WebChromeClient */ webView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView wv, int progress) { progressBar.setProgress(progress); if (progress > 0 && progress <= 60) { Helpers.getNotificationCount(wv); } if (progress > 60) { Helpers.hideTopBar(wv); } if (progress == 100) { progressBar.setVisibility(View.GONE); } else { progressBar.setVisibility(View.VISIBLE); } } @Override public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) { if (mFilePathCallback != null) mFilePathCallback.onReceiveValue(null); mFilePathCallback = filePathCallback; 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 Snackbar.make(getWindow().findViewById(R.id.drawer_layout), "Unable to get image", Snackbar.LENGTH_SHORT).show(); } // 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("image/*"); 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, "Image Chooser"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray); startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE); return true; } }); Intent intent = getIntent(); final Bundle extras = intent.getExtras(); String action = intent.getAction(); if (Intent.ACTION_SEND.equals(action)) { webView.setWebViewClient(new WebViewClient() { public void onPageFinished(WebView view, String url) { if (extras.containsKey(Intent.EXTRA_TEXT) && extras.containsKey(Intent.EXTRA_SUBJECT)) { final String extraText = (String) extras.get(Intent.EXTRA_TEXT); final String extraSubject = (String) extras.get(Intent.EXTRA_SUBJECT); webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { finish(); Intent i = new Intent(ShareActivity2.this, MainActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(i); overridePendingTransition(0, 0); return false; } }); webView.loadUrl("javascript:(function() { " + "document.getElementsByTagName('textarea')[0].style.height='110px'; " + "document.getElementsByTagName('textarea')[0].innerHTML = '**[" + extraSubject + "]** " + extraText + " *[shared with #DiasporaWebApp]*'; " + " if(document.getElementById(\"main_nav\")) {" + " document.getElementById(\"main_nav\").parentNode.removeChild(" + " document.getElementById(\"main_nav\"));" + " } else if (document.getElementById(\"main-nav\")) {" + " document.getElementById(\"main-nav\").parentNode.removeChild(" + " document.getElementById(\"main-nav\"));" + " }" + "})();"); } } }); } if (savedInstanceState == null) { if (Helpers.isOnline(ShareActivity2.this)) { webView.loadUrl("https://" + podDomain + "/status_messages/new"); } else { Snackbar.make(getWindow().findViewById(R.id.drawer_layout), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); } } }
From source file:org.odk.collect.android.views.MediaLayout.java
public void playVideo() { if (videoURI != null) { String videoFilename = ""; try {// www. j av a2s . c o m videoFilename = ReferenceManager.instance().DeriveReference(videoURI).getLocalURI(); } catch (InvalidReferenceException e) { Timber.e(e, "Invalid reference exception due to %s ", e.getMessage()); } File videoFile = new File(videoFilename); if (!videoFile.exists()) { // We should have a video clip, but the file doesn't exist. String errorMsg = getContext().getString(R.string.file_missing, videoFilename); Timber.d("File %s is missing", videoFilename); ToastUtils.showLongToast(errorMsg); return; } Intent i = new Intent("android.intent.action.VIEW"); i.setDataAndType(Uri.fromFile(videoFile), "video/*"); if (i.resolveActivity(getContext().getPackageManager()) != null) { getContext().startActivity(i); } else { ToastUtils.showShortToast(getContext().getString(R.string.activity_not_found, "view video")); } } }