List of usage examples for android.content Intent getType
public @Nullable String getType()
From source file:com.anjalimacwan.activity.NoteEditActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_note_edit); // Apply theme SharedPreferences pref = getSharedPreferences(getPackageName() + "_preferences", Context.MODE_PRIVATE); String theme = pref.getString("theme", "light-sans"); LinearLayout noteViewEdit = (LinearLayout) findViewById(R.id.noteViewEdit); if (theme.contains("light")) noteViewEdit.setBackgroundColor(ContextCompat.getColor(this, R.color.window_background)); if (theme.contains("dark")) noteViewEdit.setBackgroundColor(ContextCompat.getColor(this, R.color.window_background_dark)); // Set action bar elevation if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) getSupportActionBar().setElevation(getResources().getDimensionPixelSize(R.dimen.action_bar_elevation)); if (!(getSupportFragmentManager().findFragmentById(R.id.noteViewEdit) instanceof NoteEditFragment)) { // Handle intents Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); // Intent sent through an external application if (Intent.ACTION_SEND.equals(action) && type != null) { if ("text/plain".equals(type)) { external = intent.getStringExtra(Intent.EXTRA_TEXT); if (external != null) { newNote();// ww w .j a va 2 s . c om } else { showToast(R.string.loading_external_file); finish(); } } else { showToast(R.string.loading_external_file); finish(); } // Intent sent through Google Now "note to self" } else if ("com.google.android.gm.action.AUTO_SEND".equals(action) && type != null) { if ("text/plain".equals(type)) { external = intent.getStringExtra(Intent.EXTRA_TEXT); if (external != null) { try { // Write note to disk FileOutputStream output = openFileOutput(String.valueOf(System.currentTimeMillis()), Context.MODE_PRIVATE); output.write(external.getBytes()); output.close(); // Show toast notification and finish showToast(R.string.note_saved); finish(); } catch (IOException e) { // Show error message as toast if file fails to save showToast(R.string.failed_to_save); finish(); } } } } else newNote(); } }
From source file:nirwan.cordova.plugin.printer.Printer.java
private void loadContentIntoPrintController(String content, Intent intent, String filename, String mineType) { String mimeType = intent.getType(); if (filename != null) { loadContentFromSDCardRoot(intent, filename, mimeType); } else if (mimeType.equals("text/html")) { loadContentAsHtmlIntoPrintController(content, intent); } else {//from w ww . jav a 2 s. c o m loadContentAsBitmapIntoPrintController(content, intent); } }
From source file:org.sufficientlysecure.keychain.ui.DecryptTextActivity.java
/** * Handles all actions with this intent/* w w w . ja v a2 s. co m*/ */ private void handleActions(Bundle savedInstanceState, Intent intent) { String action = intent.getAction(); Bundle extras = intent.getExtras(); String type = intent.getType(); if (extras == null) { extras = new Bundle(); } if (savedInstanceState != null) { return; } if (Intent.ACTION_SEND.equals(action) && type != null) { Log.d(Constants.TAG, "ACTION_SEND"); Log.logDebugBundle(extras, "SEND extras"); // When sending to Keychain Decrypt via share menu if ("text/plain".equals(type)) { String sharedText = extras.getString(Intent.EXTRA_TEXT); sharedText = getPgpContent(sharedText); if (sharedText != null) { loadFragment(sharedText); } else { Log.e(Constants.TAG, "EXTRA_TEXT does not contain PGP content!"); Toast.makeText(this, R.string.error_invalid_data, Toast.LENGTH_LONG).show(); finish(); } } else { Log.e(Constants.TAG, "ACTION_SEND received non-plaintext, this should not happen in this activity!"); Toast.makeText(this, R.string.error_invalid_data, Toast.LENGTH_LONG).show(); finish(); } } else if (ACTION_DECRYPT_TEXT.equals(action)) { Log.d(Constants.TAG, "ACTION_DECRYPT_TEXT"); String extraText = extras.getString(EXTRA_TEXT); extraText = getPgpContent(extraText); if (extraText != null) { loadFragment(extraText); } else { Log.e(Constants.TAG, "EXTRA_TEXT does not contain PGP content!"); Toast.makeText(this, R.string.error_invalid_data, Toast.LENGTH_LONG).show(); finish(); } } else if (ACTION_DECRYPT_FROM_CLIPBOARD.equals(action)) { Log.d(Constants.TAG, "ACTION_DECRYPT_FROM_CLIPBOARD"); CharSequence clipboardText = ClipboardReflection.getClipboardText(this); String text = getPgpContent(clipboardText); if (text != null) { loadFragment(text); } else { returnInvalidResult(); } } else if (ACTION_DECRYPT_TEXT.equals(action)) { Log.e(Constants.TAG, "Include the extra 'text' in your Intent!"); Toast.makeText(this, R.string.error_invalid_data, Toast.LENGTH_LONG).show(); finish(); } }
From source file:com.vmihalachi.turboeditor.activity.HomeActivity.java
/** * Parses the intent//from w w w. j av a 2 s . c o 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) { // Post the NewFileOpened Event EventBus.getDefault().postSticky(new NewFileOpened(intent.getData().getPath())); } }
From source file:org.thialfihar.android.apg.ui.DecryptActivity.java
/** * Handles all actions with this intent/*from www . j a v a 2 s .c o m*/ * * @param intent */ private void handleActions(Intent intent) { String action = intent.getAction(); Bundle extras = intent.getExtras(); String type = intent.getType(); Uri uri = intent.getData(); if (extras == null) { extras = new Bundle(); } /* * Android's Action */ if (Intent.ACTION_SEND.equals(action) && type != null) { // When sending to Keychain Decrypt via share menu if ("text/plain".equals(type)) { // Plain text String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT); if (sharedText != null) { // handle like normal text decryption, override action and extras to later // executeServiceMethod ACTION_DECRYPT in main actions extras.putString(EXTRA_TEXT, sharedText); action = ACTION_DECRYPT; } } else { // Binary via content provider (could also be files) // override uri to get stream from send uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); action = ACTION_DECRYPT; } } else if (Intent.ACTION_VIEW.equals(action)) { // Android's Action when opening file associated to Keychain (see AndroidManifest.xml) // override action action = ACTION_DECRYPT; } String textData = extras.getString(EXTRA_TEXT); mLegacyMode = false; if ("org.thialfihar.android.apg.intent.DECRYPT_AND_RETURN".equals(action)) { mLegacyMode = true; Matcher matcher = PgpHelper.PGP_MESSAGE.matcher(textData); if (matcher.matches()) { Log.d(Constants.TAG, "PGP_MESSAGE matched"); textData = matcher.group(1); // replace non breakable spaces textData = textData.replaceAll("\\xa0", " "); mMessageFragmentBundle.putString(DecryptMessageFragment.ARG_CIPHERTEXT, textData); mSwitchToTab = PAGER_TAB_MESSAGE; } else { matcher = PgpHelper.PGP_CLEARTEXT_SIGNATURE.matcher(textData); if (matcher.matches()) { Log.d(Constants.TAG, "PGP_SIGNED_MESSAGE matched"); textData = matcher.group(1); // replace non breakable spaces textData = textData.replaceAll("\\xa0", " "); mMessageFragmentBundle.putString(DecryptMessageFragment.ARG_CIPHERTEXT, textData); mSwitchToTab = PAGER_TAB_MESSAGE; } else { Log.d(Constants.TAG, "Nothing matched!"); } } return; } /** * Main Actions */ if (ACTION_DECRYPT.equals(action) && textData != null) { Log.d(Constants.TAG, "textData not null, matching text ..."); Matcher matcher = PgpHelper.PGP_MESSAGE.matcher(textData); if (matcher.matches()) { Log.d(Constants.TAG, "PGP_MESSAGE matched"); textData = matcher.group(1); // replace non breakable spaces textData = textData.replaceAll("\\xa0", " "); mMessageFragmentBundle.putString(DecryptMessageFragment.ARG_CIPHERTEXT, textData); mSwitchToTab = PAGER_TAB_MESSAGE; } else { matcher = PgpHelper.PGP_CLEARTEXT_SIGNATURE.matcher(textData); if (matcher.matches()) { Log.d(Constants.TAG, "PGP_CLEARTEXT_SIGNATURE matched"); textData = matcher.group(1); // replace non breakable spaces textData = textData.replaceAll("\\xa0", " "); mMessageFragmentBundle.putString(DecryptMessageFragment.ARG_CIPHERTEXT, textData); mSwitchToTab = PAGER_TAB_MESSAGE; } else { Log.d(Constants.TAG, "Nothing matched!"); } } } else if (ACTION_DECRYPT.equals(action) && uri != null) { // get file path from uri String path = FileHelper.getPath(this, uri); if (path != null) { mFileFragmentBundle.putString(DecryptFileFragment.ARG_FILENAME, path); mSwitchToTab = PAGER_TAB_FILE; } else { Log.e(Constants.TAG, "Direct binary data without actual file in filesystem is not supported. " + "Please use the Remote Service API!"); Toast.makeText(this, R.string.error_only_files_are_supported, Toast.LENGTH_LONG).show(); // end activity finish(); } } else { Log.e(Constants.TAG, "Include the extra 'text' or an Uri with setData() in your Intent!"); } }
From source file:org.sufficientlysecure.keychain.ui.EncryptActivity.java
/** * Handles all actions with this intent//from w w w .j av a 2 s .c om * * @param intent */ private void handleActions(Intent intent) { String action = intent.getAction(); Bundle extras = intent.getExtras(); String type = intent.getType(); Uri uri = intent.getData(); if (extras == null) { extras = new Bundle(); } /* * Android's Action */ if (Intent.ACTION_SEND.equals(action) && type != null) { // When sending to APG Encrypt via share menu if ("text/plain".equals(type)) { // Plain text String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT); if (sharedText != null) { // handle like normal text encryption, override action and extras to later // executeServiceMethod ACTION_ENCRYPT in main actions extras.putString(EXTRA_TEXT, sharedText); extras.putBoolean(EXTRA_ASCII_ARMOR, true); action = ACTION_ENCRYPT; } } else { // Files via content provider, override uri and action uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); action = ACTION_ENCRYPT; } } if (extras.containsKey(EXTRA_ASCII_ARMOR)) { boolean requestAsciiArmor = extras.getBoolean(EXTRA_ASCII_ARMOR, true); mFileFragmentBundle.putBoolean(EncryptFileFragment.ARG_ASCII_ARMOR, requestAsciiArmor); } String textData = extras.getString(EXTRA_TEXT); long signatureKeyId = extras.getLong(EXTRA_SIGNATURE_KEY_ID); long[] encryptionKeyIds = extras.getLongArray(EXTRA_ENCRYPTION_KEY_IDS); // preselect keys given by intent mAsymmetricFragmentBundle.putLongArray(EncryptAsymmetricFragment.ARG_ENCRYPTION_KEY_IDS, encryptionKeyIds); mAsymmetricFragmentBundle.putLong(EncryptAsymmetricFragment.ARG_SIGNATURE_KEY_ID, signatureKeyId); mSwitchToMode = PAGER_MODE_ASYMMETRIC; /** * Main Actions */ if (ACTION_ENCRYPT.equals(action) && textData != null) { // encrypt text based on given extra mMessageFragmentBundle.putString(EncryptMessageFragment.ARG_TEXT, textData); mSwitchToContent = PAGER_CONTENT_MESSAGE; } else if (ACTION_ENCRYPT.equals(action) && uri != null) { // encrypt file based on Uri // get file path from uri String path = FileHelper.getPath(this, uri); if (path != null) { mFileFragmentBundle.putString(EncryptFileFragment.ARG_FILENAME, path); mSwitchToContent = PAGER_CONTENT_FILE; } else { Log.e(Constants.TAG, "Direct binary data without actual file in filesystem is not supported " + "by Intents. Please use the Remote Service API!"); Toast.makeText(this, R.string.error_only_files_are_supported, Toast.LENGTH_LONG).show(); // end activity finish(); } } else { Log.e(Constants.TAG, "Include the extra 'text' or an Uri with setData() in your Intent!"); } }
From source file:edu.stanford.mobisocial.dungbeetle.ui.FeedHomeActivity.java
/** Called when the activity is first created. */ @Override/* w ww .ja v a 2 s. co m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_feed_home); mNfc = new Nfc(this); checked = new boolean[filterTypes.length]; for (int x = 0; x < filterTypes.length; x++) { checked[x] = true; } mFeedViews = new ArrayList<FeedView>(); mFeedViews.add(FeedViews.feedViewFrom("Feed", new FeedViewFragment())); mFeedViews.add(FeedViews.feedViewFrom("Apps", new AppsViewFragment())); mFeedViews.add(FeedViews.feedViewFrom("People", new FeedMembersFragment())); mFeedViews.add(new PresenceView()); Intent intent = getIntent(); String feed_name = null; String dyn_feed_uri = null; if (intent.getType() != null && intent.getType().equals(Feed.MIME_TYPE)) { Uri feedUri = getIntent().getData(); feed_name = feedUri.getLastPathSegment(); Maybe<Group> maybeG = Group.forFeedName(FeedHomeActivity.this, feed_name); try { Group g = maybeG.get(); mGroupName = g.name; dyn_feed_uri = g.dynUpdateUri; } catch (Exception e) { } } if (dyn_feed_uri != null) { mNfc.share(NdefFactory.fromUri(dyn_feed_uri)); Log.w(TAG, dyn_feed_uri); } mFeedUri = Feed.uriForName(feed_name); mColor = Feed.colorFor(feed_name); Bundle args = new Bundle(); args.putParcelable(FeedViewFragment.ARG_FEED_URI, mFeedUri); mActionsFragment = new FeedActionsFragment(); mActionsFragment.setArguments(args); for (FeedView f : mFeedViews) { f.getFragment().setArguments(args); } // TODO: Why is FeedActionsFragment.getActivity() null without this hack? FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); Fragment actions = getSupportFragmentManager().findFragmentByTag("feedActions"); if (actions != null) { ft.remove(actions); } ft.add(mActionsFragment, "feedActions"); ft.commit(); PagerAdapter adapter = new FeedFragmentAdapter(getSupportFragmentManager(), mFeedUri); mFeedViewPager = (ViewPager) findViewById(R.id.feed_pager); mFeedViewPager.setAdapter(adapter); mFeedViewPager.setOnPageChangeListener(this); mFeedViewPager.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); ViewGroup group = (ViewGroup) findViewById(R.id.tab_frame); int i = 0; for (FeedView f : mFeedViews) { Button button = new Button(this); button.setText(f.getName()); button.setTextSize(18f); button.setLayoutParams(CommonLayouts.FULL_HEIGHT); button.setTag(i++); button.setOnClickListener(mViewSelected); group.addView(button); mButtons.add(button); } doTitleBar(this, mGroupName); onPageSelected(0); }
From source file:com.eng.arab.translator.androidtranslator.ShowDetailsMonth.java
private void InitMainPanel() { mainPanel = (LinearLayout) findViewById(R.id.activity_translators_details); srcCard = (CardView) findViewById(R.id.src_card_details); srcToolbar = (Toolbar) findViewById(R.id.src_toolbar_details); srcToolbar.inflateMenu(R.menu.src_card_months); srcToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override// w ww . j av a 2 s. c o m public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.action_share_details: if (keyboard_flag == 0) { hideSoftKeyboard(); keyboard_flag = 1; } else keyboard_flag = 0; Toast.makeText(ShowDetailsMonth.this, "Share", Toast.LENGTH_SHORT).show(); break; case R.id.action_clear_details: Toast.makeText(ShowDetailsMonth.this, "CLEAR", Toast.LENGTH_SHORT).show(); break; } return true; } }); srcToolbar.setOnClickListener(this); srcToolbar.setTitle("ARABIC"); /**UPPER Text to translate*/ //srcContent = (LinearLayout)findViewById(R.id.src_content_details); mainPanel.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { } }); final Intent intent = getIntent(); if (Intent.ACTION_SEND.equals(intent.getAction()) && "text/plain".equals(intent.getType())) { trg_text_details.setText(intent.getStringExtra(Intent.EXTRA_TEXT)); } //snackBar(); }
From source file:com.vmihalachi.turboeditor.activity.HomeActivity.java
/** * When a file is saved/*from ww w .ja v a2s. co m*/ * Invoked by the EditorFragment * * @param event The event called */ public void onEvent(FileSavedEvent event) { try { closeKeyBoard(); } catch (NullPointerException e) { Log.e(TAG, e.getMessage(), e); } // Get intent, action and MIME type final Intent intent = getIntent(); 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) { //This Activity was called by startActivityForResult final Intent returnIntent = new Intent(); setResult(Activity.RESULT_OK, returnIntent); // finish the activity finish(); } else { //This Activity was called by startActivity // mDrawerLayout.openDrawer(Gravity.LEFT); // getActionBar().setTitle(getString(R.string.nome_app_turbo_editor)); // Replace fragment getFragmentManager().beginTransaction().replace(R.id.fragment_editor, new NoFileOpenedFragment()) .commit(); } }
From source file:org.thialfihar.android.apg.ui.EncryptActivity.java
/** * Handles all actions with this intent/*from w w w .ja v a 2s .c o m*/ * * @param intent */ private void handleActions(Intent intent) { String action = intent.getAction(); Bundle extras = intent.getExtras(); String type = intent.getType(); Uri uri = intent.getData(); if (extras == null) { extras = new Bundle(); } /* * Android's Action */ if (Intent.ACTION_SEND.equals(action) && type != null) { // When sending to APG Encrypt via share menu if ("text/plain".equals(type)) { // Plain text String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT); if (sharedText != null) { // handle like normal text encryption, override action and extras to later // executeServiceMethod ACTION_ENCRYPT in main actions extras.putString(EXTRA_TEXT, sharedText); extras.putBoolean(EXTRA_ASCII_ARMOR, true); action = ACTION_ENCRYPT; } } else { // Files via content provider, override uri and action uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); action = ACTION_ENCRYPT; } } if (extras.containsKey(EXTRA_ASCII_ARMOR)) { boolean requestAsciiArmor = extras.getBoolean(EXTRA_ASCII_ARMOR, true); mFileFragmentBundle.putBoolean(EncryptFileFragment.ARG_ASCII_ARMOR, requestAsciiArmor); } String textData = extras.getString(EXTRA_TEXT); long signatureKeyId = extras.getLong(EXTRA_SIGNATURE_KEY_ID); long[] encryptionKeyIds = extras.getLongArray(EXTRA_ENCRYPTION_KEY_IDS); mLegacyMode = false; if ("org.thialfihar.android.apg.intent.ENCRYPT_AND_RETURN".equals(action)) { mLegacyMode = true; encryptionKeyIds = extras.getLongArray("encryptionKeyIds"); signatureKeyId = extras.getLong("signatureKeyId"); mSigningKeyId = signatureKeyId; mEncryptionKeyIds = encryptionKeyIds; mMessageFragmentBundle.putString(EncryptMessageFragment.ARG_TEXT, textData); mSwitchToContent = PAGER_CONTENT_MESSAGE; } // preselect keys given by intent mAsymmetricFragmentBundle.putLongArray(EncryptAsymmetricFragment.ARG_ENCRYPTION_KEY_IDS, encryptionKeyIds); mAsymmetricFragmentBundle.putLong(EncryptAsymmetricFragment.ARG_SIGNATURE_KEY_ID, signatureKeyId); mSwitchToMode = PAGER_MODE_ASYMMETRIC; /** * Main Actions */ if (ACTION_ENCRYPT.equals(action) && textData != null) { // encrypt text based on given extra mMessageFragmentBundle.putString(EncryptMessageFragment.ARG_TEXT, textData); mSwitchToContent = PAGER_CONTENT_MESSAGE; } else if (ACTION_ENCRYPT.equals(action) && uri != null) { // encrypt file based on Uri // get file path from uri String path = FileHelper.getPath(this, uri); if (path != null) { mFileFragmentBundle.putString(EncryptFileFragment.ARG_FILENAME, path); mSwitchToContent = PAGER_CONTENT_FILE; } else { Log.e(Constants.TAG, "Direct binary data without actual file in filesystem is not supported " + "by Intents. Please use the Remote Service API!"); Toast.makeText(this, R.string.error_only_files_are_supported, Toast.LENGTH_LONG).show(); // end activity finish(); } } else { Log.e(Constants.TAG, "Include the extra 'text' or an Uri with setData() in your Intent!"); } }