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.cordova.photo.CameraLauncher.java

/**
 * Get image from photo library.//from w  w w .j  a  v a2  s . c o m
 *
 * @param quality           Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
 * @param srcType           The album to get image from.
 * @param returnType        Set the type of image to return.
 * @param encodingType 
 */
// TODO: Images selected from SDCARD don't display correctly, but from CAMERA ALBUM do!
// TODO: Images from kitkat filechooser not going into crop function
public void getImage(int srcType, int returnType, int encodingType) {
    Intent intent = new Intent();
    String title = GET_PICTURE;
    croppedUri = null;
    if (this.mediaType == PICTURE) {
        intent.setType("image/*");
        if (this.allowEdit) {
            intent.setAction(Intent.ACTION_PICK);
            intent.putExtra("crop", "true");
            if (targetWidth > 0) {
                intent.putExtra("outputX", targetWidth);
            }
            if (targetHeight > 0) {
                intent.putExtra("outputY", targetHeight);
            }
            if (targetHeight > 0 && targetWidth > 0 && targetWidth == targetHeight) {
                intent.putExtra("aspectX", 1);
                intent.putExtra("aspectY", 1);
            }
            File photo = createCaptureFile(encodingType);
            croppedUri = Uri.fromFile(photo);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, croppedUri);
        } else {
            intent.setAction(Intent.ACTION_GET_CONTENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
        }
    } else if (this.mediaType == VIDEO) {
        intent.setType("video/*");
        title = GET_VIDEO;
        intent.setAction(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
    } else if (this.mediaType == ALLMEDIA) {
        // I wanted to make the type 'image/*, video/*' but this does not work on all versions
        // of android so I had to go with the wildcard search.
        intent.setType("*/*");
        title = GET_All;
        intent.setAction(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
    }
    if (this.activity != null) {
        this.activity.startActivityForResult(Intent.createChooser(intent, new String(title)),
                (srcType + 1) * 16 + returnType + 1);
    }
}

From source file:com.fabernovel.alertevoirie.ReportDetailsActivity.java

private void takePicture(int type, int RequestCode) {
    // Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    File tmpFile = null;/* w  w  w  .j  av  a 2  s  .c  o  m*/
    try {
        tmpFile = File.createTempFile("capture", ".tmp");
    } catch (IOException e) {
        e.printStackTrace();
    }

    Intent camIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    uriOfPicFromCamera = Uri.fromFile(tmpFile);
    camIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriOfPicFromCamera);

    Intent gallIntent = new Intent();
    gallIntent.setType("image/*");
    gallIntent.setAction(Intent.ACTION_GET_CONTENT);

    if (type == 0) {
        ReportDetailsActivity.this.startActivityForResult(camIntent, RequestCode);
    } else if (type == 1) {
        ReportDetailsActivity.this.startActivityForResult(Intent.createChooser(gallIntent, "Galerie photo"),
                RequestCode);
    }
    // startActivityForResult(intent, v.getId());

}

From source file:com.matthewmitchell.peercoin_android_wallet.ui.WalletActivity.java

private void archiveWalletBackup(@Nonnull final File file) {
    final Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.export_keys_dialog_mail_subject));
    intent.putExtra(Intent.EXTRA_TEXT, makeEmailText(getString(R.string.export_keys_dialog_mail_text)));
    intent.setType(Constants.MIMETYPE_WALLET_BACKUP);
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));

    try {/*from ww  w. j a  v a  2s .c o m*/
        startActivity(Intent.createChooser(intent, getString(R.string.export_keys_dialog_mail_intent_chooser)));
        log.info("invoked chooser for archiving wallet backup");
    } catch (final Exception x) {
        longToast(R.string.export_keys_dialog_mail_intent_failed);
        log.error("archiving wallet backup failed", x);
    }
}

From source file:com.dwdesign.tweetings.fragment.StatusFragment.java

