List of usage examples for android.content Intent resolveActivity
public ComponentName resolveActivity(@NonNull PackageManager pm)
From source file:com.android.settings.users.EditUserPhotoController.java
private void cropPhoto(Uri pictureUri) { // TODO: Use a public intent, when there is one. Intent intent = new Intent("com.android.camera.action.CROP"); intent.setDataAndType(pictureUri, "image/*"); appendOutputExtra(intent, mCropPictureUri); appendCropExtras(intent);//w w w. j a v a 2 s . c o m if (intent.resolveActivity(mContext.getPackageManager()) != null) { try { StrictMode.disableDeathOnFileUriExposure(); mFragment.startActivityForResult(intent, REQUEST_CODE_CROP_PHOTO); } finally { StrictMode.enableDeathOnFileUriExposure(); } } else { onPhotoCropped(pictureUri, false); } }
From source file:com.concavenp.artistrymuse.ImageAppCompatActivity.java
protected void dispatchTakePictureIntent() { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(getPackageManager()) != null) { // Create the File where the photo should go File photoFile = createImageFile(); // Continue only if the File was successfully created if (photoFile != null) { Uri photoURI = FileProvider.getUriForFile(this, "com.concavenp.artistrymuse", photoFile); Log.d(TAG, "New camera image URI location: " + photoURI.toString()); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI); startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); }/* w ww.j a va 2 s .co m*/ } }
From source file:ng.uavp.ch.ngusbterminal.FileSelectFragment.java
@Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { currentFile = fileList.get(position); if (!currentFile.isDirectory()) { Intent intent = new Intent(Intent.ACTION_EDIT); Uri uri = Uri.parse("file://" + currentFile.getAbsolutePath()); intent.setDataAndType(uri, "text/plain"); if (intent.resolveActivity(getActivity().getPackageManager()) != null) { startActivity(intent);// ww w. ja v a2 s . c om } else { showToast(R.string.err_cannot_edit, Toast.LENGTH_SHORT); } } return false; }
From source file:io.radio.streamer.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // The action bar home/up action should open or close the drawer. // ActionBarDrawerToggle will take care of this. if (mDrawerToggle.onOptionsItemSelected(item)) { return true; }//from w w w. j av a 2s. co m // Handle action buttons switch (item.getItemId()) { case R.id.action_search: // create intent to search Intent intent = new Intent(Intent.ACTION_SEARCH); // catch event that there's no activity to handle intent if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } else { Toast.makeText(this, R.string.search_not_available, Toast.LENGTH_LONG).show(); } return true; default: return super.onOptionsItemSelected(item); } }
From source file:eu.pellerito.popularmoviesproject2.fragment.DetailFragment.java
private void playTrailer(String key) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Costants.YOUTUBE_URI_INTENT + key)); if (intent.resolveActivity(mContext.getPackageManager()) != null) { startActivity(intent);/*from ww w . j av a 2 s . co m*/ } }
From source file:com.example.android.apprestrictionenforcer.SetupProfileFragment.java
/** * Initiates the managed profile provisioning. If we already have a managed profile set up on * this device, we will get an error dialog in the following provisioning phase. *//*from w w w. j a v a2 s .co m*/ private void provisionManagedProfile() { Activity activity = getActivity(); if (null == activity) { return; } Intent intent = new Intent(ACTION_PROVISION_MANAGED_PROFILE); if (Build.VERSION.SDK_INT >= 24) { intent.putExtra(EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME, EnforcerDeviceAdminReceiver.getComponentName(activity)); } else { intent.putExtra(EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME, activity.getApplicationContext().getPackageName()); intent.putExtra(EXTRA_DEVICE_ADMIN, EnforcerDeviceAdminReceiver.getComponentName(activity)); } if (intent.resolveActivity(activity.getPackageManager()) != null) { startActivityForResult(intent, REQUEST_PROVISION_MANAGED_PROFILE); activity.finish(); } else { Toast.makeText(activity, "Device provisioning is not enabled. Stopping.", Toast.LENGTH_SHORT).show(); } }
From source file:com.lcl6.cn.imagepickerl.AndroidImagePicker.java
/** * take picture/*from ww w . j a v a2 s .c o m*/ */ public void takePicture(Activity act, int requestCode) throws IOException { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(act.getPackageManager()) != null) { // Create the File where the photo should go //File photoFile = createImageFile(); File photoFile = createImageSaveFile(act); // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); } } act.startActivityForResult(takePictureIntent, requestCode); }
From source file:me.trashout.fragment.EventDetailFragment.java
@OnClick({ R.id.event_detail_join_btn, R.id.event_detail_phone_layout, R.id.event_detail_email_layout, R.id.event_detail_direction_btn }) public void onClick(View view) { switch (view.getId()) { case R.id.event_detail_join_btn: if (mEvent != null) { if (user == null) { showToast(R.string.event_signToJoin); } else { MaterialDialog dialog = new MaterialDialog.Builder(getActivity()) .title(R.string.global_validation_warning) .content(R.string.event_joinEventConfirmationMessage).positiveText(android.R.string.ok) .negativeText(android.R.string.cancel).autoDismiss(true) .onPositive(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { showProgressDialog(); JoinUserToEventService.startForRequest(getContext(), JOIN_TO_EVENT_REQUEST_ID, mEvent.getId(), Collections.singletonList(user.getId())); }/*ww w . ja va 2s . c om*/ }).build(); dialog.show(); } } break; case R.id.event_detail_phone_layout: if (mEvent != null && mEvent.getContact() != null && !TextUtils.isEmpty(mEvent.getContact().getPhone())) { Intent intent = new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel", mEvent.getContact().getPhone(), null)); startActivity(intent); } break; case R.id.event_detail_email_layout: if (mEvent != null && mEvent.getContact() != null && !TextUtils.isEmpty(mEvent.getContact().getEmail())) { sendEmail(); } break; case R.id.event_detail_direction_btn: if (mEvent != null) { Uri gmmIntentUri = Uri.parse("http://maps.google.com/maps?daddr=" + mEvent.getGps().getLat() + "," + mEvent.getGps().getLng()); Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri); mapIntent.setPackage("com.google.android.apps.maps"); if (mapIntent.resolveActivity(getActivity().getPackageManager()) != null) { startActivity(mapIntent); } } break; } }
From source file:dentex.youtube.downloader.ShareActivity.java
public static void NotificationHelper() { pt1 = mContext.getString(R.string.notification_downloading_pt1); pt2 = mContext.getString(R.string.notification_downloading_pt2); noDownloads = mContext.getString(R.string.notification_no_downloads); mBuilder = new NotificationCompat.Builder(mContext); mBuilder.setSmallIcon(R.drawable.ic_stat_ytd) .setContentTitle(mContext.getString(R.string.title_activity_share)) .setContentText(mContext.getString(R.string.notification_downloading_pt1) + " " + sequence.size() + " " + mContext.getString(R.string.notification_downloading_pt2)); mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(android.app.DownloadManager.ACTION_VIEW_DOWNLOADS); if (notificationIntent.resolveActivity(mContext.getPackageManager()) != null) { notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); } else {//from ww w . j a v a 2 s . c o m Log.e(DEBUG_TAG, "notificationIntent not resolved"); } PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, notificationIntent, 0); mBuilder.setContentIntent(contentIntent); mId = 1; mNotificationManager.notify(mId, mBuilder.build()); }
From source file:com.pizidea.imagepicker.AndroidImagePicker.java
/** * take picture//from www . jav a2s . co m */ public void takePicture(Context ctx, int requestCode) throws IOException { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(ctx.getPackageManager()) != null) { // Create the File where the photo should go //File photoFile = createImageFile(); File photoFile = createImageSaveFile(ctx); // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); } } if (ctx instanceof Activity) { ((Activity) ctx).startActivityForResult(takePictureIntent, requestCode); } }