Example usage for android.content Intent setType

List of usage examples for android.content Intent setType

Introduction

In this page you can find the example usage for android.content Intent setType.

Prototype

public @NonNull Intent setType(@Nullable String type) 

Source Link

Document

Set an explicit MIME data type.

Usage

From source file:com.stikyhive.stikyhive.ChattingActivity.java

private void showFileChooser() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("File/*");

    /*try {/*from ww  w  .ja  v  a  2s. c om*/
    startActivityForResult(intent, FILE_SELECT_CODE);
    } catch (android.content.ActivityNotFoundException ex) {
    // Potentially direct the user to the Market with a Dialog
    Toast.makeText(this, "Please install a File Manager.",
            Toast.LENGTH_SHORT).show();
    }*/
    // special intent for Samsung file manager
    Intent sIntent = new Intent("com.sec.android.app.myfiles.PICK_DATA");
    // if you want any file type, you can skip next line
    // sIntent.putExtra("CONTENT_TYPE", "*/*");
    sIntent.addCategory(Intent.CATEGORY_DEFAULT);

    Intent chooserIntent;
    if (getPackageManager().resolveActivity(sIntent, 0) != null) {
        // it is device with samsung file manager
        chooserIntent = Intent.createChooser(sIntent, "Open file");
        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { intent });
    } else {
        chooserIntent = Intent.createChooser(intent, "Open file");
    }

    try {
        startActivityForResult(chooserIntent, FILE_SELECT_CODE);
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(getApplicationContext(), "No suitable File Manager was found.", Toast.LENGTH_SHORT)
                .show();
    }
}

From source file:com.mitre.holdshort.MainActivity.java

private void contactMITRE(String subject) {

    final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.setType("plain/text");
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "ripple@mitre.org" });
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    emailIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}

From source file:com.ichi2.anki.DeckPicker.java

public void emailFile(String path) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("message/rfc822");
    intent.putExtra(Intent.EXTRA_SUBJECT, "AnkiDroid Apkg");
    File attachment = new File(path);
    if (attachment.exists()) {
        Uri uri = Uri.fromFile(attachment);
        intent.putExtra(Intent.EXTRA_STREAM, uri);
    }/*w w w  . j  a  v a2s .  com*/
    try {
        startActivityWithoutAnimation(intent);
    } catch (ActivityNotFoundException e) {
        Themes.showThemedToast(this, getResources().getString(R.string.no_email_client), false);
    }
}

From source file:com.mibr.android.intelligentreminder.INeedToo.java

