@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_diaplay); // Get the intent that started this activity Intent intent = getIntent(); Uri data = intent.getData(); // Figure out what to do based on the intent type if (intent.getType().indexOf("image/") != -1) { // Handle intents with image data ... } else if (intent.getType().equals("text/plain")) { // Handle intents with text ... String str = intent.getClipData().toString(); String str2 = intent.getClipData().getItemAt(0).getText().toString(); Log.e(getString(R.string.app_name), str); Log.e(getString(R.string.app_name), str2); // paste them to the txt TextView txt = (TextView) findViewById(R.id.txt_Share); txt.setText( "**********stevenkcolin**************" + str2 + "****************stevenkcolin****************"); } }
private void proceedIntent(Intent intent) { if (intent != null) { String link = intent.getStringExtra("link"); if (!StringUtil.isEmpty(link)) { Intents.openBrowser(this, link); finish(); return; } Uri data = intent.getData(); if (data != null && data.getScheme().equalsIgnoreCase("tel")) { String path = data.getSchemeSpecificPart(); showPhone(path); getTracker().track("onShowPhone:intent"); } String action = intent.getAction(); String type = intent.getType(); if (action != null && "com.android.phone.action.RECENT_CALLS".equals(action)) { mViewPager.setCurrentItem(1); } else if ("android.intent.action.VIEW".equals(action) && "vnd.android.cursor.dir/calls".equals(type)) { mViewPager.setCurrentItem(1); } else if (type != null && "vnd.android.cursor.dir/calls".equals(type)) { mViewPager.setCurrentItem(1); onBackPressed(); } removeMissedCallNotifications(this); } }
private void handleIntent(Intent intent) { String action = intent.getAction(); if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) { String type = intent.getType(); if (MIME_TEXT_PLAIN.equals(type)) { Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); new NdefReaderTask().execute(tag); } else { Log.d(TAG, "Wrong mime type: " + type); } } else if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)) { // In case we would still use the Tech Discovered Intent Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); String[] techList = tag.getTechList(); String searchedTech = Ndef.class.getName(); for (String tech : techList) { if (searchedTech.equals(tech)) { new NdefReaderTask().execute(tag); break; } } } }
/** * Sets the current tab based on the intent's request type * * @param intent Intent that contains information about which tab should be selected */ private void setCurrentTab(Intent intent) { // If we got here by hitting send and we're in call forward along to the in-call activity final boolean recentCallsRequest = Calls.CONTENT_TYPE.equals(intent.getType()); if (isSendKeyWhileInCall(intent, recentCallsRequest)) { finish(); return; } // Remember the old manually selected tab index so that it can be restored if it is // overwritten by one of the programmatic tab selections final int savedTabIndex = mLastManuallySelectedFragment; final int tabIndex; if (DialpadFragment.phoneIsInUse() || isDialIntent(intent)) { tabIndex = TAB_INDEX_DIALER; } else if (recentCallsRequest) { tabIndex = TAB_INDEX_CALL_LOG; } else { tabIndex = mLastManuallySelectedFragment; } final int previousItemIndex = mViewPager.getCurrentItem(); mViewPager.setCurrentItem(tabIndex, false /* smoothScroll */); if (previousItemIndex != tabIndex) { sendFragmentVisibilityChange(previousItemIndex, false); } mPageChangeListener.setCurrentPosition(tabIndex); sendFragmentVisibilityChange(tabIndex, true); // Restore to the previous manual selection mLastManuallySelectedFragment = savedTabIndex; mDuringSwipe = false; mUserTabClick = false; }
private static String findClassNameByIntent( Intent intent, HashMap<String, ArrayList<PluginIntentFilter>> intentFilter) { if (intentFilter != null) { Iterator<Entry<String, ArrayList<PluginIntentFilter>>> entry = intentFilter.entrySet().iterator(); while (entry.hasNext()) { Entry<String, ArrayList<PluginIntentFilter>> item = entry.next(); Iterator<PluginIntentFilter> values = item.getValue().iterator(); while (values.hasNext()) { PluginIntentFilter filter = values.next(); int result = filter.match( intent.getAction(), intent.getType(), intent.getScheme(), intent.getData(), intent.getCategories()); if (result != PluginIntentFilter.NO_MATCH_ACTION && result != PluginIntentFilter.NO_MATCH_CATEGORY && result != PluginIntentFilter.NO_MATCH_DATA && result != PluginIntentFilter.NO_MATCH_TYPE) { return item.getKey(); } } } } return null; }
@Test public void shouldFillIn() throws Exception { Intent intentA = new Intent(); Intent intentB = new Intent(); intentB.setAction("foo"); Uri uri = Uri.parse("http://www.foo.com"); intentB.setDataAndType(uri, "text/html"); String category = "category"; intentB.addCategory(category); intentB.setPackage("com.foobar.app"); ComponentName cn = new ComponentName("com.foobar.app", "fragmentActivity"); intentB.setComponent(cn); intentB.putExtra("FOO", 23); int flags = Intent.FILL_IN_ACTION | Intent.FILL_IN_DATA | Intent.FILL_IN_CATEGORIES | Intent.FILL_IN_PACKAGE | Intent.FILL_IN_COMPONENT; int result = intentA.fillIn(intentB, flags); assertEquals("foo", intentA.getAction()); assertSame(uri, intentA.getData()); assertEquals("text/html", intentA.getType()); assertTrue(intentA.getCategories().contains(category)); assertEquals("com.foobar.app", intentA.getPackage()); assertSame(cn, intentA.getComponent()); assertEquals(23, intentA.getIntExtra("FOO", -1)); assertEquals(result, flags); }
public void onMenuClicked( int action, ProgressListener listener, boolean waitOnStop, boolean showDialog) { int title; 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(CropImage.ACTION_CROP); ((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 = (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; case R.id.action_import: title = R.string.Import; break; default: return; } startAction(action, title, listener, waitOnStop, showDialog); }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RESULT_LOAD_IMAGE && resultCode == Activity.RESULT_OK && null != data) { mImagesPanel.addImage(data.getData(), data.getType()); } }
@Override public void onCreate(Bundle theSavedInstanceState) { super.onCreate(theSavedInstanceState); // create folder for external storage myContext = new ContextWrapper(this); myContext.getExternalFilesDir(null); Intent anIntent = getIntent(); String aDataType = anIntent != null ? anIntent.getType() : ""; Uri aDataUrl = anIntent != null ? anIntent.getData() : null; String aDataPath = aDataUrl != null ? aDataUrl.getEncodedPath() : ""; myTextView = new TextView(this); myTextView.setMovementMethod(new ScrollingMovementMethod()); myTextView.setText( "sView loader in progress...\n URL: " + aDataPath + "\n Type: " + aDataType); setContentView(myTextView); StringBuilder anInfo = new StringBuilder(); if (!StActivity.loadNatives(this, anInfo)) { // StActivity.exitWithError(this, "Broken apk?\n" + anInfo); return; } myTextView.append("\n\n" + anInfo); Intent anImgViewer = new Intent(this, StActivity.class); anImgViewer.setDataAndType(aDataUrl, aDataType); startActivityForResult(anImgViewer, 0); }
@Test public void testSetType() throws Exception { Intent intent = new Intent(); intent.setData(Uri.parse("content://this/and/that")); assertSame(intent, intent.setType("def")); assertNull(intent.getData()); assertEquals("def", intent.getType()); }
@Test public void testSetDataAndType() throws Exception { Intent intent = new Intent(); Uri uri = Uri.parse("content://this/and/that"); assertSame(intent, intent.setDataAndType(uri, "ghi")); assertSame(uri, intent.getData()); assertEquals("ghi", intent.getType()); }
@Test public void testSetData() throws Exception { Intent intent = new Intent(); Uri uri = Uri.parse("content://this/and/that"); intent.setType("abc"); assertSame(intent, intent.setData(uri)); assertSame(uri, intent.getData()); assertNull(intent.getType()); }
private void runStart() { Intent intent = makeIntent(); if (intent != null) { System.out.println("Starting: " + intent); try { intent.addFlags(intent.FLAG_ACTIVITY_NEW_TASK); // XXX should do something to determine the MIME type. int res = mAm.startActivity( null, intent, intent.getType(), null, 0, null, null, 0, false, mDebugOption); switch (res) { case IActivityManager.START_SUCCESS: break; case IActivityManager.START_CLASS_NOT_FOUND: System.err.println("Error type 3"); System.err.println( "Error: Activity class " + intent.getComponent().toShortString() + " does not exist."); break; case IActivityManager.START_DELIVERED_TO_TOP: System.err.println( "Warning: Activity not started, intent has " + "been delivered to currently running " + "top-most instance."); break; case IActivityManager.START_FORWARD_AND_REQUEST_CONFLICT: System.err.println( "Error: Activity not started, you requested to " + "both forward and receive its result"); break; case IActivityManager.START_INTENT_NOT_RESOLVED: System.err.println( "Error: Activity not started, unable to " + "resolve " + intent.toString()); break; case IActivityManager.START_RETURN_INTENT_TO_CALLER: System.err.println( "Warning: Activity not started because intent " + "should be handled by the caller"); break; case IActivityManager.START_TASK_TO_FRONT: System.err.println( "Warning: Activity not started, its current " + "task has been brought to the front"); break; default: System.err.println("Error: Activity not started, unknown error " + "code " + res); break; } } catch (RemoteException e) { System.err.println("Error type 1"); System.err.println( "Error: Activity not started, unable to " + "call on to activity manager service"); } } }
/** Returns the MIME type from the activity. */ @SimpleProperty(category = PropertyCategory.BEHAVIOR) public String ResultType() { if (resultIntent != null) { String resultType = resultIntent.getType(); if (resultType != null) { return resultType; } } return ""; }
/** * Start 'Set as' function Set intent for start 'Set as' function. * * @param context - {@link Context} * @param path - selected item path */ public static void startSetAsActivity(Context context, String path) { File file = new File(path); if (file.exists()) { Intent intent = new Intent(Intent.ACTION_ATTACH_DATA).setDataAndType(Uri.fromFile(file), "image/jpg"); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.putExtra("mimeType", intent.getType()); context.startActivity(Intent.createChooser(intent, context.getString(R.string.set_as))); } }
private void checkIntent() { Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); if (Intent.ACTION_VIEW.equals(action) && type != null) { Toast.makeText(this, intent.getData().getPath(), Toast.LENGTH_LONG).show(); openMission(intent.getData().getPath()); update(); zoom(); } }
private boolean receivedIntent(Intent i) { return Constants.ACTION_SHORTCUT.equals(i.getAction()) || Constants.ACTION_NOTIFICATION_CLICK.equals(i.getAction()) || Constants.ACTION_WIDGET.equals(i.getAction()) || Constants.ACTION_TAKE_PHOTO.equals(i.getAction()) || ((Intent.ACTION_SEND.equals(i.getAction()) || Intent.ACTION_SEND_MULTIPLE.equals(i.getAction()) || Constants.INTENT_GOOGLE_NOW.equals(i.getAction())) && i.getType() != null) || i.getAction().contains(Constants.ACTION_NOTIFICATION_CLICK); }
/** 处理其他应用的数据 */ public void getOtherAppsData() { shareIntent = getIntent(); String action = shareIntent.getAction(); String type = shareIntent.getType(); if (Intent.ACTION_SEND.equals(action) && type != null) { if ("text/plain".equals(type)) { handleSendText(shareIntent); // 处理文本 } } else { } }
/** * Handle intent and NFC intent * * @param intent */ private void handleIntend(Intent intent) { String action = intent.getAction(); if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) { String type = intent.getType(); if (NFC_MIME.equals(type)) { Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); new NdefReaderTask().execute(tag); } else { Log.d(TAG, "Wrong mime type: " + type); } } }
SendData(Intent intent, ContentResolver contentResolver) { Bundle extras = intent.getExtras(); if (extras.containsKey(Intent.EXTRA_STREAM)) { Uri uri = this.uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM); String scheme = uri.getScheme(); if (scheme.equals("content")) { Cursor cursor = contentResolver.query(uri, null, null, null, null); cursor.moveToFirst(); this.fileName = cursor.getString(cursor.getColumnIndexOrThrow(Images.Media.DISPLAY_NAME)); this.contentType = intent.getType(); this.contentLength = cursor.getLong(cursor.getColumnIndexOrThrow(Images.Media.SIZE)); } } }
@Test public void intentForShareTweetScheme_whenValidUri_shouldReturnShareTweetIntent() throws UrlParseException { Intent intent; final String shareMessage = "Check out @SpaceX's Tweet: https://twitter.com/SpaceX/status/596026229536460802"; intent = Intents.intentForShareTweet( Uri.parse("mopubshare://tweet?screen_name=SpaceX&tweet_id=596026229536460802")); assertThat(intent.getAction()).isEqualTo(Intent.ACTION_SEND); assertThat(intent.getType()).isEqualTo("text/plain"); assertThat(intent.getStringExtra(Intent.EXTRA_SUBJECT)).isEqualTo(shareMessage); assertThat(intent.getStringExtra(Intent.EXTRA_TEXT)).isEqualTo(shareMessage); }
/** * Retrieve the best activity for the given intent. If a default activity is provided, choose the * default one. Otherwise, return the Intent picker if there are more than one capable activities. * If the intent is pdf type, return the platform pdf viewer if it is available so user don't need * to choose it from Intent picker. * * @param context Context of the app. * @param intent Intent to open. * @param allowSelfOpen Whether chrome itself is allowed to open the intent. * @return true if the intent can be resolved, or false otherwise. */ public static boolean resolveIntent(Context context, Intent intent, boolean allowSelfOpen) { try { boolean activityResolved = false; ResolveInfo info = context.getPackageManager().resolveActivity(intent, 0); if (info != null) { final String packageName = context.getPackageName(); if (info.match != 0) { // There is a default activity for this intent, use that. if (allowSelfOpen || !packageName.equals(info.activityInfo.packageName)) { activityResolved = true; } } else { List<ResolveInfo> handlers = context .getPackageManager() .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (handlers != null && !handlers.isEmpty()) { activityResolved = true; boolean canSelfOpen = false; boolean hasPdfViewer = false; for (ResolveInfo resolveInfo : handlers) { String pName = resolveInfo.activityInfo.packageName; if (packageName.equals(pName)) { canSelfOpen = true; } else if (PDF_VIEWER.equals(pName)) { String filename = intent.getData().getLastPathSegment(); if ((filename != null && filename.endsWith(PDF_SUFFIX)) || PDF_MIME.equals(intent.getType())) { intent.setClassName(pName, resolveInfo.activityInfo.name); hasPdfViewer = true; break; } } } if ((canSelfOpen && !allowSelfOpen) && !hasPdfViewer) { activityResolved = false; } } } } return activityResolved; } catch (RuntimeException e) { logTransactionTooLargeOrRethrow(e, intent); } return false; }
private void fillIntent(@Nullable Intent intent, @NonNull TextView textView) { if (intent == null) { textView.setText(Printer.EMPTY); return; } Truss truss = new Truss(); Printer.append(truss, "action", intent.getAction()); Printer.append(truss, "categories", intent.getCategories()); Printer.append(truss, "type", intent.getType()); Printer.append(truss, "flags", Flags.decode(intent.getFlags())); Printer.append(truss, "package", intent.getPackage()); Printer.append(truss, "component", intent.getComponent()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { Printer.append(truss, "referrer", getReferrer()); } textView.setText(truss.build()); }
@Override public void onManagerConnected(int status) { switch (status) { case LoaderCallbackInterface.SUCCESS: { init_sd_imgs(); // mat_share = new Mat(); Bitmap bitmap_share = null; Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); if (Intent.ACTION_SEND.equals(action) && type != null) { if ("text/plain".equals(type)) { handleSendText(intent); } else if (type.startsWith("image/")) { bitmap_share = handleSendImage(intent); } } Fragment fragment = new GalleryFragment(); if (mat_share == null && bitmap_share != null) { mat_share = new Mat(); Utils.bitmapToMat(bitmap_share, mat_share); } if (mat_share != null) { fragment = new RcvGridFragment(MainActivity.this); } getFragmentManager().beginTransaction().replace(R.id.container, fragment).commit(); } break; default: { super.onManagerConnected(status); } break; } }
private static void dumpIntent(String prefix, Intent intent) { Log.v(prefix + "Flags:" + dumpFlags(intent.getFlags())); Log.v(prefix + "Action:" + intent.getAction()); Log.v(prefix + "Categories:"); if (intent.getCategories() != null) { for (String str : intent.getCategories()) Log.v(prefix + " " + str); } Log.v(prefix + "Type:" + intent.getType()); Log.v(prefix + "Data:" + intent.getDataString()); Log.v(prefix + "Pkg:" + intent.getPackage()); ComponentName comp = intent.getComponent(); Log.v(prefix + "Comp:" + (comp == null ? null : intent.getComponent().flattenToString())); Bundle extra = intent.getExtras(); if (extra != null) { for (String key : extra.keySet()) { dumpKeyValue(prefix + " ", key, extra.get(key)); } } }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.receiver); final Button cancelbtn = (Button) findViewById(R.id.ButtonCancel); // cancelbtn.setEnabled(false); cancelbtn.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // streamtask.cancel(true); finish(); } }); try { Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); if ((!(Intent.ACTION_SEND.equals(action))) || (type == null)) { throw new RuntimeException("Unknown intent action or type"); } if (!("text/plain".equals(type))) { throw new RuntimeException("Type is not text/plain"); } String extra = intent.getStringExtra(Intent.EXTRA_TEXT); if (extra == null) { throw new RuntimeException("Cannot get shared text"); } final DownloadStreamTask streamtask = new DownloadStreamTask(this); // Once created, a task is executed very simply: streamtask.execute(extra); } catch (Exception e) { Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show(); } }
/** * Fires an Intent to open a downloaded item. * * @param context Context to use. * @param intent Intent that can be fired. * @return Whether an Activity was successfully started for the Intent. */ static boolean fireOpenIntentForDownload(Context context, Intent intent) { try { if (TextUtils.equals(intent.getPackage(), context.getPackageName())) { IntentHandler.startActivityForTrustedIntent(intent, context); } else { context.startActivity(intent); } return true; } catch (ActivityNotFoundException ex) { Log.d( TAG, "Activity not found for " + intent.getType() + " over " + intent.getData().getScheme(), ex); } catch (SecurityException ex) { Log.d(TAG, "cannot open intent: " + intent, ex); } return false; }
/** * Loads message data from an intent. Currently supports text/plain and image/* ACTION_SEND * intents. * * @param intent The intent with the data to load. */ public void loadMessageFromIntent(final Intent intent) { String type = intent == null ? null : intent.getType(); if (intent != null) { if (type != null) { if ("text/plain".equals(type)) { mReplyText.setText(intent.getStringExtra(Intent.EXTRA_TEXT)); } else if (type.startsWith("image/")) { Uri uri = intent.getData(); // If the Uri is null, try looking elsewhere for it. [1] [2] // [1]: // http://stackoverflow.com/questions/10386885/intent-filter-intent-getdata-returns-null // [2]: http://developer.android.com/reference/android/content/Intent.html#ACTION_SEND if (uri == null) { Bundle extras = intent.getExtras(); if (extras != null) { uri = (Uri) extras.get(Intent.EXTRA_STREAM); } } new ImageLoaderTask(mContext, uri).execute(); // If the Uri is still null here, throw the exception. if (uri == null) { // TODO show the user some kind of feedback } } } else { if (intent.getExtras() != null) { String body = intent.getExtras().getString("sms_body"); if (body != null) { mReplyText.setText(body); } } } } }
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); if (Intent.ACTION_SEND.equals(action) && type != null) { if ("text/plain".equals(type)) { handleSendText(intent); } else if (type.startsWith("image/")) { handleSendImage(intent); } } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) { if (type.startsWith("image/")) { handleSendMultipleImages(intent); } } else { } }
/** * 响应从图片分享进入的事件 * * @param intent */ private void respondExternal(Intent intent) { currentFragment = (TalkPubFragment) mFragment.get(); String action = intent.getAction(); String type = intent.getType(); if (Intent.ACTION_SEND.equals(action) && type != null) { if ("text/plain".equals(type)) { handleSendText(intent); // Handle text being sent } else if (type.startsWith("image/")) { handleSendImage(intent); // Handle single image being sent } } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) { if (type.startsWith("image/")) { handleSendMultipleImages(intent); // Handle multiple images // being sent } } else { // Handle other intents, such as being started from the home screen } }