android.content.Intent#setType ( )源码实例Demo

下面列出了android.content.Intent#setType ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android-app   文件: MainActivity.java
@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);
}
 
源代码2 项目: Learning-Resources   文件: IntentShareHelper.java
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");
    }
}
 
源代码3 项目: jpHolo   文件: Share.java
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);
}
 
源代码4 项目: hacker-news-android   文件: IntentUtils.java
/**
 * 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);
}
 
源代码5 项目: NClientV2   文件: Global.java
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);
}
 
源代码6 项目: candybar-library   文件: ReportBugsTask.java
@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;
}
 
源代码7 项目: Android   文件: PacketSendActivity.java
@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"));
}
 
源代码8 项目: NetGuard   文件: ActivityMain.java
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;
}
 
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);
}
 
源代码10 项目: Xndroid   文件: IntentUtils.java
/**
 * 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)));
    }
}
 
源代码11 项目: openlauncher   文件: ShareUtil.java
/**
 * 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);
}
 
源代码12 项目: Hews   文件: ShareBroadcastReceiver.java
@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);
    }
}
 
源代码13 项目: United4   文件: UnitedWebFragment.java
/**
 * 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;
}
 
源代码14 项目: NewFastFrame   文件: MainActivity.java
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);
}
 
源代码15 项目: Cotable   文件: UIHelper.java
/**
 * 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"));
}
 
源代码16 项目: codeexamples-android   文件: ShareActivity.java
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:"));
}
 
源代码17 项目: scallop   文件: WebViewActivity.java
@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);
}
 
源代码18 项目: CoreModule   文件: ShareSDK.java
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, "发送到:"));
}
 
源代码19 项目: X-Alarm   文件: MainActivity.java
@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;
    }
}
 
源代码20 项目: android-intents   文件: SystemIntents.java
/**
 * 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;
}
 
 方法所在类
 同类方法