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.roamprocess1.roaming4world.ui.messages.MessageActivity.java

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

    try {/*from www.j a va 2s  .  c om*/
        startActivityForResult(Intent.createChooser(intent, "Select a File to Upload"), 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();
    }
}

From source file:com.roamprocess1.roaming4world.ui.messages.MessageActivity.java

private void showAudioFileChooser() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("audio/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    try {/*from w ww . j  av  a2 s.c  o  m*/
        startActivityForResult(Intent.createChooser(intent, "Select a File to Upload"), AUDIO_REQUEST);
    } 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();
    }
}

From source file:com.richtodd.android.quiltdesign.app.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    switch (itemId) {
    case R.id.menu_settings: {
        Intent intent = new Intent(this, MainPreferenceActivity.class);
        startActivity(intent);// ww w  .  ja v a  2  s. co  m

        return true;
    }
    case R.id.menu_about: {
        TextDialogFragment dialog = TextDialogFragment.create("About Quilt Design", getString(R.string.about),
                "Close");
        dialog.show(getFragmentManager(), null);

        return true;
    }
    case R.id.menu_help: {
        // Intent intent = new Intent(this, BrowserActivity.class);
        // intent.putExtra(BrowserActivity.ARG_URL,
        // "http://quiltdesign.richtodd.com");

        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://quiltdesign.richtodd.com"));
        startActivity(intent);

        return true;
    }
    case R.id.menu_backup: {
        Uri uriFile;
        try {
            uriFile = saveRepository();

            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.putExtra(Intent.EXTRA_STREAM, uriFile);
            intent.setType("application/vnd.richtodd.quiltdesign");
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

            startActivity(Intent.createChooser(intent, "Backup"));

        } catch (RepositoryException e) {
            Handle.asRuntimeError(e);
        }

        return true;
    }
    case R.id.menu_loadSamples: {

        SampleLoaderTask task = new SampleLoaderTask();
        setSampleLoaderTask(task);
        task.execute(this);

        return true;
    }
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.roamprocess1.roaming4world.ui.messages.MessageActivity.java

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

    intent.addCategory(Intent.CATEGORY_OPENABLE);

    try {//ww w .  j  a va  2s .  c o  m
        startActivityForResult(Intent.createChooser(intent, "Select a File to Upload"), VIDEO_REQUEST);
    } 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();
    }
}

From source file:com.google.android.apps.paco.ExperimentExecutorCustomRendering.java

private boolean sendEmail(String body, String subject, String userEmail) {
    userEmail = findAccount(userEmail);/* w  ww  .  ja  v a2s.co  m*/
    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    String aEmailList[] = { userEmail };
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
    emailIntent.setType("plain/text");
    try {
        startActivity(emailIntent);
        return true;
    } catch (ActivityNotFoundException anf) {
        Log.i(PacoConstants.TAG, "No email client configured");
        return false;
    }
}