@Override
public Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_REMINDER_CONTACTS_SERVICE_FAILED_LICENSING:
        AlertDialog.Builder buildersvc = new AlertDialog.Builder(this);
        buildersvc.setMessage(/*www  .  j  ava 2s . co m*/
                "The Reminder Contact Service add-on that you've got installed is not a licensed version");
        buildersvc.setCancelable(false)
                .setNeutralButton(R.string.msg_cus, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        String[] mailto = { "info@intelligentreminder.com", "" };
                        Intent sendIntent = new Intent(Intent.ACTION_SEND);
                        sendIntent.putExtra(Intent.EXTRA_EMAIL, mailto);
                        sendIntent.putExtra(Intent.EXTRA_SUBJECT, "".toString());
                        sendIntent.putExtra(Intent.EXTRA_TEXT, "".toString());
                        sendIntent.setType("text/plain");
                        startActivity(Intent.createChooser(sendIntent, "Send EMail..."));
                    }
                }).setPositiveButton(R.string.msg_register, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {

                        if (INeedToo.IS_ANDROID_VERSION) {
                            String uri = getString(R.string.indeedtopayforservice);
                            Intent ii3 = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
                            startActivity(ii3);
                        } else {
                            Uri uri = Uri.parse(
                                    "http://www.amazon.com/gp/mas/dl/android?p=com.mibr.android.remindercontacts");
                            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                            startActivity(intent);
                        }

                        isReminderContactsAvailable = true;
                        iDidReminderContacts = false;
                    }
                }).setNegativeButton(R.string.msg_cancel, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
        AlertDialog alert = buildersvc.create();
        return alert;

    case DOING_SAMPLE_NEEDS_DIALOG:
        if (allItems == null) {
            return null;
        }
        dialogDoingSamples = new Dialog(this);
        dialogDoingSamples.setOwnerActivity(this);
        dialogDoingSamples.setContentView(R.layout.ineedvoiceprogress);
        dialogDoingSamples.setTitle("Working ...");
        ((Button) dialogDoingSamples.findViewById(R.id.needvoiceprogress_cancel)).setEnabled(true);
        ((Button) dialogDoingSamples.findViewById(R.id.needvoiceprogress_ok)).setEnabled(false);
        ;
        //         dialogDoingSamples.show();
        ArrayList stuff = new ArrayList();
        stuff.add(dialogDoingSamples);
        stuff.add(getApplicationContext());
        stuff.add(this);
        stuff.add(getLocationManager());
        stuff.add(getDbAdapter());
        stuff.add(allItems.get(whereImAtInAllItems));
        stuff.add(new Integer(1));
        new NeedByVoiceProgress().execute(stuff);
        return dialogDoingSamples;

    case DIALOG_SAMPLES:
        Dialog aDialog = null;
        AlertDialog.Builder builder2;
        LayoutInflater inflater2 = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
        View layout2 = inflater2.inflate(R.layout.ineedsamples, (ViewGroup) findViewById(R.id.hijklmnop));
        builder2 = new AlertDialog.Builder(this);
        builder2.setView(layout2);
        builder2.setTitle("Build Sample Data Set");
        builder2.setPositiveButton("Okay", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                allItems = new ArrayList<ArrayList<String>>();
                Boolean doit = false;
                StringBuilder sb = new StringBuilder();
                StringBuilder sb2 = new StringBuilder();
                StringBuilder sb3 = new StringBuilder();
                int cnt = 0;
                Boolean dw = false;
                ArrayList<String> jdmatchesSS = null;
                ;
                sb.append("I need Print Cartridges description HP 28 and 48 ");
                if (mWalmart != null && mWalmart.isChecked()) {
                    sb.append(" location Walmart ");
                    dw = true;
                }
                if (mWalgreens != null && mWalgreens.isChecked()) {
                    sb.append(" location Walgreens ");
                    dw = true;
                }
                if (dw) { // they checked something
                    doit = true;
                    jdmatchesSS = new ArrayList<String>();
                    jdmatchesSS.add(sb.toString());
                    allItems.add(jdmatchesSS);
                    cnt++;
                }
                if (mSevenEleven != null && mSevenEleven.isChecked()) {
                    sb3.append("I need Energy Drink description Red Bull location 7-Eleven ");
                    ArrayList<String> jdmatches = new ArrayList<String>();
                    jdmatches.add(sb3.toString());
                    allItems.add(jdmatches);
                    cnt++;
                    doit = true;
                }

                if (mStarbucks != null && mStarbucks.isChecked()) {
                    sb2.append("I need Coffee description French Roast location Starbucks");
                    ArrayList<String> jdmatches = new ArrayList<String>();
                    jdmatches.add(sb2.toString());
                    allItems.add(jdmatches);
                    cnt++;
                    doit = true;
                }
                if (doit) {
                    whereImAtInAllItems = 0;
                    INeedToo.this.showDialog(DOING_SAMPLE_NEEDS_DIALOG);
                }

            }
        });
        mWalmart = (CheckBox) layout2.findViewById(R.id.BuildWalmart);
        mWalgreens = (CheckBox) layout2.findViewById(R.id.BuildWalgreens);
        mSevenEleven = (CheckBox) layout2.findViewById(R.id.Build7Eleven);
        mStarbucks = (CheckBox) layout2.findViewById(R.id.BuildStarbucks);

        aDialog = builder2.create();
        return aDialog;

    case DIALOG_SPLASH:
        /*
        jdd=new Dialog(mContext);
        jdd.setContentView(R.layout.ineed2splash);
        jdd.setTitle("W E L C O M E");
        */

        AlertDialog.Builder builder;
        LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.ineed2splashv2,
                (ViewGroup) findViewById(R.id.ScrollView01lmnop2));
        builder = new AlertDialog.Builder(this);

        builder.setPositiveButton("Okay", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                if (mWantSample != null) {
                    if (mWantSample.isChecked()) {
                        showDialog(DIALOG_SAMPLES);
                    }
                }
            }
        });
        builder.setTitle("W E L C O M E");
        if (getDbAdapter().thereAreSomeLocationsOnSystem()) {
            LinearLayout ll = (LinearLayout) layout.findViewById(R.id.CreateDefaultValues);
            ll.setVisibility(View.INVISIBLE);
        } else {
            mWantSample = (CheckBox) layout.findViewById(R.id.BuildDefaultValues);
        }
        builder.setView(layout);
        jdd = builder.create();
        //Button butt=(Button)jdd.findViewById(R.id.Button01);
        /*butt.setOnClickListener(new View.OnClickListener() {
                   
           @Override
           public void onClick(View v) {
              jdd.cancel();
           }
        });
        */
        break;
    default:
        return null;
    }
    return jdd;

}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Allows to create a share intent and it can be launched.
 * /*from w w  w.  ja  va  2  s .  c o m*/
 * @param context
 * @param type      Mime type.
 * @param nameApp   You can filter the application you want to share with. Use "wha", "twitt", etc.
 * @param title      The title of the share.Take in account that sometimes is not possible to add the title.
 * @param data      The data, can be a file or a text.
 * @param isBinaryData   If the share has a data file, set to TRUE otherwise FALSE.
 */
