List of usage examples for android.content Intent getData
public @Nullable Uri getData()
From source file:androidx.navigation.NavController.java
/** * Checks the given Intent for a Navigation deep link and navigates to the deep link if present. * This is called automatically for you the first time you set the graph if you've passed in an * {@link Activity} as the context when constructing this NavController, but should be manually * called if your Activity receives new Intents in {@link Activity#onNewIntent(Intent)}. * <p>//ww w .ja va 2s . c o m * The types of Intents that are supported include: * <ul> * <ol>Intents created by {@link NavDeepLinkBuilder} or * {@link #createDeepLink()}. This assumes that the current graph shares * the same hierarchy to get to the deep linked destination as when the deep link was * constructed.</ol> * <ol>Intents that include a {@link Intent#getData() data Uri}. This Uri will be checked * against the Uri patterns added via {@link NavDestination#addDeepLink(String)}.</ol> * </ul> * <p>The {@link #getGraph() navigation graph} should be set before calling this method.</p> * @param intent The Intent that may contain a valid deep link * @return True if the navigation controller found a valid deep link and navigated to it. * @see NavDestination#addDeepLink(String) */ public boolean onHandleDeepLink(@Nullable Intent intent) { if (intent == null) { return false; } Bundle extras = intent.getExtras(); int[] deepLink = extras != null ? extras.getIntArray(KEY_DEEP_LINK_IDS) : null; Bundle bundle = new Bundle(); Bundle deepLinkExtras = extras != null ? extras.getBundle(KEY_DEEP_LINK_EXTRAS) : null; if (deepLinkExtras != null) { bundle.putAll(deepLinkExtras); } if ((deepLink == null || deepLink.length == 0) && intent.getData() != null) { Pair<NavDestination, Bundle> matchingDeepLink = mGraph.matchDeepLink(intent.getData()); if (matchingDeepLink != null) { deepLink = matchingDeepLink.first.buildDeepLinkIds(); bundle.putAll(matchingDeepLink.second); } } if (deepLink == null || deepLink.length == 0) { return false; } bundle.putParcelable(KEY_DEEP_LINK_INTENT, intent); int flags = intent.getFlags(); if ((flags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0 && (flags & Intent.FLAG_ACTIVITY_CLEAR_TASK) == 0) { // Someone called us with NEW_TASK, but we don't know what state our whole // task stack is in, so we need to manually restart the whole stack to // ensure we're in a predictably good state. intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(mContext) .addNextIntentWithParentStack(intent); taskStackBuilder.startActivities(); if (mActivity != null) { mActivity.finish(); } return true; } if ((flags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) { // Start with a cleared task starting at our root when we're on our own task if (!mBackStack.isEmpty()) { navigate(mGraph.getStartDestination(), bundle, new NavOptions.Builder() .setPopUpTo(mGraph.getId(), true).setEnterAnim(0).setExitAnim(0).build()); } int index = 0; while (index < deepLink.length) { int destinationId = deepLink[index++]; NavDestination node = findDestination(destinationId); if (node == null) { throw new IllegalStateException("unknown destination during deep link: " + NavDestination.getDisplayName(mContext, destinationId)); } node.navigate(bundle, new NavOptions.Builder().setEnterAnim(0).setExitAnim(0).build()); } return true; } // Assume we're on another apps' task and only start the final destination NavGraph graph = mGraph; for (int i = 0; i < deepLink.length; i++) { int destinationId = deepLink[i]; NavDestination node = i == 0 ? mGraph : graph.findNode(destinationId); if (node == null) { throw new IllegalStateException("unknown destination during deep link: " + NavDestination.getDisplayName(mContext, destinationId)); } if (i != deepLink.length - 1) { // We're not at the final NavDestination yet, so keep going through the chain graph = (NavGraph) node; } else { // Navigate to the last NavDestination, clearing any existing destinations node.navigate(bundle, new NavOptions.Builder().setPopUpTo(mGraph.getId(), true).setEnterAnim(0) .setExitAnim(0).build()); } } return true; }
From source file:com.cloudstudio.camera.ForegroundCameraLauncher.java
/** * Called when the camera view exits.//from w w w . jav a2 s . c om * * @param requestCode * The request code originally supplied to * startActivityForResult(), allowing you to identify who this * result came from. * @param resultCode * The integer result code returned by the child activity through * its setResult(). * @param intent * An Intent, which can return result data to the caller (various * data can be attached to Intent "extras"). */ public void onActivityResult(int requestCode, int resultCode, Intent intent) { // If image available if (resultCode == Activity.RESULT_OK) { try { // Create an ExifHelper to save the exif data that is lost // during compression ExifHelper exif = new ExifHelper(); exif.createInFile( getTempDirectoryPath(this.cordova.getActivity().getApplicationContext()) + "/Pic.jpg"); exif.readExifData(); // Read in bitmap of captured image Bitmap bitmap; try { bitmap = android.provider.MediaStore.Images.Media .getBitmap(this.cordova.getActivity().getContentResolver(), imageUri); } catch (FileNotFoundException e) { Uri uri = intent.getData(); android.content.ContentResolver resolver = this.cordova.getActivity().getContentResolver(); bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri)); } bitmap = scaleBitmap(bitmap); // Create entry in media store for image // (Don't use insertImage() because it uses default compression // setting of 50 - no way to change it) ContentValues values = new ContentValues(); values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); Uri uri = null; try { Log.d("camera", "external_content_uri:" + android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); uri = this.cordova.getActivity().getContentResolver() .insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); } catch (UnsupportedOperationException e) { LOG.d(LOG_TAG, "Can't write to external media storage."); try { uri = this.cordova.getActivity().getContentResolver() .insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values); } catch (UnsupportedOperationException ex) { LOG.d(LOG_TAG, "Can't write to internal media storage."); this.failPicture("Error capturing image - no media storage found."); return; } } Log.d("camera", "uri:" + uri.toString()); // Add compressed version of captured image to returned media // store Uri OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri); bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); os.close(); // Restore exif data to file exif.createOutFile(getRealPathFromURI(uri, this.cordova)); exif.writeExifData(); // Send Uri back to JavaScript for viewing image this.callbackContext.success(getRealPathFromURI(uri, this.cordova)); bitmap.recycle(); bitmap = null; System.gc(); checkForDuplicateImage(); } catch (IOException e) { e.printStackTrace(); this.failPicture("Error capturing image."); } } // If cancelled else if (resultCode == Activity.RESULT_CANCELED) { this.failPicture("Camera cancelled."); } // If something else else { this.failPicture("Did not complete!"); } }
From source file:com.aimfire.gallery.cardboard.PhotoActivity.java
/** * Sets the view to our CardboardView and initializes the transformation matrices we will use * to render our scene./*from ww w . java2 s .c om*/ */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_photo); loadDisplayPrefs(); /* * show error message in case no photo to be displayed */ mOverlayView = (CardboardOverlayView) findViewById(R.id.overlay); Intent intent = getIntent(); mIsMyMedia = intent.getBooleanExtra(MainConsts.EXTRA_MSG, false); mAssetColor = intent.getBooleanExtra(MainConsts.EXTRA_COLOR, true); Uri uri = intent.getData(); if (uri != null) { String filePath = getFilePathFromUri(uri); if (filePath == null) { Toast.makeText(this, "Please open downloaded file from a file manager/explorer.", Toast.LENGTH_LONG) .show(); finish(); return; } File f = new File(filePath); String fileName = f.getName(); if (!filePath.endsWith("jpg")) { /* * something's wrong. no point in continuing */ Toast.makeText(this, R.string.error_no_media, Toast.LENGTH_LONG).show(); finish(); return; } if (!filePath.contains(MainConsts.MEDIA_3D_ROOT_PATH)) { /* * in case we got here directly without going thru MainActivity * first, it's possible we don't have storage initialized yet. */ if (!FileUtils.initStorage()) { Toast.makeText(this, R.string.error_accessing_storage, Toast.LENGTH_LONG).show(); finish(); return; } /* * we are launched from external apps by host or file type. move the * file to our "shared with me" dir. if rename fails, we will have * to do the actual copy (rather than rename, as we may be copying * the file from internal to external storage; or we don't have * write permission on the source directory) */ String newFilePath = MainConsts.MEDIA_3D_SHARED_PATH + fileName; boolean success = false; try { File from = (new File(filePath)); File to = (new File(newFilePath)); success = from.renameTo(to); } catch (Exception e) { e.printStackTrace(); } if (!success) { FileUtils.copyFile(filePath, newFilePath); } filePath = newFilePath; /* * make MediaScanner aware of the new file */ MediaScanner.addItemMediaList(filePath); } mAssetList = MediaScanner.getNonEmptyPhotoList( mIsMyMedia ? MainConsts.MEDIA_3D_SAVE_DIR : MainConsts.MEDIA_3D_SHARED_DIR); if ((mAssetList != null) && (mAssetList.size() > 0)) { mAssetInd = mAssetList.indexOf(filePath); if (mAssetInd == -1) { if (BuildConfig.DEBUG) Log.e(TAG, "onCreate: specified photo not found, path=" + filePath); mAssetInd = 0; } if (BuildConfig.DEBUG) Log.d(TAG, "onCreate: mMovieList size=" + mAssetList.size() + ", index=" + mAssetInd); } else { if (BuildConfig.DEBUG) Log.e(TAG, "onCreate: no photo found!"); mOverlayView.show3DToast("no photo found!", 5000); } } else { if (BuildConfig.DEBUG) Log.d(TAG, "onCreate: no file uri specified in intent, are we " + "directly envoked by daydream?"); mAssetList = MediaScanner.getNonEmptyPhotoList( mIsMyMedia ? MainConsts.MEDIA_3D_SAVE_DIR : MainConsts.MEDIA_3D_SHARED_DIR); if ((mAssetList != null) && (mAssetList.size() > 0)) { mAssetInd = 0; if (BuildConfig.DEBUG) Log.d(TAG, "onCreate: mAssetList size=" + mAssetList.size() + ", index=" + mAssetInd); } else { if (BuildConfig.DEBUG) Log.e(TAG, "onCreate: no photo found!"); mOverlayView.show3DToast("no photo found!", 5000); } } /* * initialize cardboard related stuff */ mCardboardView = (GvrView) findViewById(R.id.cardboard_view); mCardboardView.setRenderer(this); mCardboardView.setOnTouchListener(otl); mCardboardView.setTransitionViewEnabled(true); // Enable Cardboard-trigger feedback with Daydream headsets. This is a simple way of supporting // Daydream controller input for basic interactions using the existing Cardboard trigger API. mCardboardView.enableCardboardTriggerEmulation(); setGvrView(mCardboardView); //debug //ScreenParams sp = mCardboardView.getScreenParams(); //if(BuildConfig.DEBUG) Log.i(TAG, "ScreenParams width=" + sp.getWidth() + ", height=" + sp.getHeight()); //mPicRotation = new float[16]; //mPicFrustum = new float[16]; mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); mHgd = new HeadGestureDetector(this); }
From source file:nf.frex.android.FrexActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode != Activity.RESULT_OK) { return;//from w w w . ja va 2s . c o m } if (requestCode == R.id.manage_fractals && data.getAction().equals(Intent.ACTION_VIEW)) { final Uri imageUri = data.getData(); if (imageUri != null) { File imageFile = new File(imageUri.getPath()); String configName = FrexIO.getFilenameWithoutExt(imageFile); File paramFile = new File(imageFile.getParent(), configName + FrexIO.PARAM_FILE_EXT); try { FileInputStream fis = new FileInputStream(paramFile); try { readFrexDoc(fis, configName); } finally { fis.close(); } } catch (IOException e) { Toast.makeText(FrexActivity.this, getString(R.string.error_msg, e.getLocalizedMessage()), Toast.LENGTH_SHORT).show(); } } } else if (requestCode == R.id.settings) { view.getGenerator().setNumTasks(SettingsActivity.getNumTasks(this)); } else if (requestCode == SELECT_PICTURE_REQUEST_CODE) { final Uri imageUri = data.getData(); final ColorQuantizer colorQuantizer = new ColorQuantizer(); final ProgressDialog progressDialog = new ProgressDialog(FrexActivity.this); final DialogInterface.OnCancelListener cancelListener = new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (progressDialog.isShowing()) { progressDialog.dismiss(); } colorQuantizer.cancel(); } }; final ColorQuantizer.ProgressListener progressListener = new ColorQuantizer.ProgressListener() { @Override public void progress(final String msg, final int iter, final int maxIter) { runOnUiThread(new Runnable() { @Override public void run() { progressDialog.setMessage(msg); progressDialog.setProgress(iter); } }); } }; progressDialog.setTitle(getString(R.string.get_pal_from_img_title)); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setCancelable(true); progressDialog.setOnCancelListener(cancelListener); progressDialog.setMax(colorQuantizer.getMaxIterCount()); progressDialog.show(); Thread thread = new Thread(new Runnable() { @Override public void run() { Bitmap bitmap; try { bitmap = FrexIO.readBitmap(getContentResolver(), imageUri, 256); } catch (IOException e) { alert("I/O error: " + e.getLocalizedMessage()); return; } ColorScheme colorScheme = colorQuantizer.quantize(bitmap, progressListener); progressDialog.dismiss(); if (colorScheme != null) { Log.d(TAG, "SELECT_PICTURE_REQUEST_CODE: Got colorScheme"); String colorSchemeId = "$" + imageUri.toString(); colorSchemes.add(colorSchemeId, colorScheme); view.setColorSchemeId(colorSchemeId); view.setColorScheme(colorScheme); view.recomputeColors(); runOnUiThread(new Runnable() { @Override public void run() { Log.d(TAG, "SELECT_PICTURE_REQUEST_CODE: showDialog(R.id.colors)"); showDialog(R.id.colors); } }); } } }); thread.start(); } }
From source file:cn.xcom.helper.activity.AuthorizedActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode != RESULT_CANCELED) { switch (requestCode) { case PHOTO_REQUEST_CAMERA:// // ???? String state = Environment.getExternalStorageState(); if (state.equals(Environment.MEDIA_MOUNTED)) { File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM); File tempFile = new File(path, "51helper.jpg"); startPhotoZoom(Uri.fromFile(tempFile)); } else { Toast.makeText(getApplicationContext(), "??", Toast.LENGTH_SHORT).show(); }/* w ww .j ava 2 s.co m*/ break; case PHOTO_REQUEST_ALBUM:// startPhotoZoom(data.getData()); break; case PHOTO_REQUEST_CUT: // ?? if (data != null) { getImageToView(data); } break; case 4: if (data != null) { tv_city.setText(data.getStringExtra("city")); } } } super.onActivityResult(requestCode, resultCode, data); }
From source file:com.facebook.android.Hackbook.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { /*/*from w ww. ja va 2 s.c o m*/ * if this is the activity result from authorization flow, do a call * back to authorizeCallback Source Tag: login_tag */ case AUTHORIZE_ACTIVITY_RESULT_CODE: { Utility.mFacebook.authorizeCallback(requestCode, resultCode, data); break; } /* * if this is the result for a photo picker from the gallery, upload * the image after scaling it. You can use the Utility.scaleImage() * function for scaling */ case PICK_EXISTING_PHOTO_RESULT_CODE: { if (resultCode == Activity.RESULT_OK) { Uri photoUri = data.getData(); if (photoUri != null) { Bundle params = new Bundle(); try { params.putByteArray("photo", Utility.scaleImage(getApplicationContext(), photoUri)); } catch (IOException e) { e.printStackTrace(); } params.putString("caption", "FbAPIs Sample App photo upload"); Utility.mAsyncRunner.request("me/photos", params, "POST", new PhotoUploadListener(), null); } else { Toast.makeText(getApplicationContext(), "Error selecting image from the gallery.", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(getApplicationContext(), "No image selected for upload.", Toast.LENGTH_SHORT).show(); } break; } } }
From source file:com.shafiq.myfeedle.core.StatusDialog.java
@Override protected void onResume() { super.onResume(); Intent intent = getIntent(); if (intent != null) { if (intent.hasExtra(Widgets.INSTANT_UPLOAD)) { mFilePath = intent.getStringExtra(Widgets.INSTANT_UPLOAD); Log.d(TAG, "upload photo?" + mFilePath); } else {//from w w w . j a va2 s .com mData = intent.getData(); if (mData != null) { mData = intent.getData(); if (intent.hasExtra(LauncherIntent.Extra.Scroll.EXTRA_SOURCE_BOUNDS)) mRect = intent.getParcelableExtra(LauncherIntent.Extra.Scroll.EXTRA_SOURCE_BOUNDS); else mRect = intent.getSourceBounds(); Log.d(TAG, "data:" + mData.toString()); // need to use a thread here to avoid anr mLoadingDialog = new ProgressDialog(this); mLoadingDialog.setMessage(getString(R.string.status_loading)); mLoadingDialog.setCancelable(true); mLoadingDialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { if (mStatusLoader != null) mStatusLoader.cancel(true); finish(); } }); mLoadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); finish(); } }); mLoadingDialog.show(); mStatusLoader = new StatusLoader(); mStatusLoader.execute(); } } } if (mFilePath != null) { mDialog = (new AlertDialog.Builder(this)).setTitle(R.string.uploadprompt) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startActivityForResult( Myfeedle.getPackageIntent(getApplicationContext(), MyfeedleCreatePost.class) .putExtra(Widgets.INSTANT_UPLOAD, mFilePath), RESULT_REFRESH); dialog.dismiss(); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); StatusDialog.this.finish(); } }).create(); mDialog.show(); } else { // check if the dialog is still loading if (mFinish) finish(); else if ((mLoadingDialog == null) || !mLoadingDialog.isShowing()) showDialog(); } }
From source file:ee.ria.DigiDoc.fragment.ContainerDetailsFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == CHOOSE_FILE_REQUEST_ID && resultCode == RESULT_OK && data != null) { ClipData clipData;//w w w .j a v a2 s. co m Uri uriData; if ((clipData = data.getClipData()) != null) { for (int i = 0; i < clipData.getItemCount(); i++) { ClipData.Item item = clipData.getItemAt(i); Uri uri = item.getUri(); if (uri != null) { addToFileList(uri); } } } else if ((uriData = data.getData()) != null) { addToFileList(uriData); } } }
From source file:edu.cens.loci.ui.PlaceViewActivity.java
protected void onActivityResult(int requestCode, int resultCode, Intent data) { Log.d(TAG, "onActivityResult:" + String.format(" requestCode=%d resultCode=%d ", requestCode, resultCode)); switch (requestCode) { case SUBACTIVITY_ADD_PLACE: if (resultCode == RESULT_OK) { long placeId = ContentUris.parseId(data.getData()); if (mPlace.state == Places.STATE_SUGGESTED) { if (placeId != mPlaceId) { // A suggested place has been merged to an existing place // update all visit's placeId's here LociDbUtils dbUtils = new LociDbUtils(this); dbUtils.updateVisitPlaceId(mPlaceId, placeId); mPlaceId = placeId;/*from w w w . ja va2s. c o m*/ } } setResult(RESULT_OK, data); } break; case SUBACTIVITY_VIEW_PLACE: if (resultCode == RESULT_OK) { } } }
From source file:com.wishlist.Wishlist.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { /*/* w w w. j a v a 2s . c o m*/ * if this is the activity result from authorization flow, do a call back to authorizeCallback * Source Tag: login_tag */ case AUTHORIZE_ACTIVITY_RESULT_CODE: { Utility.mFacebook.authorizeCallback(requestCode, resultCode, data); break; } /* * if this is the result for a photo picker from the gallery, upload the image after scaling it. * You can use the Utility.scaleImage() function for scaling */ case PICK_EXISTING_PHOTO_RESULT_CODE: { if (resultCode == Activity.RESULT_OK) { Uri imageUri = data.getData(); ((BitmapDrawable) image.getDrawable()).getBitmap().recycle(); System.gc(); try { imageBytes = Utility.scaleImage(getApplicationContext(), imageUri); image.setImageBitmap(BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length)); image.invalidate(); } catch (IOException e) { showToast(getString(R.string.error_getting_image)); } } else { showToast(getString(R.string.no_image_selected)); } break; } } }