List of usage examples for android.content Intent setType
public @NonNull Intent setType(@Nullable String type)
From source file:com.saltedge.sdk.webview.SEWebViewTools.java
private void pickFile() { Intent chooserIntent = new Intent(Intent.ACTION_GET_CONTENT); chooserIntent.setType("file/*"); activity.startActivityForResult(chooserIntent, SEConstants.FILECHOOSER_RESULT_CODE); }
From source file:com.manning.androidhacks.hack004.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.prefs); Preference sharePref = findPreference("pref_share"); Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.setType("text/plain"); shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Check this app!"); shareIntent.putExtra(Intent.EXTRA_TEXT, "Check this awesome app at: ..."); sharePref.setIntent(shareIntent);/*from w ww. ja v a 2s. co m*/ Preference ratePref = findPreference("pref_rate"); Uri uri = Uri.parse("market://details?id=" + getPackageName()); Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri); ratePref.setIntent(goToMarket); updateUserText(); }
From source file:com.vladstirbu.cordova.CDVInstagramPlugin.java
private void share(String imageString) { if (imageString != null && imageString.length() > 0) { byte[] imageData = Base64.decode(imageString, 0); FileOutputStream os = null; File filePath = new File(this.webView.getContext().getExternalFilesDir(null), "instagram.png"); try {/*from w w w.ja v a2s . com*/ os = new FileOutputStream(filePath, true); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { os.write(imageData); os.flush(); os.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("image/*"); shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + filePath)); shareIntent.setPackage("com.instagram.android"); this.cordova.startActivityForResult((CordovaPlugin) this, shareIntent, 12345); } else { this.cbContext.error("Expected one non-empty string argument."); } }
From source file:cc.metapro.openct.allclasses.ExcelDialog.java
private void showFilerChooser() { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("*/*"); intent.addCategory(Intent.CATEGORY_OPENABLE); try {/*from www . j a v a 2s.c o m*/ startActivityForResult(Intent.createChooser(intent, getString(R.string.select_schedule_file)), FILE_SELECT_CODE); } catch (ActivityNotFoundException ex) { Toast.makeText(getActivity(), R.string.fail_file_chooser, Toast.LENGTH_LONG).show(); } }
From source file:com.chess.genesis.activity.GameListFrag.java
protected void sendGame(final Bundle gamedata) { try {//from www . j a va 2 s. c om final String gamename = gamedata.containsKey("gameid") ? gamedata.getString("white") + " V. " + gamedata.getString("black") : gamedata.getString("name"); final String filename = gamename + ".txt"; final String gamestr = GameParser.export(gamedata).toString(); final Uri uri = FileUtils.writeFile(filename, gamestr); final Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_STREAM, uri); intent.setType("application/json"); startActivity(intent); } catch (final JSONException e) { Toast.makeText(act, "Corrupt Game Data", Toast.LENGTH_LONG).show(); } catch (final FileNotFoundException e) { Toast.makeText(act, "File Not Found", Toast.LENGTH_LONG).show(); } catch (final IOException e) { Toast.makeText(act, "Error Reading File", Toast.LENGTH_LONG).show(); } }
From source file:net.quranquiz.ui.QQLastScreenActivity.java
private Intent createShareIntent() { Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("text/plain"); //shareIntent.putExtra(Intent.EXTRA_SUBJECT, " ? "); shareIntent.putExtra(Intent.EXTRA_TEXT, conclusionMessage + " http://quranquiz.net"); return shareIntent; }
From source file:com.vrem.wifianalyzer.navigation.items.ExportItem.java
private Intent createIntent(String title, String data) { Intent intent = createSendIntent(); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TITLE, title); intent.putExtra(Intent.EXTRA_SUBJECT, title); intent.putExtra(Intent.EXTRA_TEXT, data); return intent; }
From source file:com.ryan.ryanreader.reddit.prepared.RedditPreparedPost.java
public static void onActionMenuItemSelected(final RedditPreparedPost post, final Fragment fragmentParent, final Action action) { final Activity activity = fragmentParent.getSupportActivity(); switch (action) { case UPVOTE:/*from ww w . j ava2 s . c o m*/ post.action(activity, RedditAPI.RedditAction.UPVOTE); break; case DOWNVOTE: post.action(activity, RedditAPI.RedditAction.DOWNVOTE); break; case UNVOTE: post.action(activity, RedditAPI.RedditAction.UNVOTE); break; case SAVE: post.action(activity, RedditAPI.RedditAction.SAVE); break; case UNSAVE: post.action(activity, RedditAPI.RedditAction.UNSAVE); break; case HIDE: post.action(activity, RedditAPI.RedditAction.HIDE); break; case UNHIDE: post.action(activity, RedditAPI.RedditAction.UNHIDE); break; case REPORT: new AlertDialog.Builder(activity).setTitle(R.string.action_report) .setMessage(R.string.action_report_sure) .setPositiveButton(R.string.action_report, new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int which) { post.action(activity, RedditAPI.RedditAction.REPORT); // TODO update the view to show the result // TODO don't forget, this also hides } }).setNegativeButton(R.string.dialog_cancel, null).show(); break; case EXTERNAL: { final Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(post.url)); activity.startActivity(intent); break; } case SELFTEXT_LINKS: { final HashSet<String> linksInComment = LinkHandler .computeAllLinks(StringEscapeUtils.unescapeHtml4(post.src.selftext)); if (linksInComment.isEmpty()) { General.quickToast(activity, R.string.error_toast_no_urls_in_self); } else { final String[] linksArr = linksInComment.toArray(new String[linksInComment.size()]); final AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setItems(linksArr, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { LinkHandler.onLinkClicked(activity, linksArr[which], false, post.src); dialog.dismiss(); } }); final AlertDialog alert = builder.create(); alert.setTitle(R.string.action_selftext_links); alert.setCanceledOnTouchOutside(true); alert.show(); } break; } case SAVE_IMAGE: { final RedditAccount anon = RedditAccountManager.getAnon(); CacheManager.getInstance(activity) .makeRequest(new CacheRequest(General.uriFromString(post.imageUrl), anon, null, Constants.Priority.IMAGE_VIEW, 0, CacheRequest.DownloadType.IF_NECESSARY, Constants.FileType.IMAGE, false, false, false, activity) { @Override protected void onCallbackException(Throwable t) { BugReportActivity.handleGlobalError(context, t); } @Override protected void onDownloadNecessary() { General.quickToast(context, R.string.download_downloading); } @Override protected void onDownloadStarted() { } @Override protected void onFailure(RequestFailureType type, Throwable t, StatusLine status, String readableMessage) { final RRError error = General.getGeneralErrorForFailure(context, type, t, status); General.showResultDialog(activity, error); } @Override protected void onProgress(long bytesRead, long totalBytes) { } @Override protected void onSuccess(CacheManager.ReadableCacheFile cacheFile, long timestamp, UUID session, boolean fromCache, String mimetype) { File dst = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), General.uriFromString(post.imageUrl).getPath()); if (dst.exists()) { int count = 0; while (dst.exists()) { count++; dst = new File( Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES), count + "_" + General.uriFromString(post.imageUrl).getPath().substring(1)); } } try { General.copyFile(cacheFile.getInputStream(), dst); } catch (IOException e) { notifyFailure(RequestFailureType.STORAGE, e, null, "Could not copy file"); return; } activity.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + dst.getAbsolutePath()))); General.quickToast(context, context.getString(R.string.action_save_image_success) + " " + dst.getAbsolutePath()); } }); break; } case SHARE: { final Intent mailer = new Intent(Intent.ACTION_SEND); mailer.setType("text/plain"); mailer.putExtra(Intent.EXTRA_SUBJECT, post.title); mailer.putExtra(Intent.EXTRA_TEXT, post.url); activity.startActivity(Intent.createChooser(mailer, activity.getString(R.string.action_share))); break; } case SHARE_COMMENTS: { final Intent mailer = new Intent(Intent.ACTION_SEND); mailer.setType("text/plain"); mailer.putExtra(Intent.EXTRA_SUBJECT, "Comments for " + post.title); mailer.putExtra(Intent.EXTRA_TEXT, Constants.Reddit.getUri(Constants.Reddit.PATH_COMMENTS + post.idAlone).toString()); activity.startActivity( Intent.createChooser(mailer, activity.getString(R.string.action_share_comments))); break; } case COPY: { ClipboardManager manager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); manager.setText(post.url); break; } case GOTO_SUBREDDIT: { final RedditSubreddit subreddit = new RedditSubreddit("/r/" + post.src.subreddit, "/r/" + post.src.subreddit, true); final Intent intent = new Intent(activity, PostListingActivity.class); intent.putExtra("subreddit", subreddit); activity.startActivityForResult(intent, 1); break; } case USER_PROFILE: UserProfileDialog.newInstance(post.src.author).show(activity); break; case PROPERTIES: PostPropertiesDialog.newInstance(post.src).show(activity); break; case COMMENTS: ((RedditPostView.PostSelectionListener) fragmentParent).onPostCommentsSelected(post); break; case LINK: ((RedditPostView.PostSelectionListener) fragmentParent).onPostSelected(post); break; case COMMENTS_SWITCH: if (!(activity instanceof MainActivity)) activity.finish(); ((RedditPostView.PostSelectionListener) fragmentParent).onPostCommentsSelected(post); break; case LINK_SWITCH: if (!(activity instanceof MainActivity)) activity.finish(); ((RedditPostView.PostSelectionListener) fragmentParent).onPostSelected(post); break; case ACTION_MENU: showActionMenu(activity, fragmentParent, post); break; case REPLY: final Intent intent = new Intent(activity, CommentReplyActivity.class); intent.putExtra("parentIdAndType", post.idAndType); activity.startActivity(intent); break; } }
From source file:com.samuelcastro.cordova.InstagramSharePlugin.java
private void shareVideo(String videoString, String captionString) { // Create the URI from the media File media = new File(this.getRealVideoPathFromURI(Uri.parse(videoString))); Uri uri = Uri.fromFile(media);/* w w w . ja v a2s. c o m*/ Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("video/*"); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); shareIntent.putExtra(Intent.EXTRA_TEXT, captionString); shareIntent.setPackage("com.instagram.android"); this.cordova.startActivityForResult((CordovaPlugin) this, shareIntent, 12345); }
From source file:mobisocial.musubi.ui.fragments.ChooseImageDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { return new AlertDialog.Builder(getActivity()).setTitle("Choose an Image...") .setItems(new String[] { "From Camera", "From Gallery" }, new DialogInterface.OnClickListener() { @SuppressWarnings("deprecation") @Override/* w ww. j a va 2 s. co m*/ public void onClick(DialogInterface dialog, int which) { switch (which) { case 0: final Activity activity = getActivity(); Toast.makeText(activity, "Loading camera...", Toast.LENGTH_SHORT).show(); ((InstrumentedActivity) activity) .doActivityForResult(new PhotoTaker(activity, new PhotoTaker.ResultHandler() { @Override public void onResult(Uri imageUri) { Log.d(getClass().getSimpleName(), "Updating thumbnail..."); try { UriImage image = new UriImage(activity, imageUri); byte[] data = image.getResizedImageData(512, 512, PictureObj.MAX_IMAGE_SIZE / 2); // profile Bitmap sourceBitmap = BitmapFactory.decodeByteArray(data, 0, data.length); int width = sourceBitmap.getWidth(); int height = sourceBitmap.getHeight(); int cropSize = Math.min(width, height); Bitmap cropped = Bitmap.createBitmap(sourceBitmap, 0, 0, cropSize, cropSize); ByteArrayOutputStream baos = new ByteArrayOutputStream(); cropped.compress(Bitmap.CompressFormat.JPEG, 90, baos); cropped.recycle(); sourceBitmap.recycle(); Bundle bundle = new Bundle(); bundle.putByteArray(EXTRA_THUMBNAIL, baos.toByteArray()); Intent res = new Intent(); res.putExtras(bundle); getTargetFragment().onActivityResult(REQUEST_PROFILE_PICTURE, Activity.RESULT_OK, res); } catch (Throwable t) { Log.e("ViewProfile", "failed to generate thumbnail of profile", t); Toast.makeText(activity, "Profile picture capture failed. Try again.", Toast.LENGTH_SHORT).show(); } } }, 200, false)); break; case 1: Intent gallery = new Intent(Intent.ACTION_GET_CONTENT); gallery.setType("image/*"); // god damn fragments. getTargetFragment().startActivityForResult(Intent.createChooser(gallery, null), REQUEST_GALLERY_THUMBNAIL); break; } } }).create(); }