@SuppressLint("DefaultLocale")
public static Intent share_newSharingIntent(Context context, String type, String nameApp, String title,
        String data, boolean isBinaryData, boolean launch) {

    Intent res = null;

    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType(type);

    List<Intent> targetedShareIntents = new ArrayList<Intent>();
    List<ResolveInfo> resInfo = context.getPackageManager().queryIntentActivities(share, 0);
    if (!resInfo.isEmpty()) {
        for (ResolveInfo info : resInfo) {
            Intent targetedShare = new Intent(Intent.ACTION_SEND);
            targetedShare.setType(type);

            if (title != null) {
                targetedShare.putExtra(Intent.EXTRA_SUBJECT, title);
                targetedShare.putExtra(Intent.EXTRA_TITLE, title);
                if (data != null && !isBinaryData) {
                    targetedShare.putExtra(Intent.EXTRA_TEXT, data);
                }
            }
            if (data != null && isBinaryData) {
                targetedShare.putExtra(Intent.EXTRA_TEXT, title);
                targetedShare.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(data)));
            }

            if (nameApp != null) {
                if (info.activityInfo.packageName.toLowerCase().contains(nameApp)
                        || info.activityInfo.name.toLowerCase().contains(nameApp)) {
                    targetedShare.setPackage(info.activityInfo.packageName);
                    targetedShareIntents.add(targetedShare);
                }
            } else {
                targetedShare.setPackage(info.activityInfo.packageName);
                targetedShareIntents.add(targetedShare);
            }
        }

        Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Select app to share");
        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[] {}));

        res = chooserIntent;

        if (launch) {
            context.startActivity(chooserIntent);
        }
    }

    return res;
}

From source file:com.andrewshu.android.reddit.comments.CommentsListActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    int rowId = (int) info.id;

    switch (item.getItemId()) {
    case Constants.SAVE_CONTEXT_ITEM:
        new SaveTask(true, getOpThingInfo(), mSettings, this).execute();
        return true;

    case Constants.UNSAVE_CONTEXT_ITEM:
        new SaveTask(false, getOpThingInfo(), mSettings, this).execute();
        return true;

    case Constants.HIDE_CONTEXT_ITEM:
        new HideTask(true, getOpThingInfo(), mSettings, this).execute();
        return true;

    case Constants.UNHIDE_CONTEXT_ITEM:
        new HideTask(false, getOpThingInfo(), mSettings, this).execute();
        return true;

    case Constants.SHARE_CONTEXT_ITEM:
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_SEND);
        intent.setType("text/plain");

        intent.putExtra(Intent.EXTRA_TEXT, getOpThingInfo().getUrl());

        try {/* ww w  .ja  v a 2s  .co m*/
            startActivity(Intent.createChooser(intent, "Share Link"));
        } catch (android.content.ActivityNotFoundException ex) {

        }

        return true;

    case Constants.DIALOG_HIDE_COMMENT:
        hideComment(rowId);
        return true;

    case Constants.DIALOG_SHOW_COMMENT:
        showComment(rowId);
        return true;

    case Constants.DIALOG_GOTO_PARENT:
        int myIndent = mCommentsAdapter.getItem(rowId).getIndent();
        int parentRowId;
        for (parentRowId = rowId - 1; parentRowId >= 0; parentRowId--)
            if (mCommentsAdapter.getItem(parentRowId).getIndent() < myIndent)
                break;
        getListView().setSelection(parentRowId);
        return true;

    case Constants.DIALOG_VIEW_PROFILE:
        Intent i = new Intent(this, ProfileActivity.class);
        i.setData(Util.createProfileUri(mCommentsAdapter.getItem(rowId).getAuthor()));
        startActivity(i);
        return true;

    case Constants.DIALOG_EDIT:
        mReplyTargetName = mCommentsAdapter.getItem(rowId).getName();
        mEditTargetBody = mCommentsAdapter.getItem(rowId).getBody();
        showDialog(Constants.DIALOG_EDIT);
        return true;

    case Constants.DIALOG_DELETE:
        mReplyTargetName = mCommentsAdapter.getItem(rowId).getName();
        // It must be a comment, since the OP selftext is reached via options menu, not context menu
        mDeleteTargetKind = Constants.COMMENT_KIND;
        showDialog(Constants.DIALOG_DELETE);
        return true;

    case Constants.DIALOG_REPORT:
        mReportTargetName = mCommentsAdapter.getItem(rowId).getName();
        showDialog(Constants.DIALOG_REPORT);
        return true;

    default:
        return super.onContextItemSelected(item);
    }
}