List of usage examples for android.content Intent setType
public @NonNull Intent setType(@Nullable String type)
From source file:jahirfiquitiva.iconshowcase.services.MuzeiArtSourceService.java
@Override public void onCustomCommand(int id) { super.onCustomCommand(id); if (id == COMMAND_ID_SHARE) { Artwork currentArtwork = getCurrentArtwork(); Intent shareWall = new Intent(Intent.ACTION_SEND); shareWall.setType("text/plain"); String wallName = currentArtwork.getTitle(); String authorName = currentArtwork.getByline(); String storeUrl = MARKET_URL + getPackageName(); String iconPackName = getString(R.string.app_name); shareWall.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_text, wallName, authorName, iconPackName, storeUrl)); shareWall = Intent.createChooser(shareWall, getString(R.string.share_title)); shareWall.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(shareWall);/* w ww. j av a 2 s . c o m*/ } }
From source file:com.samuelcastro.cordova.InstagramSharePlugin.java
private void shareImage(String imageString, String captionString) { if (imageString != null && imageString.length() > 0) { byte[] imageData = Base64.decode(imageString, 0); File file = null;/*from w ww .j a v a2 s . c o m*/ FileOutputStream os = null; File parentDir = this.webView.getContext().getExternalFilesDir(null); File[] oldImages = parentDir.listFiles(OLD_IMAGE_FILTER); for (File oldImage : oldImages) { oldImage.delete(); } try { file = File.createTempFile("instagram", ".png", parentDir); os = new FileOutputStream(file, true); } catch (Exception e) { 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://" + file)); shareIntent.putExtra(Intent.EXTRA_TEXT, captionString); 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:com.liato.bankdroid.banking.banks.Coop.java
@Override public Urllib login() throws LoginException, BankException { try {//w ww . j a va 2s . co m LoginPackage lp = preLogin(); response = urlopen.open(lp.getLoginTarget(), lp.getPostData()); if (response.contains("forfarande logga in med ditt personnummer")) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (prefs.getBoolean("debug_mode", false) && prefs.getBoolean("debug_coop_sendmail", false)) { Intent i = new Intent(android.content.Intent.ACTION_SEND); i.setType("plain/text"); i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "android@nullbyte.eu" }); i.putExtra(android.content.Intent.EXTRA_SUBJECT, "Bankdroid - Coop Error"); i.putExtra(android.content.Intent.EXTRA_TEXT, response); context.startActivity(i); } throw new LoginException(res.getText(R.string.invalid_username_password).toString()); } } catch (ClientProtocolException e) { throw new BankException(e.getMessage()); } catch (IOException e) { throw new BankException(e.getMessage()); } return urlopen; }
From source file:com.vladstirbu.cordova.CDVInstagramVideoPlugin.java
private void share(String videoUrl, String captionString) { if (videoUrl != null && videoUrl.length() > 0) { this.webView.loadUrl("javascript:console.log('processing " + videoUrl + "');"); byte[] videoData = null; try {//from w w w .ja v a 2 s .co m URL url = new URL(videoUrl); URLConnection ucon = url.openConnection(); InputStream is = ucon.getInputStream(); videoData = new byte[is.available()]; is.read(videoData); is.close(); } catch (Exception e) { this.webView.loadUrl("javascript:console.log('" + e.getMessage() + "');"); e.printStackTrace(); } File file = null; FileOutputStream os = null; File parentDir = this.webView.getContext().getExternalFilesDir(null); File[] oldVideos = parentDir.listFiles(OLD_IMAGE_FILTER); for (File oldVideo : oldVideos) { oldVideo.delete(); } try { file = File.createTempFile("instagram_video", ".mp4", parentDir); os = new FileOutputStream(file, true); } catch (Exception e) { this.webView.loadUrl("javascript:console.log('" + e.getMessage() + "');"); e.printStackTrace(); } try { os.write(videoData); os.flush(); os.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("video/mp4"); //File media = new File(file); //Uri uri = Uri.fromFile(media); // Add the URI to the Intent. //share.putExtra(Intent.EXTRA_STREAM, uri); // Broadcast the Intent. //startActivity(Intent.createChooser(share, "Share to")); shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file)); shareIntent.putExtra(Intent.EXTRA_TEXT, captionString); 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:com.mbientlab.metawear.app.SensorFragment.java
@Override public void onViewCreated(final View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); chart = (LineChart) view.findViewById(R.id.data_chart); initializeChart();//from w ww . j a va2s . com resetData(false); chart.invalidate(); view.findViewById(R.id.data_clear).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { chart.resetTracking(); chart.clear(); resetData(true); chart.invalidate(); } }); ((Switch) view.findViewById(R.id.sample_control)) .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { if (b) { moveViewToLast(); setup(); chartHandler.postDelayed(updateChartTask, UPDATE_PERIOD); } else { chart.setVisibleXRangeMaximum(sampleCount); clean(); if (streamRouteManager != null) { streamRouteManager.remove(); streamRouteManager = null; } chartHandler.removeCallbacks(updateChartTask); } } }); view.findViewById(R.id.data_save).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String filename = saveData(); if (filename != null) { File dataFile = getActivity().getFileStreamPath(filename); Uri contentUri = FileProvider.getUriForFile(getActivity(), "com.mbientlab.metawear.app.fileprovider", dataFile); Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, filename); intent.putExtra(Intent.EXTRA_STREAM, contentUri); startActivity(Intent.createChooser(intent, "Saving Data")); } } }); }
From source file:org.lol.reddit.reddit.prepared.RedditPreparedPost.java
public static void onActionMenuItemSelected(final RedditPreparedPost post, final Activity activity, final Action action) { switch (action) { case UPVOTE:/*from ww w .ja v a2s . 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); String url = (activity instanceof WebViewActivity) ? ((WebViewActivity) activity).getCurrentUrl() : post.url; intent.setData(Uri.parse(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, url.toString()); 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 { final InputStream cacheFileInputStream = cacheFile.getInputStream(); if (cacheFileInputStream == null) { notifyFailure(RequestFailureType.CACHE_MISS, null, null, "Could not find cached image"); return; } General.copyFile(cacheFileInputStream, 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: { try { final Intent intent = new Intent(activity, PostListingActivity.class); intent.setData(SubredditPostListURL.getSubreddit(post.src.subreddit).generateJsonUri()); activity.startActivityForResult(intent, 1); } catch (RedditSubreddit.InvalidSubredditNameException e) { Toast.makeText(activity, R.string.invalid_subreddit_name, Toast.LENGTH_LONG).show(); } break; } case USER_PROFILE: LinkHandler.onLinkClicked(activity, new UserProfileURL(post.src.author).toString()); break; case PROPERTIES: PostPropertiesDialog.newInstance(post.src).show(activity); break; case COMMENTS: ((RedditPostView.PostSelectionListener) activity).onPostCommentsSelected(post); break; case LINK: ((RedditPostView.PostSelectionListener) activity).onPostSelected(post); break; case COMMENTS_SWITCH: if (!(activity instanceof MainActivity)) activity.finish(); ((RedditPostView.PostSelectionListener) activity).onPostCommentsSelected(post); break; case LINK_SWITCH: if (!(activity instanceof MainActivity)) activity.finish(); ((RedditPostView.PostSelectionListener) activity).onPostSelected(post); break; case ACTION_MENU: showActionMenu(activity, post); break; case REPLY: final Intent intent = new Intent(activity, CommentReplyActivity.class); intent.putExtra("parentIdAndType", post.idAndType); activity.startActivity(intent); break; } }
From source file:org.tomahawk.tomahawk_android.utils.TomahawkExceptionReporter.java
/** * Pull information from the given {@link CrashReportData} and send it via HTTP to * oops.tomahawk-player.org or sends it as a TEXT intent, if IS_SILENT is true *///w ww .java2 s .c o m @Override public void send(CrashReportData data) throws ReportSenderException { StringBuilder body = new StringBuilder(); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("Version", data.getProperty(ReportField.APP_VERSION_NAME))); nameValuePairs.add(new BasicNameValuePair("BuildID", data.getProperty(ReportField.BUILD))); nameValuePairs.add(new BasicNameValuePair("ProductName", "tomahawk-android")); nameValuePairs.add(new BasicNameValuePair("Vendor", "Tomahawk")); nameValuePairs.add(new BasicNameValuePair("timestamp", data.getProperty(ReportField.USER_CRASH_DATE))); for (NameValuePair pair : nameValuePairs) { body.append("--thkboundary\r\n"); body.append("Content-Disposition: form-data; name=\""); body.append(pair.getName()).append("\"\r\n\r\n").append(pair.getValue()).append("\r\n"); } body.append("--thkboundary\r\n"); body.append("Content-Disposition: form-data; name=\"upload_file_minidump\"; filename=\"") .append(data.getProperty(ReportField.REPORT_ID)).append("\"\r\n"); body.append("Content-Type: application/octet-stream\r\n\r\n"); body.append("============== Tomahawk Exception Report ==============\r\n\r\n"); body.append("Report ID: ").append(data.getProperty(ReportField.REPORT_ID)).append("\r\n"); body.append("App Start Date: ").append(data.getProperty(ReportField.USER_APP_START_DATE)).append("\r\n"); body.append("Crash Date: ").append(data.getProperty(ReportField.USER_CRASH_DATE)).append("\r\n\r\n"); body.append("--------- Phone Details ----------\r\n"); body.append("Phone Model: ").append(data.getProperty(ReportField.PHONE_MODEL)).append("\r\n"); body.append("Brand: ").append(data.getProperty(ReportField.BRAND)).append("\r\n"); body.append("Product: ").append(data.getProperty(ReportField.PRODUCT)).append("\r\n"); body.append("Display: ").append(data.getProperty(ReportField.DISPLAY)).append("\r\n"); body.append("-----------------------------------\r\n\r\n"); body.append("----------- Stack Trace -----------\r\n"); body.append(data.getProperty(ReportField.STACK_TRACE)).append("\r\n"); body.append("-----------------------------------\r\n\r\n"); body.append("------- Operating System ---------\r\n"); body.append("App Version Name: ").append(data.getProperty(ReportField.APP_VERSION_NAME)).append("\r\n"); body.append("Total Mem Size: ").append(data.getProperty(ReportField.TOTAL_MEM_SIZE)).append("\r\n"); body.append("Available Mem Size: ").append(data.getProperty(ReportField.AVAILABLE_MEM_SIZE)).append("\r\n"); body.append("Dumpsys Meminfo: ").append(data.getProperty(ReportField.DUMPSYS_MEMINFO)).append("\r\n"); body.append("-----------------------------------\r\n\r\n"); body.append("-------------- Misc ---------------\r\n"); body.append("Package Name: ").append(data.getProperty(ReportField.PACKAGE_NAME)).append("\r\n"); body.append("File Path: ").append(data.getProperty(ReportField.FILE_PATH)).append("\r\n"); body.append("Android Version: ").append(data.getProperty(ReportField.ANDROID_VERSION)).append("\r\n"); body.append("Build: ").append(data.getProperty(ReportField.BUILD)).append("\r\n"); body.append("Initial Configuration: ").append(data.getProperty(ReportField.INITIAL_CONFIGURATION)) .append("\r\n"); body.append("Crash Configuration: ").append(data.getProperty(ReportField.CRASH_CONFIGURATION)) .append("\r\n"); body.append("Settings Secure: ").append(data.getProperty(ReportField.SETTINGS_SECURE)).append("\r\n"); body.append("User Email: ").append(data.getProperty(ReportField.USER_EMAIL)).append("\r\n"); body.append("User Comment: ").append(data.getProperty(ReportField.USER_COMMENT)).append("\r\n"); body.append("-----------------------------------\r\n\r\n"); body.append("---------------- Logs -------------\r\n"); body.append("Logcat: ").append(data.getProperty(ReportField.LOGCAT)).append("\r\n\r\n"); body.append("Events Log: ").append(data.getProperty(ReportField.EVENTSLOG)).append("\r\n\r\n"); body.append("Radio Log: ").append(data.getProperty(ReportField.RADIOLOG)).append("\r\n"); body.append("-----------------------------------\r\n\r\n"); body.append("=======================================================\r\n\r\n"); body.append("--thkboundary\r\n"); body.append( "Content-Disposition: form-data; name=\"upload_file_tomahawklog\"; filename=\"Tomahawk.log\"\r\n"); body.append("Content-Type: text/plain\r\n\r\n"); body.append(data.getProperty(ReportField.LOGCAT)); body.append("\r\n--thkboundary--\r\n"); if ("true".equals(data.getProperty(ReportField.IS_SILENT))) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); body.insert(0, "Please tell us why you're sending us this log:\n\n\n\n\n"); intent.putExtra(Intent.EXTRA_TEXT, body.toString()); intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "support@tomahawk-player.org" }); intent.putExtra(Intent.EXTRA_SUBJECT, "Tomahawk Android Log"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); TomahawkApp.getContext().startActivity(intent); } else { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://oops.tomahawk-player.org/addreport.php"); httppost.setHeader("Content-type", "multipart/form-data; boundary=thkboundary"); try { httppost.setEntity(new StringEntity(body.toString())); httpclient.execute(httppost); } catch (ClientProtocolException e) { Log.e(TAG, "send: " + e.getClass() + ": " + e.getLocalizedMessage()); } catch (IOException e) { Log.e(TAG, "send: " + e.getClass() + ": " + e.getLocalizedMessage()); } } }
From source file:com.bellman.bible.android.control.page.PageControl.java
/** send the current verse via social applications installed on user's device *///from w w w . j av a 2 s . c om public void shareVerse(VerseRange verseRange) { try { Book book = getCurrentPageManager().getCurrentPage().getCurrentDocument(); String text = verseRange.getName() + "\n" + SwordContentFacade.getInstance().getCanonicalText(book, verseRange); Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.setType("text/plain"); sendIntent.putExtra(Intent.EXTRA_TEXT, text); // subject is used when user chooses to send verse via e-mail sendIntent.putExtra(Intent.EXTRA_SUBJECT, CurrentActivityHolder.getInstance().getApplication().getText(R.string.share_verse_subject)); Activity activity = CurrentActivityHolder.getInstance().getCurrentActivity(); activity.startActivity(Intent.createChooser(sendIntent, activity.getString(R.string.share_verse))); } catch (Exception e) { Log.e(TAG, "Error sharing verse", e); Dialogs.getInstance().showErrorMsg("Error sharing verse"); } }
From source file:net.bible.android.control.page.PageControl.java
/** send the current verse via social applications installed on user's device *//*from w w w.jav a2s .c o m*/ public void shareVerse() { try { Book book = getCurrentPageManager().getCurrentPage().getCurrentDocument(); Key key = getCurrentPageManager().getCurrentPage().getSingleKey(); String text = key.getName() + "\n" + SwordContentFacade.getInstance().getCanonicalText(book, key); Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.setType("text/plain"); sendIntent.putExtra(Intent.EXTRA_TEXT, text); // subject is used when user chooses to send verse via e-mail sendIntent.putExtra(Intent.EXTRA_SUBJECT, BibleApplication.getApplication().getText(R.string.share_verse_subject)); Activity activity = CurrentActivityHolder.getInstance().getCurrentActivity(); activity.startActivity(Intent.createChooser(sendIntent, activity.getString(R.string.share_verse))); } catch (Exception e) { Log.e(TAG, "Error sharing verse", e); Dialogs.getInstance().showErrorMsg("Error sharing verse"); } }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.LinkObj.java
public void handleDirectMessage(Context context, Contact from, JSONObject obj) { String mimeType = obj.optString(MIME_TYPE); Uri uri = Uri.parse(obj.optString(URI)); if (fileAvailable(mimeType, uri)) { Intent i = new Intent(); i.setAction(Intent.ACTION_VIEW); i.addCategory(Intent.CATEGORY_DEFAULT); i.setType(mimeType); i.setData(uri);//from w w w . ja v a 2 s . c o m i.putExtra(Intent.EXTRA_TEXT, uri); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); (new PresenceAwareNotify(context)).notify("New content from Musubi", "New Content from Musubi", mimeType + " " + uri, contentIntent); } else { Log.w(TAG, "Received file, failed to handle: " + uri); } }