@SuppressLint({ "NewApi", "NewApi", "NewApi" })
@Override//www .  j av a 2s  .c  o m
public boolean onMenuItemClick(final MenuItem item) {
    if (mStatus == null)
        return false;
    final String text_plain = mStatus.text_plain;
    final String screen_name = mStatus.screen_name;
    final String name = mStatus.name;
    switch (item.getItemId()) {
    case MENU_SHARE: {
        final Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT, "@" + mStatus.screen_name + ": " + text_plain);
        startActivity(Intent.createChooser(intent, getString(R.string.share)));
        break;
    }
    case MENU_RETWEET: {
        if (isMyRetweet(mStatus)) {
            mService.destroyStatus(mAccountId, mStatus.retweet_id);
        } else {
            final long id_to_retweet = mStatus.is_retweet && mStatus.retweet_id > 0 ? mStatus.retweet_id
                    : mStatus.status_id;
            mService.retweetStatus(mAccountId, id_to_retweet);
        }
        break;
    }
    case MENU_TRANSLATE: {
        translate(mStatus);
        break;
    }
    case MENU_QUOTE_REPLY: {
        final Intent intent = new Intent(INTENT_ACTION_COMPOSE);
        final Bundle bundle = new Bundle();
        bundle.putLong(INTENT_KEY_ACCOUNT_ID, mAccountId);
        bundle.putLong(INTENT_KEY_IN_REPLY_TO_ID, mStatusId);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_SCREEN_NAME, screen_name);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_NAME, name);
        bundle.putBoolean(INTENT_KEY_IS_QUOTE, true);
        bundle.putString(INTENT_KEY_TEXT, getQuoteStatus(getActivity(), screen_name, text_plain));
        intent.putExtras(bundle);
        startActivity(intent);
        break;
    }
    case MENU_QUOTE: {
        final Intent intent = new Intent(INTENT_ACTION_COMPOSE);
        final Bundle bundle = new Bundle();
        bundle.putLong(INTENT_KEY_ACCOUNT_ID, mAccountId);
        bundle.putBoolean(INTENT_KEY_IS_QUOTE, true);
        bundle.putString(INTENT_KEY_TEXT, getQuoteStatus(getActivity(), screen_name, text_plain));
        intent.putExtras(bundle);
        startActivity(intent);
        break;
    }
    case MENU_ADD_TO_BUFFER: {
        final Intent intent = new Intent(INTENT_ACTION_COMPOSE);
        final Bundle bundle = new Bundle();
        bundle.putLong(INTENT_KEY_ACCOUNT_ID, mAccountId);
        bundle.putBoolean(INTENT_KEY_IS_BUFFER, true);
        bundle.putString(INTENT_KEY_TEXT, getQuoteStatus(getActivity(), screen_name, text_plain));
        intent.putExtras(bundle);
        startActivity(intent);
        break;
    }
    case MENU_REPLY: {
        final Intent intent = new Intent(INTENT_ACTION_COMPOSE);
        final Bundle bundle = new Bundle();
        final List<String> mentions = new Extractor().extractMentionedScreennames(text_plain);
        mentions.remove(screen_name);
        mentions.add(0, screen_name);
        bundle.putStringArray(INTENT_KEY_MENTIONS, mentions.toArray(new String[mentions.size()]));
        bundle.putLong(INTENT_KEY_ACCOUNT_ID, mAccountId);
        bundle.putLong(INTENT_KEY_IN_REPLY_TO_ID, mStatusId);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_TWEET, text_plain);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_SCREEN_NAME, screen_name);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_NAME, name);
        intent.putExtras(bundle);
        startActivity(intent);
        break;
    }
    case MENU_FAV: {
        if (mStatus.is_favorite) {
            mService.destroyFavorite(mAccountId, mStatusId);
        } else {
            mService.createFavorite(mAccountId, mStatusId);
        }
        break;
    }
    case MENU_COPY_CLIPBOARD: {
        final String textToCopy = "@" + mStatus.screen_name + ": " + mStatus.text_plain;
        int sdk = android.os.Build.VERSION.SDK_INT;
        if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
            android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(
                    Context.CLIPBOARD_SERVICE);
            clipboard.setText(textToCopy);
        } else {
            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                    Context.CLIPBOARD_SERVICE);
            android.content.ClipData clip = android.content.ClipData.newPlainText("Status", textToCopy);
            clipboard.setPrimaryClip(clip);
        }
        Toast.makeText(getActivity(), R.string.text_copied, Toast.LENGTH_SHORT).show();
        break;
    }
    case MENU_DELETE: {
        mService.destroyStatus(mAccountId, mStatusId);
        break;
    }
    case MENU_EXTENSIONS: {
        final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_STATUS);
        final Bundle extras = new Bundle();
        extras.putParcelable(INTENT_KEY_STATUS, mStatus);
        intent.putExtras(extras);
        startActivity(Intent.createChooser(intent, getString(R.string.open_with_extensions)));
        break;
    }
    case MENU_MUTE_SOURCE: {
        final String source = HtmlEscapeHelper.unescape(mStatus.source);
        if (source == null)
            return false;
        final Uri uri = Filters.Sources.CONTENT_URI;
        final ContentValues values = new ContentValues();
        final SharedPreferences.Editor editor = getSharedPreferences(SHARED_PREFERENCES_NAME,
                Context.MODE_PRIVATE).edit();
        final ContentResolver resolver = getContentResolver();
        values.put(Filters.TEXT, source);
        resolver.delete(uri, Filters.TEXT + " = '" + source + "'", null);
        resolver.insert(uri, values);
        editor.putBoolean(PREFERENCE_KEY_ENABLE_FILTER, true).commit();
        Toast.makeText(getActivity(), getString(R.string.source_muted, source), Toast.LENGTH_SHORT).show();
        break;
    }
    case MENU_SET_COLOR: {
        final Intent intent = new Intent(INTENT_ACTION_SET_COLOR);
        startActivityForResult(intent, REQUEST_SET_COLOR);
        break;
    }
    case MENU_CLEAR_COLOR: {
        clearUserColor(getActivity(), mStatus.user_id);
        updateUserColor();
        break;
    }
    case MENU_RECENT_TWEETS: {
        openUserTimeline(getActivity(), mAccountId, mStatus.user_id, mStatus.screen_name);
        break;
    }
    case MENU_FIND_RETWEETS: {
        openUserRetweetedStatus(getActivity(), mStatus.account_id,
                mStatus.retweet_id > 0 ? mStatus.retweet_id : mStatus.status_id);
        break;
    }
    default:
        return false;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.shafiq.myfeedle.core.MyfeedleCreatePost.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    if (itemId == R.id.menu_post_accounts)
        chooseAccounts();/*from   w  ww .j  a  va  2  s.c  o m*/
    else if (itemId == R.id.menu_post_photo) {
        boolean supported = false;
        Iterator<Integer> services = mAccountsService.values().iterator();
        while (services.hasNext() && ((supported = sPhotoSupported.contains(services.next())) == false))
            ;
        if (supported) {
            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent, "Select Picture"), PHOTO);
        } else
            unsupportedToast(sPhotoSupported);
        //      } else if (itemId == R.id.menu_post_tags) {
        //         if (mAccountsService.size() == 1) {
        //            if (sTaggingSupported.contains(mAccountsService.values().iterator().next()))
        //               selectFriends(mAccountsService.keySet().iterator().next());
        //            else
        //               unsupportedToast(sTaggingSupported);
        //         } else {
        //            // dialog to select an account
        //            Iterator<Long> accountIds = mAccountsService.keySet().iterator();
        //            HashMap<Long, String> accountEntries = new HashMap<Long, String>();
        //            while (accountIds.hasNext()) {
        //               Long accountId = accountIds.next();
        //               Cursor account = this.getContentResolver().query(Accounts.getContentUri(this), new String[]{Accounts._ID, ACCOUNTS_QUERY}, Accounts._ID + "=?", new String[]{Long.toString(accountId)}, null);
        //               if (account.moveToFirst() && sTaggingSupported.contains(mAccountsService.get(accountId)))
        //                  accountEntries.put(account.getLong(0), account.getString(1));
        //            }
        //            int size = accountEntries.size();
        //            if (size != 0) {
        //               final long[] accountIndexes = new long[size];
        //               final String[] accounts = new String[size];
        //               int i = 0;
        //               Iterator<Map.Entry<Long, String>> entries = accountEntries.entrySet().iterator();
        //               while (entries.hasNext()) {
        //                  Map.Entry<Long, String> entry = entries.next();
        //                  accountIndexes[i] = entry.getKey();
        //                  accounts[i++] = entry.getValue();
        //               }
        //               mDialog = (new AlertDialog.Builder(this))
        //                     .setTitle(R.string.accounts)
        //                     .setSingleChoiceItems(accounts, -1, new DialogInterface.OnClickListener() {
        //                        @Override
        //                        public void onClick(DialogInterface dialog, int which) {
        //                           selectFriends(accountIndexes[which]);
        //                           dialog.dismiss();
        //                        }
        //                     })
        //                     .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        //                        @Override
        //                        public void onClick(DialogInterface dialog, int which) {
        //                           dialog.dismiss();
        //                        }
        //                     })
        //                     .create();
        //               mDialog.show();
        //            } else
        //               unsupportedToast(sTaggingSupported);
        //         }
    } else if (itemId == R.id.menu_post_location) {
        LocationManager locationManager = (LocationManager) MyfeedleCreatePost.this
                .getSystemService(Context.LOCATION_SERVICE);
        Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        if (location != null) {
            mLat = Double.toString(location.getLatitude());
            mLong = Double.toString(location.getLongitude());
            if (mAccountsService.size() == 1) {
                if (sLocationSupported.contains(mAccountsService.values().iterator().next()))
                    setLocation(mAccountsService.keySet().iterator().next());
                else
                    unsupportedToast(sLocationSupported);
            } else {
                // dialog to select an account
                Iterator<Long> accountIds = mAccountsService.keySet().iterator();
                HashMap<Long, String> accountEntries = new HashMap<Long, String>();
                while (accountIds.hasNext()) {
                    Long accountId = accountIds.next();
                    Cursor account = this.getContentResolver().query(Accounts.getContentUri(this),
                            new String[] { Accounts._ID, ACCOUNTS_QUERY }, Accounts._ID + "=?",
                            new String[] { Long.toString(accountId) }, null);
                    if (account.moveToFirst() && sLocationSupported.contains(mAccountsService.get(accountId)))
                        accountEntries.put(account.getLong(account.getColumnIndex(Accounts._ID)),
                                account.getString(account.getColumnIndex(Accounts.USERNAME)));
                }
                int size = accountEntries.size();
                if (size != 0) {
                    final long[] accountIndexes = new long[size];
                    final String[] accounts = new String[size];
                    int i = 0;
                    Iterator<Map.Entry<Long, String>> entries = accountEntries.entrySet().iterator();
                    while (entries.hasNext()) {
                        Map.Entry<Long, String> entry = entries.next();
                        accountIndexes[i] = entry.getKey();
                        accounts[i++] = entry.getValue();
                    }
                    mDialog = (new AlertDialog.Builder(this)).setTitle(R.string.accounts)
                            .setSingleChoiceItems(accounts, -1, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    setLocation(accountIndexes[which]);
                                    dialog.dismiss();
                                }
                            })
                            .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                }
                            }).create();
                    mDialog.show();
                } else
                    unsupportedToast(sLocationSupported);
            }
        } else
            (Toast.makeText(this, getString(R.string.location_unavailable), Toast.LENGTH_LONG)).show();
    }
    return super.onOptionsItemSelected(item);
}

