List of usage examples for android.content Intent getType
public @Nullable String getType()
From source file:com.tweetlanes.android.view.HomeActivity.java
void onCreateHandleIntents() { boolean turnSoftKeyboardOff = true; Intent intent = getIntent(); if (intent.getAction() == Intent.ACTION_SEND) { Bundle extras = intent.getExtras(); String type = intent.getType(); if (type.equals("text/plain") == true) { String shareString = extras.getString(Intent.EXTRA_TEXT); if (extras.containsKey(Intent.EXTRA_TEXT)) { shareString = extras.getString(Intent.EXTRA_SUBJECT) + " " + shareString; }//from w w w. ja v a 2 s . c om beginShareStatus(shareString); turnSoftKeyboardOff = false; } else if (type.contains("image/")) { // From http://stackoverflow.com/a/2641363/328679 if (extras.containsKey(Intent.EXTRA_STREAM)) { Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM); String scheme = uri.getScheme(); if (scheme.equals("content")) { ContentResolver contentResolver = getContentResolver(); Cursor cursor = contentResolver.query(uri, null, null, null, null); cursor.moveToFirst(); try { String imagePath = cursor.getString(cursor.getColumnIndexOrThrow(Images.Media.DATA)); beginShareImage(imagePath); } catch (java.lang.IllegalArgumentException e) { Toast.makeText(this, R.string.picture_attach_error, Toast.LENGTH_SHORT).show(); } turnSoftKeyboardOff = false; } } } } if (turnSoftKeyboardOff == true) { // Turn the soft-keyboard off. For some reason it wants to appear on screen by default when coming back from multitasking... getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); } }
From source file:edu.mum.ml.group7.guessasketch.android.EasyPaint.java
public void loadFromIntents() { Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); System.out.println("Intentoso " + action + " type " + type); if (Intent.ACTION_SEND.equals(action) && type != null) { if (type.startsWith("image/")) { setBackgroundUri((Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM)); }//from w w w . j av a 2s . co m } }
From source file:cz.maresmar.sfm.view.user.UserDetailFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case PICK_PROFILE_PICTURE: if (resultCode == Activity.RESULT_OK) { Timber.i("Profile picture selected"); // Try to crop image (not every Android support it) try { Intent intent = new Intent("com.android.camera.action.CROP"); intent.setDataAndType(data.getData(), data.getType()); // Push selected picture to crop intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.putExtra("crop", "true"); intent.putExtra("aspectX", 1); intent.putExtra("aspectY", 1); intent.putExtra("return-data", true); intent.putExtra("finishActivityOnSaveCompleted", true); startActivityForResult(//w w w . j av a 2 s. co m Intent.createChooser(intent, getString(R.string.user_crop_picture_dialog)), CROP_PROFILE_PICTURE); } catch (ActivityNotFoundException e) { Timber.w(e, "No cropping activity found"); } // Save selected image new PictureLoaderAsyncTask(this).execute(data.getData()); } break; case CROP_PROFILE_PICTURE: if (resultCode == Activity.RESULT_OK && data.getExtras() != null) { Bitmap resBitmap = data.getExtras().getParcelable("data"); if (resBitmap != null) { Timber.i("User picture cropped"); new PictureCropperAsyncTask(this).execute(resBitmap); break; } } Timber.w("Cropping wasn't successful (result code: %d)", requestCode); break; default: throw new UnsupportedOperationException("Unknown action request " + requestCode); } }
From source file:com.tweetlanes.android.core.view.HomeActivity.java
void onCreateHandleIntents() { boolean turnSoftKeyboardOff = true; Intent intent = getIntent(); Bundle extras = intent.getExtras();/*from w w w. j av a2s .c o m*/ if (extras != null) { String type = intent.getType(); if (intent.getAction() == Intent.ACTION_SEND && type != null) { if (type.equals("text/plain") && extras.containsKey(Intent.EXTRA_TEXT)) { String shareString = extras.getString(Intent.EXTRA_TEXT); if (extras.containsKey(Intent.EXTRA_SUBJECT)) { shareString = extras.getString(Intent.EXTRA_SUBJECT) + " " + shareString; } beginShareStatus(shareString); turnSoftKeyboardOff = false; } else if (type.contains("image/")) { // From http://stackoverflow.com/a/2641363/328679 if (extras.containsKey(Intent.EXTRA_STREAM)) { Uri uri = extras.getParcelable(Intent.EXTRA_STREAM); String scheme = uri.getScheme(); if (scheme.equals("content")) { ContentResolver contentResolver = getContentResolver(); Cursor cursor = contentResolver.query(uri, null, null, null, null); cursor.moveToFirst(); try { String imagePath = cursor .getString(cursor.getColumnIndexOrThrow(Images.Media.DATA)); beginShareImage(imagePath); } catch (java.lang.IllegalArgumentException e) { Toast.makeText(this, R.string.picture_attach_error, Toast.LENGTH_SHORT).show(); } finally { cursor.close(); cursor = null; } turnSoftKeyboardOff = false; } } } } } if (turnSoftKeyboardOff) { // Turn the soft-keyboard off. For some reason it wants to appear on // screen by default when coming back from multitasking... getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); } }
From source file:com.shafiq.mytwittle.view.HomeActivity.java
void onCreateHandleIntents() { boolean turnSoftKeyboardOff = true; Intent intent = getIntent(); if (intent.getAction() == Intent.ACTION_SEND) { Bundle extras = intent.getExtras(); String type = intent.getType(); if (type.equals("text/plain") == true) { String shareString = extras.getString(Intent.EXTRA_TEXT); if (extras.containsKey(Intent.EXTRA_TEXT)) { shareString = extras.getString(Intent.EXTRA_SUBJECT) + " " + shareString; }// w w w. jav a2 s . c om beginShareStatus(shareString); turnSoftKeyboardOff = false; } else if (type.contains("image/")) { // From http://stackoverflow.com/a/2641363/328679 if (extras.containsKey(Intent.EXTRA_STREAM)) { Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM); String scheme = uri.getScheme(); if (scheme.equals("content")) { ContentResolver contentResolver = getContentResolver(); Cursor cursor = contentResolver.query(uri, null, null, null, null); cursor.moveToFirst(); try { String imagePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaColumns.DATA)); beginShareImage(imagePath); } catch (java.lang.IllegalArgumentException e) { Toast.makeText(this, R.string.picture_attach_error, Toast.LENGTH_SHORT).show(); } turnSoftKeyboardOff = false; } } } } if (turnSoftKeyboardOff == true) { // Turn the soft-keyboard off. For some reason it wants to appear on // screen by default when coming back from multitasking... getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); } }
From source file:com.slim.turboeditor.activity.MainActivity.java
/** * Parses the intent// w ww .j a va 2 s . co m */ private void parseIntent(Intent intent) { final String action = intent.getAction(); final String type = intent.getType(); if (Intent.ACTION_VIEW.equals(action) || Intent.ACTION_EDIT.equals(action) || Intent.ACTION_PICK.equals(action) && type != null) { Uri uri = intent.getData(); File newFile = new File(uri.getPath()); newFileToOpen(newFile, ""); } else if (Intent.ACTION_SEND.equals(action) && type != null) { if ("text/plain".equals(type)) { newFileToOpen(null, intent.getStringExtra(Intent.EXTRA_TEXT)); } } }
From source file:de.schildbach.wallet.ui.WalletActivity.java
private void handleIntent(final Intent intent) { final String action = intent.getAction(); if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) { final String inputType = intent.getType(); final NdefMessage ndefMessage = (NdefMessage) intent .getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)[0]; final byte[] input = Nfc.extractMimePayload(Constants.MIMETYPE_TRANSACTION, ndefMessage); new BinaryInputParser(inputType, input) { @Override//w w w.ja v a 2s. c o m protected void handlePaymentIntent(final PaymentIntent paymentIntent) { cannotClassify(inputType); } @Override protected void error(final int messageResId, final Object... messageArgs) { dialog(WalletActivity.this, null, 0, messageResId, messageArgs); } }.parse(); } }
From source file:com.tinfoil.sms.sms.SendMessageActivity.java
private void handleSendIntent() { Intent intent = this.getIntent(); //Toast.makeText(this, ""+(Intent.ACTION_SENDTO.equals(intent.getAction())&& intent.getType() != null), Toast.LENGTH_LONG).show(); if (Intent.ACTION_SEND.equals(intent.getAction()) && intent.getType() != null) { if ("text/plain".equals(intent.getType())) { String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT); if (sharedText != null) { setupComposeView(null, sharedText); }// w ww.j a v a 2 s . c om } } else if (Intent.ACTION_SENDTO.equals(intent.getAction())) { String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT); Uri uri = this.getIntent().getData(); if (uri.getSchemeSpecificPart() != null) { String number = uri.getSchemeSpecificPart(); if (dba.inDatabase(number)) { setupMessageView(SMSUtility.format(number), sharedText); } else { setupComposeView(SMSUtility.format(number), sharedText); } } } }
From source file:com.boko.vimusic.ui.activities.AudioPlayerActivity.java
/** * Checks whether the passed intent contains a playback request, and starts * playback if that's the case//from w w w . j av a2s . c o m */ private void startPlayback() { Intent intent = getIntent(); if (intent == null || mService == null) { return; } Uri uri = intent.getData(); String mimeType = intent.getType(); boolean handled = false; if (uri != null && uri.toString().length() > 0) { MusicUtils.playFile(this, uri); handled = true; } else if (Playlists.CONTENT_TYPE.equals(mimeType)) { String id = intent.getStringExtra("playlistId"); if (id == null) { String idString = intent.getStringExtra("playlist"); if (idString != null) { try { id = idString; } catch (NumberFormatException e) { // ignore } } } if (id != null) { MusicUtils.playPlaylist(this, id); handled = true; } } if (handled) { // Make sure to process intent only once setIntent(new Intent()); // Refresh the queue ((QueueFragment) mPagerAdapter.getFragment(0)).refreshQueue(); } }
From source file:com.android.gallery3d.ui.MenuExecutor.java
public void onMenuClicked(int action, ProgressListener listener, boolean waitOnStop, boolean showDialog) { int title;//from w w w. j av a 2 s .c o m switch (action) { case R.id.action_select_all: if (mSelectionManager.inSelectAllMode()) { mSelectionManager.deSelectAll(); } else { mSelectionManager.selectAll(); } return; case R.id.action_crop: { Intent intent = getIntentBySingleSelectedPath(CropActivity.CROP_ACTION); ((Activity) mActivity).startActivity(intent); return; } case R.id.action_edit: { Intent intent = getIntentBySingleSelectedPath(Intent.ACTION_EDIT) .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); ((Activity) mActivity).startActivity(Intent.createChooser(intent, null)); return; } case R.id.action_setas: { Intent intent = getIntentBySingleSelectedPath(Intent.ACTION_ATTACH_DATA) .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.putExtra("mimeType", intent.getType()); Activity activity = mActivity; activity.startActivity(Intent.createChooser(intent, activity.getString(R.string.set_as))); return; } case R.id.action_delete: title = R.string.delete; break; case R.id.action_rotate_cw: title = R.string.rotate_right; break; case R.id.action_rotate_ccw: title = R.string.rotate_left; break; case R.id.action_show_on_map: title = R.string.show_on_map; break; default: return; } startAction(action, title, listener, waitOnStop, showDialog); }