Java Code Examples for android.content.Intent#setType()
The following examples show how to use
android.content.Intent#setType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntentShareHelper.java From Learning-Resources with MIT License | 6 votes |
public static void shareOnWhatsapp(AppCompatActivity appCompatActivity, String textBody, Uri fileUri) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.setPackage("com.whatsapp"); intent.putExtra(Intent.EXTRA_TEXT, !TextUtils.isEmpty(textBody) ? textBody : ""); if (fileUri != null) { intent.putExtra(Intent.EXTRA_STREAM, fileUri); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setType("image/*"); } try { appCompatActivity.startActivity(intent); } catch (android.content.ActivityNotFoundException ex) { ex.printStackTrace(); showWarningDialog(appCompatActivity, "activity not found"); } }
Example 2
Source File: MainActivity.java From android-app with The Unlicense | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement txtSubject=(TextView)findViewById(R.id.result); if (id == R.id.action_settings) { Intent share=new Intent(Intent.ACTION_SEND); share.setType("text/plain"); String shareBody=txtSubject.getText().toString()+"\n\nhttps://evilinsult.com/"; String shareSubject=txtSubject.getText().toString(); share.putExtra(Intent.EXTRA_SUBJECT,shareSubject); share.putExtra(Intent.EXTRA_TEXT,shareBody); startActivity(Intent.createChooser(share,"Share using")); } return super.onOptionsItemSelected(item); }
Example 3
Source File: ShareUtil.java From openlauncher with Apache License 2.0 | 5 votes |
/** * Share text with given mime-type * * @param text The text to share * @param mimeType MimeType or null (uses text/plain) */ public void shareText(final String text, @Nullable final String mimeType) { Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_TEXT, text); intent.setType(mimeType != null ? mimeType : MIME_TEXT_PLAIN); showChooser(intent, null); }
Example 4
Source File: ShareSDK.java From CoreModule with Apache License 2.0 | 5 votes |
public static void shareUrl(Context context, String url) { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, "来自开源实验室的分享:" + url); sendIntent.setType("text/plain"); context.startActivity(Intent.createChooser(sendIntent, "发送到:")); }
Example 5
Source File: WebViewActivity.java From scallop with MIT License | 5 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: onBackPressed(); break; case R.id.share: Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("text/plain"); String shareText = getResources().getString(R.string.share_dialog_title_share); String shareContent = getResources().getString(R.string.share_content); shareIntent.putExtra(Intent.EXTRA_SUBJECT, shareText); shareIntent.putExtra(Intent.EXTRA_TEXT, url + shareContent); startActivity(Intent.createChooser(shareIntent, shareText)); break; case R.id.refresh: webView.reload(); break; case R.id.copy_link: copyTextToClipboard(); break; case R.id.open_in_browser: if (!url.startsWith("http://") && !url.startsWith("https://")) { url = "http://" + url; } Intent openBrowserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(openBrowserIntent); break; } return super.onOptionsItemSelected(item); }
Example 6
Source File: ShareActivity.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
public void onClick(View view) { EditText editView = (EditText) findViewById(R.id.input); String string = editView.getText().toString(); Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, string); startActivity(Intent.createChooser(intent, "Share with:")); }
Example 7
Source File: UIHelper.java From Cotable with Apache License 2.0 | 5 votes |
/** * Call the system application with shares. * * @param context context * @param title share title * @param url share url */ public static void showShareMore(Activity context, final String title, final String url) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, "Share: " + title); intent.putExtra(Intent.EXTRA_TEXT, title + " " + url); context.startActivity(Intent.createChooser(intent, "Choose to share")); }
Example 8
Source File: MainActivity.java From NewFastFrame with Apache License 2.0 | 5 votes |
public void pickPhoto(Activity activity, int requestCode) { Intent intent = new Intent(); if (Build.VERSION.SDK_INT < 19) { intent.setAction(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); } else { intent.setAction(Intent.ACTION_PICK); intent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI); } activity.startActivityForResult(intent, requestCode); }
Example 9
Source File: UnitedWebFragment.java From United4 with GNU General Public License v3.0 | 5 votes |
/** * Creates an intent for an email activity * @param address the email address to send to * @param subject the subject * @param body the body * @param cc any email addresses to cc * @return an intent that when started, prompts the user to send the email */ private static Intent newEmailIntent(String address, String subject, String body, String cc) { Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_EMAIL, new String[] { address }); intent.putExtra(Intent.EXTRA_TEXT, body); intent.putExtra(Intent.EXTRA_SUBJECT, subject); intent.putExtra(Intent.EXTRA_CC, cc); intent.setType("message/rfc822"); return intent; }
Example 10
Source File: ShareBroadcastReceiver.java From Hews with MIT License | 5 votes |
@Override public void onReceive(Context context, Intent intent) { String url = intent.getDataString(); if (url != null) { Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("text/plain"); shareIntent.putExtra(Intent.EXTRA_TEXT, url); Intent chooserIntent = Intent.createChooser(shareIntent, "Share url"); chooserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(chooserIntent); } }
Example 11
Source File: Share.java From jpHolo with MIT License | 5 votes |
private void doSendIntent(final String subject, final String text) { final Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND); sendIntent.setType("text/plain"); sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, text); cordova.getActivity().startActivityForResult(sendIntent, 0); }
Example 12
Source File: IntentUtils.java From Xndroid with GNU General Public License v3.0 | 5 votes |
/** * Shares a URL to the system. * * @param url the URL to share. If the URL is null * or a special URL, no sharing will occur. * @param title the title of the URL to share. This * is optional. */ public void shareUrl(@Nullable String url, @Nullable String title) { if (url != null && !UrlUtils.isSpecialUrl(url)) { Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("text/plain"); if (title != null) { shareIntent.putExtra(Intent.EXTRA_SUBJECT, title); } shareIntent.putExtra(Intent.EXTRA_TEXT, url); mActivity.startActivity(Intent.createChooser(shareIntent, mActivity.getString(R.string.dialog_title_share))); } }
Example 13
Source File: DappBrowserViewModel.java From alpha-wallet-android with MIT License | 5 votes |
public void share(Context context, String url) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_TEXT, url); intent.setType("text/plain"); context.startActivity(intent); }
Example 14
Source File: ActivityMain.java From NetGuard with GNU General Public License v3.0 | 5 votes |
private static Intent getIntentInvite(Context context) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.app_name)); intent.putExtra(Intent.EXTRA_TEXT, context.getString(R.string.msg_try) + "\n\nhttps://www.netguard.me/\n\n"); return intent; }
Example 15
Source File: PacketSendActivity.java From Android with MIT License | 5 votes |
@OnClick(R.id.send_btn) void sendPacket(View view) { String url = sendOutBean.getUrl(); Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_TEXT, url); shareIntent.setType("text/plain"); startActivity(Intent.createChooser(shareIntent, "share to")); }
Example 16
Source File: ReportBugsTask.java From candybar-library with Apache License 2.0 | 5 votes |
@Override protected void onPostExecute(Boolean aBoolean) { super.onPostExecute(aBoolean); if (mContext.get() == null) return; if (((AppCompatActivity) mContext.get()).isFinishing()) return; mDialog.dismiss(); if (aBoolean) { final Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("message/rfc822"); intent.putExtra(Intent.EXTRA_EMAIL, new String[]{mContext.get().getResources().getString(R.string.dev_email)}); intent.putExtra(Intent.EXTRA_SUBJECT, "Report Bugs " + (mContext.get().getString( R.string.app_name))); intent.putExtra(Intent.EXTRA_TEXT, mStringBuilder.toString()); if (mZipPath != null) { File zip = new File(mZipPath); if (zip.exists()) { Uri uri = getUriFromFile(mContext.get(), mContext.get().getPackageName(), zip); if (uri == null) uri = Uri.fromFile(zip); intent.putExtra(Intent.EXTRA_STREAM, uri); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } } mContext.get().startActivity(Intent.createChooser(intent, mContext.get().getResources().getString(R.string.email_client))); } else { Toast.makeText(mContext.get(), R.string.report_bugs_failed, Toast.LENGTH_LONG).show(); } mZipPath = null; }
Example 17
Source File: Global.java From NClientV2 with Apache License 2.0 | 5 votes |
public static void shareURL(Context context,String title, String url){ Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT,title+": "+url); sendIntent.setType("text/plain"); Intent clipboardIntent = new Intent(context, CopyToClipboardActivity.class); clipboardIntent.setData(Uri.parse(url)); Intent chooserIntent = Intent.createChooser(sendIntent,context.getString(R.string.share_with)); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { clipboardIntent }); context.startActivity(chooserIntent); }
Example 18
Source File: IntentUtils.java From hacker-news-android with Apache License 2.0 | 5 votes |
/** * Share plain text using system share * @param context Context to share from * @param text plain text to share * @see Intent#ACTION_SEND */ public static void share(final Context context, final String text){ Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.setType("text/plain"); shareIntent.putExtra(Intent.EXTRA_TEXT, text); context.startActivity(shareIntent); }
Example 19
Source File: MainActivity.java From X-Alarm with GNU Affero General Public License v3.0 | 4 votes |
@Override public void onClick(View v) { switch (v.getId()) { // Go to Set Alarm Activity case R.id.im_set_alarm: Intent intent = new Intent(MainActivity.this, SetAlarmActivity.class); intent.putExtra(AlarmScheduler.X_ALARM_ID, mAlarm.getId()); startActivityForResult(intent, SET_ALARM_REQUEST_CODE); break; case R.id.iv_top_main_content_indicator: if (mAlarm.isEnabled()) { mAlarm.setEnabled(false); mAlarm.cancel(); ivMainContentIndicator.setImageResource(R.drawable.main_mid_off); ToastMaster.setToast(Toast.makeText(MainActivity.this, getString(R.string.turn_off_alarm), Toast.LENGTH_SHORT)); } else { mAlarm.setEnabled(true); mAlarm.schedule(); ivMainContentIndicator.setImageResource(R.drawable.main_mid); ToastMaster.setToast(Toast.makeText(MainActivity.this, getString(R.string.turn_on_alarm), Toast.LENGTH_SHORT)); } updateAlarmDistanceText(); ToastMaster.showToast(); break; case R.id.iv_left_menu_indicator: if (loopXDragMenuLayout.getMenuStatus() == DragMenuLayout.MenuStatus.Close) { loopXDragMenuLayout.openLeftMenuWithAnimation(); } else { loopXDragMenuLayout.closeMenuWithAnimation(); } break; case R.id.iv_right_menu_indicator: if (loopXDragMenuLayout.getMenuStatus() == DragMenuLayout.MenuStatus.Close) { loopXDragMenuLayout.openRightMenuWithAnimation(); } else { loopXDragMenuLayout.closeMenuWithAnimation(); } break; case R.id.btn_about: Intent intentToAbout = new Intent(this, AboutActivity.class); startActivity(intentToAbout); break; case R.id.btn_share: Intent intentToShare = new Intent(Intent.ACTION_SEND); intentToShare.setType("text/plain"); intentToShare.putExtra(Intent.EXTRA_SUBJECT, "X Alarm"); String sAux = "\n独特的起床闹钟\n\n"; // ToDo 分享 sAux = sAux + "XXXXX \n\n"; intentToShare.putExtra(Intent.EXTRA_TEXT, sAux); startActivity(Intent.createChooser(intentToShare, "Choose one")); break; } }
Example 20
Source File: SystemIntents.java From android-intents with Apache License 2.0 | 2 votes |
/** * Pick file from sdcard with file manager. Chosen file can be obtained from Intent in onActivityResult. * See code below for example: * <p/> * <pre><code> * @Override * protected void onActivityResult(int requestCode, int resultCode, Intent data) { * Uri file = data.getData(); * } * </code></pre> */ public static Intent newPickFileIntent() { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("file/*"); return intent; }