From source file:gr.scify.newsum.ui.ViewActivity.java

private void Sendmail() {
    TextView title = (TextView) findViewById(R.id.title);
    String emailSubject = title.getText().toString();

    // track the Send mail action
    if (getAnalyticsPref()) {
        EasyTracker.getTracker().sendEvent(SHARING_ACTION, "Send Mail", emailSubject, 0l);
    }/*from w  w w .  j  a va  2 s.  c  o  m*/
    final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.setType("text/html");
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "NewSum app : " + emailSubject);
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(sText));
    startActivity(Intent.createChooser(emailIntent, "Email:"));
}

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

private void startGalleryPicker() {
    Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
    photoPickerIntent.setType("image/*");
    startActivityForResult(photoPickerIntent, RESULT_GALLERY);
}

From source file:com.polyvi.xface.view.XWebViewClient.java

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    try {//www . j  ava2s .  co m
        // ?exec()?.
        if (XNativeToJsMessageQueue.ENABLE_LOCATION_CHANGE_EXEC_MODE && url.startsWith(XFACE_EXEC_URL_PREFIX)) {
            handleExecUrl(url);
        }

        XWhiteList whiteList = mWebAppView.getOwnerApp().getAppInfo().getWhiteList();
        if (url.startsWith("tel") && !XConfiguration.getInstance().isTelLinkEnabled()) {
            return true;
        }
        // TODO:??phonegap?url????
        else if (url.startsWith(XConstant.FILE_SCHEME) || url.startsWith("data:")
                || ((url.startsWith(XConstant.HTTP_SCHEME) || url.startsWith(XConstant.HTTPS_SCHEME))
                        && (null != whiteList && whiteList.isUrlWhiteListed(url)))) {
            /**
             * I9003??url? url???
             */
            return handleUrl(url);
        } else if (url.startsWith(XConstant.SCHEME_SMS)) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            // ??
            String address = null;
            int parmIndex = url.indexOf('?');
            if (-1 == parmIndex) {
                address = url.substring(XConstant.SCHEME_SMS.length());
            } else {
                address = url.substring(XConstant.SCHEME_SMS.length(), parmIndex);
                Uri uri = Uri.parse(url);
                String query = uri.getQuery();
                if (null != query) {
                    if (query.startsWith(SMS_BODY)) {
                        intent.putExtra("sms_body", query.substring(SMS_BODY.length()));
                    }
                }
            }
            intent.setData(Uri.parse(XConstant.SCHEME_SMS + address));
            intent.putExtra("address", address);
            intent.setType("vnd.android-dir/mms-sms");
            mSystemContext.getContext().startActivity(intent);
            return true;
        } else {
            // ?????
            return startSysApplication(url);
        }
    } catch (ActivityNotFoundException e) {
        XLog.e(CLASS_NAME, e.toString());
    }
    return false;
}

From source file:com.juick.android.MessageMenu.java

private void actionShareMessage() {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TEXT, listSelectedItem.toString());
    activity.startActivity(intent);//from   w  w  w  .  j a  v  a  2 s.c  om
}