From source file:com.edible.ocr.CaptureActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    switch (item.getItemId()) {

    case OPTIONS_COPY_RECOGNIZED_TEXT_ID:
        clipboardManager.setText(ocrResultView.getText());
        if (clipboardManager.hasText()) {
            Toast toast = Toast.makeText(this, "Text copied.", Toast.LENGTH_LONG);
            toast.setGravity(Gravity.BOTTOM, 0, 0);
            toast.show();/*from  www  . j a v  a  2  s .  c o m*/
        }
        return true;
    case OPTIONS_SHARE_RECOGNIZED_TEXT_ID:
        Intent shareRecognizedTextIntent = new Intent(android.content.Intent.ACTION_SEND);
        shareRecognizedTextIntent.setType("text/plain");
        shareRecognizedTextIntent.putExtra(android.content.Intent.EXTRA_TEXT, ocrResultView.getText());
        startActivity(Intent.createChooser(shareRecognizedTextIntent, "Share via"));
        return true;
    case OPTIONS_COPY_TRANSLATED_TEXT_ID:
        clipboardManager.setText(translationView.getText());
        if (clipboardManager.hasText()) {
            Toast toast = Toast.makeText(this, "Text copied.", Toast.LENGTH_LONG);
            toast.setGravity(Gravity.BOTTOM, 0, 0);
            toast.show();
        }
        return true;
    case OPTIONS_SHARE_TRANSLATED_TEXT_ID:
        Intent shareTranslatedTextIntent = new Intent(android.content.Intent.ACTION_SEND);
        shareTranslatedTextIntent.setType("text/plain");
        shareTranslatedTextIntent.putExtra(android.content.Intent.EXTRA_TEXT, translationView.getText());
        startActivity(Intent.createChooser(shareTranslatedTextIntent, "Share via"));
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

From source file:com.linkbubble.Settings.java

private void setDefaultLeftConsumeBubble() {
    String leftConsumeBubblePackageName = mSharedPreferences
            .getString(PREFERENCE_LEFT_CONSUME_BUBBLE_PACKAGE_NAME, null);
    if (leftConsumeBubblePackageName == null) {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        PackageManager packageManager = mContext.getPackageManager();
        List<ResolveInfo> resolveInfos = packageManager.queryIntentActivities(intent, 0);

        if (setDefaultLeftConsumeBubble(
                findResolveInfoForPackageName(resolveInfos, Constant.POCKET_PACKAGE_NAME),
                packageManager) == false) {
            if (setDefaultLeftConsumeBubble(
                    findResolveInfoForPackageName(resolveInfos, "com.instapaper.android"),
                    packageManager) == false) {
                if (setDefaultLeftConsumeBubble(
                        findResolveInfoForPackageName(resolveInfos, "com.facebook.katana"),
                        packageManager) == false) {
                    if (setDefaultLeftConsumeBubble(
                            findResolveInfoForPackageName(resolveInfos, "com.twitter.android"),
                            packageManager) == false) {
                        if (setDefaultLeftConsumeBubble(
                                findResolveInfoForPackageName(resolveInfos, "com.google.android.apps.plus"),
                                packageManager) == false) {
                            if (setDefaultLeftConsumeBubble(
                                    findResolveInfoForPackageName(resolveInfos, "com.google.android.gm"),
                                    packageManager) == false) {
                                // Can't imagine *none* of the above apps will not be installed too often, but if so, fall back to the first item in the list...
                                setDefaultLeftConsumeBubble(resolveInfos.get(0), packageManager);
                            }/*from   w  ww  . j a v  a 2  s  . c  om*/
                        }
                    }
                }
            }
        }
    }
}

From source file:com.intel.xdk.device.Device.java

public void sendEmail(String body, String to, String subject, boolean ishtml, String cc, String bcc) {

    String toArray[] = to.split(",");
    String ccArray[] = cc.split(",");
    String bccArray[] = bcc.split(",");

    Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE); // it's not ACTION_SEND
    if (ishtml) {
        //Android default mail clients poorly support html formatted mail :(
        //intent.setType("text/html");
        //intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(body,null,null));
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT, body);
    } else {//from  w  w w .j av  a  2 s .  c  om
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT, body);
    }

    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    if (toArray.length > 0 && !toArray[0].equals("")) {
        intent.putExtra(Intent.EXTRA_EMAIL, toArray);
    }
    if (ccArray.length > 0 && !ccArray[0].equals("")) {
        intent.putExtra(Intent.EXTRA_CC, ccArray);
    }
    if (bccArray.length > 0 && !bccArray[0].equals("")) {
        intent.putExtra(Intent.EXTRA_BCC, bccArray);
    }

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //return user to app after sending mail
    activity.startActivity(intent);
}

From source file:com.andrewshu.android.reddit.threads.ThreadsListActivity.java

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

    ThingInfo _item = mThreadsAdapter.getItem(info.position);

    switch (item.getItemId()) {
    case Constants.VIEW_SUBREDDIT_CONTEXT_ITEM:
        new MyDownloadThreadsTask(_item.getSubreddit()).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, _item.getUrl());
        try {// w  ww . j a v  a 2  s .c  o  m
            startActivity(Intent.createChooser(intent, "Share Link"));
        } catch (android.content.ActivityNotFoundException ex) {
            if (Constants.LOGGING)
                Log.e(TAG, "Share Link", ex);
        }
        return true;

    case Constants.OPEN_IN_BROWSER_CONTEXT_ITEM:
        setLinkClicked(_item);
        Common.launchBrowser(this, _item.getUrl(), Util.createThreadUri(_item).toString(), false, true, true,
                mSettings.isSaveHistory());
        return true;

    case Constants.SAVE_CONTEXT_ITEM:
        new SaveTask(true, _item, mSettings, getApplicationContext()).execute();
        return true;

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

    case Constants.HIDE_CONTEXT_ITEM:
        new MyHideTask(true, _item, mSettings, getApplicationContext()).execute();
        return true;

    case Constants.UNHIDE_CONTEXT_ITEM:
        new MyHideTask(false, _item, mSettings, getApplicationContext()).execute();

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

    default:
        return super.onContextItemSelected(item);
    }

}

From source file:com.lewa.crazychapter11.MainActivity.java

private void LookupContact() {
    Button btnLookupContact = (Button) findViewById(R.id.btn_lookup_contact);
    btnLookupContact.setOnClickListener(new OnClickListener() {
        @Override//from  w  ww  . j ava2 s . c o  m
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_GET_CONTENT);
            intent.setType("vnd.android.cursor.item/phone");
            startActivityForResult(intent, PICK_CONTACT);
        }
    });
    ((EditText) findViewById(R.id.show)).setVisibility(View.GONE);
    ((EditText) findViewById(R.id.phone)).setVisibility(View.GONE);
    btnLookupContact.setVisibility(View.GONE);
}