List of usage examples for android.content Intent getData
public @Nullable Uri getData()
From source file:edu.mit.mobile.android.locast.sync.AbsMediaSync.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (ACTION_SYNC_RESOURCES.equals(intent.getAction())) { final Uri data = intent.getData(); if (data == null) { try { enqueueUnpublishedMedia(); } catch (final SyncException e) { Log.e(TAG, "cannot sync request URL", e); }//from w w w. jav a2 s . c o m } else { enqueueItem(data, intent.getExtras()); } } else { Log.e(TAG, "Media Sync was told to start with an unhandled intent: " + intent); } return START_REDELIVER_INTENT; }
From source file:com.mobantica.DriverItRide.activities.ActivityProfile.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 1) { if (resultCode == -1) { previewCapturedImage();// ww w . ja v a 2 s .c o m } } else if (requestCode == 2) { Uri selectedImage = data == null ? null : data.getData(); if (selectedImage != null) { String[] filePath = { MediaStore.Images.Media.DATA }; Cursor c = getContentResolver().query(selectedImage, filePath, null, null, null); c.moveToFirst(); int columnIndex = c.getColumnIndex(filePath[0]); String picturePath = c.getString(columnIndex); c.close(); ChnagedUri = Uri.parse("file://" + picturePath); previewCapturedImage(); } } }
From source file:com.test.onesignal.MainOneSignalClassRunner.java
@Test public void testOpeningLaunchUrl() throws Exception { // Clear app launching normally Shadows.shadowOf(blankActivity).getNextStartedActivity(); // No OneSignal init here to test case where it is located in an Activity. OneSignal.handleNotificationOpened(blankActivity, new JSONArray( "[{ \"alert\": \"Test Msg\", \"custom\": { \"i\": \"UUID\", \"u\": \"http://google.com\" } }]"), false);/*from w w w. j a v a2 s . com*/ Intent intent = Shadows.shadowOf(blankActivity).getNextStartedActivity(); Assert.assertEquals("android.intent.action.VIEW", intent.getAction()); Assert.assertEquals("http://google.com", intent.getData().toString()); Assert.assertNull(Shadows.shadowOf(blankActivity).getNextStartedActivity()); }
From source file:se.lu.nateko.edca.svc.GeoHelper.java
/** * Start to listen for changes in the storage state, * and report any changes to handleStorageChange. *///from www .j a v a 2s .c o m private void startWatchingExternalStorage() { Log.d(TAG, "startWatchingExternalStorage() called."); mExternalStorageReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.i("TAG", "Storage state changed: " + intent.getData()); updateExternalStorageState(); handleStorageChange(); } }; IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_MEDIA_MOUNTED); filter.addAction(Intent.ACTION_MEDIA_REMOVED); mService.registerReceiver(mExternalStorageReceiver, filter); updateExternalStorageState(); }
From source file:com.futurologeek.smartcrossing.crop.CropImageActivity.java
private void loadInput() { Intent intent = getIntent(); Bundle extras = intent.getExtras();/*ww w . ja va 2 s .c o m*/ if (extras != null) { aspectX = extras.getInt(Crop.Extra.ASPECT_X); aspectY = extras.getInt(Crop.Extra.ASPECT_Y); maxX = extras.getInt(Crop.Extra.MAX_X); maxY = extras.getInt(Crop.Extra.MAX_Y); saveUri = extras.getParcelable(MediaStore.EXTRA_OUTPUT); } sourceUri = intent.getData(); if (sourceUri != null) { exifRotation = CropUtil .getExifRotation(CropUtil.getFromMediaUri(this, getContentResolver(), sourceUri)); InputStream is = null; try { sampleSize = calculateBitmapSampleSize(sourceUri); is = getContentResolver().openInputStream(sourceUri); BitmapFactory.Options option = new BitmapFactory.Options(); option.inSampleSize = sampleSize; rotateBitmap = new RotateBitmap(BitmapFactory.decodeStream(is, null, option), exifRotation); } catch (IOException e) { Log.e("Error reading image: " + e.getMessage(), e); setResultException(e); } catch (OutOfMemoryError e) { Log.e("OOM reading image: " + e.getMessage(), e); setResultException(e); } finally { CropUtil.closeSilently(is); } } }
From source file:com.github.gorbin.asne.linkedin.LinkedInSocialNetwork.java
/** * Overrided for LinkedIn support/*w w w. ja va2 s .c om*/ * @param requestCode The integer 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 data An Intent, which can return result data to the caller (various data can be attached to Intent "extras"). */ @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { int sanitizedRequestCode = requestCode & 0xFFFF; if (sanitizedRequestCode != REQUEST_AUTH) return; super.onActivityResult(requestCode, resultCode, data); Uri uri = data != null ? data.getData() : null; if (uri != null && uri.toString().startsWith(mRedirectURL.toLowerCase())) { String parts[] = uri.toString().split("="); String verifier = parts[1]; verifier = verifier.substring(0, verifier.indexOf("&")); RequestLogin2AsyncTask requestLogin2AsyncTask = new RequestLogin2AsyncTask(); mRequests.put(REQUEST_LOGIN2, requestLogin2AsyncTask); Bundle args = new Bundle(); args.putString(RequestLogin2AsyncTask.PARAM_VERIFIER, verifier); requestLogin2AsyncTask.execute(args); } else { if (mLocalListeners.get(REQUEST_LOGIN) != null) { mLocalListeners.get(REQUEST_LOGIN).onError(getID(), REQUEST_LOGIN, "incorrect URI returned: " + uri, null); mLocalListeners.remove(REQUEST_LOGIN); } } }
From source file:com.etalio.android.EtalioBase.java
/** * Requests an access token and a refresh token from Etalio *//* w w w. ja v a2 s . co m*/ protected void authorizeAndAcquireTokensFromCallback(final Intent intent, final AuthenticationCallback callback) throws EtalioAuthorizationCodeException { if (!isEtalioSignInCallback(intent)) { throw new IllegalArgumentException("The intent does not contain a valid authentication callback."); } //set the code for later final String code = getAuthorizationCodeFromUri(intent.getData()); //Reset intent data to not trigger this call again. if (intent != null) { intent.setData(null); } new AsyncTask<String, Void, Boolean>() { public EtalioTokenException error; @Override protected Boolean doInBackground(String... params) { //get and set the access/refresh tokens try { requestNewToken(params[0]); } catch (EtalioTokenException e) { this.error = e; return false; } catch (IOException e) { return false; } return true; } @Override protected void onPostExecute(Boolean result) { if (callback != null) { if (result) { callback.onAuthenticationSuccess(); } else { callback.onAuthenticationFailure(this.error); } } } }.execute(code); }
From source file:com.remobile.camera.CameraLauncher.java
/** * Applies all needed transformation to the image received from the gallery. * * @param destType In which form should we return the image * @param intent An Intent, which can return result data to the caller (various data can be attached to Intent "extras"). *///from w ww . j av a2 s . com private void processResultFromGallery(int destType, Intent intent) { Uri uri = intent.getData(); if (uri == null) { if (croppedUri != null) { uri = croppedUri; } else { this.failPicture("null data from photo library"); return; } } int rotate = 0; // If you ask for video or all media type you will automatically get back a file URI // and there will be no attempt to resize any returned data if (this.mediaType != PICTURE) { this.callbackContext.success(uri.toString()); } else { // This is a special case to just return the path as no scaling, // rotating, nor compressing needs to be done if (this.targetHeight == -1 && this.targetWidth == -1 && (destType == FILE_URI || destType == NATIVE_URI) && !this.correctOrientation) { this.callbackContext.success(uri.toString()); } else { String uriString = uri.toString(); // Get the path to the image. Makes loading so much easier. String mimeType = FileHelper.getMimeType(uriString, this.cordova); // If we don't have a valid image so quit. if (!("image/jpeg".equalsIgnoreCase(mimeType) || "image/png".equalsIgnoreCase(mimeType))) { Log.d(LOG_TAG, "I either have a null image path or bitmap"); this.failPicture("Unable to retrieve path to picture!"); return; } Bitmap bitmap = null; try { bitmap = getScaledBitmap(uriString); } catch (IOException e) { e.printStackTrace(); } if (bitmap == null) { Log.d(LOG_TAG, "I either have a null image path or bitmap"); this.failPicture("Unable to create bitmap!"); return; } if (this.correctOrientation) { rotate = getImageOrientation(uri); if (rotate != 0) { Matrix matrix = new Matrix(); matrix.setRotate(rotate); try { bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); this.orientationCorrected = true; } catch (OutOfMemoryError oom) { this.orientationCorrected = false; } } } // If sending base64 image back if (destType == DATA_URL) { this.processPicture(bitmap); } // If sending filename back else if (destType == FILE_URI || destType == NATIVE_URI) { // Did we modify the image? if ((this.targetHeight > 0 && this.targetWidth > 0) || (this.correctOrientation && this.orientationCorrected)) { try { String modifiedPath = this.ouputModifiedBitmap(bitmap, uri); // The modified image is cached by the app in order to get around this and not have to delete you // application cache I'm adding the current system time to the end of the file url. this.callbackContext .success("file://" + modifiedPath + "?" + System.currentTimeMillis()); } catch (Exception e) { e.printStackTrace(); this.failPicture("Error retrieving image."); } } else { this.callbackContext.success(uri.toString()); } } if (bitmap != null) { bitmap.recycle(); bitmap = null; } System.gc(); } } }
From source file:android_network.hetnet.vpn_service.Receiver.java
@Override public void onReceive(final Context context, Intent intent) { Log.i(TAG, "Received " + intent); Util.logExtras(intent);//w w w. java 2 s. co m SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) { // Application added if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) { // Show notification if (true) { int uid = intent.getIntExtra(Intent.EXTRA_UID, -1); notifyNewApplication(uid, context); } } } else if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) { // Application removed Rule.clearCache(context); if (intent.getBooleanExtra(Intent.EXTRA_DATA_REMOVED, false)) { // Remove settings String packageName = intent.getData().getSchemeSpecificPart(); Log.i(TAG, "Deleting settings package=" + packageName); context.getSharedPreferences("wifi", Context.MODE_PRIVATE).edit().remove(packageName).apply(); context.getSharedPreferences("other", Context.MODE_PRIVATE).edit().remove(packageName).apply(); context.getSharedPreferences("apply", Context.MODE_PRIVATE).edit().remove(packageName).apply(); context.getSharedPreferences("screen_wifi", Context.MODE_PRIVATE).edit().remove(packageName) .apply(); context.getSharedPreferences("screen_other", Context.MODE_PRIVATE).edit().remove(packageName) .apply(); context.getSharedPreferences("roaming", Context.MODE_PRIVATE).edit().remove(packageName).apply(); context.getSharedPreferences("notify", Context.MODE_PRIVATE).edit().remove(packageName).apply(); int uid = intent.getIntExtra(Intent.EXTRA_UID, 0); if (uid > 0) { DatabaseHelper.getInstance(context).clearAccess(uid, false); NotificationManagerCompat.from(context).cancel(uid); // installed notification NotificationManagerCompat.from(context).cancel(uid + 10000); // access notification } } } else { // Upgrade settings upgrade(true, context); // Start service try { if (prefs.getBoolean("enabled", false)) ServiceSinkhole.start("receiver", context); else if (prefs.getBoolean("show_stats", false)) ServiceSinkhole.run("receiver", context); } catch (Throwable ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } if (Util.isInteractive(context)) ServiceSinkhole.reloadStats("receiver", context); } }
From source file:com.shafiq.myfeedle.core.MyfeedleCreatePost.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case PHOTO:/* w w w.j a v a2 s. c om*/ if (resultCode == RESULT_OK) { getPhoto(data.getData()); } break; case TAGS: if ((resultCode == RESULT_OK) && data.hasExtra(Stags) && data.hasExtra(Accounts.SID)) mAccountsTags.put(data.getLongExtra(Accounts.SID, Myfeedle.INVALID_ACCOUNT_ID), data.getStringArrayExtra(Stags)); break; } }