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.hybris.mobile.activity.AbstractProductDetailActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    boolean handled = super.onOptionsItemSelected(item);
    if (!handled) {
        // Put custom menu items handlers here
        switch (item.getItemId()) {

        // NFC writing is for debug use only 
        case R.id.write_tag:
            if (NFCUtil.canNFC(this)) {
                Intent writeIntent = new Intent(this, NFCWriteActivity.class);
                NdefMessage msg = getNDEF(mProduct.getCode());
                writeIntent.putExtra(NFCWriteActivity.NDEF_MESSAGE, msg);
                startActivity(writeIntent);
            } else {
                Toast.makeText(this, R.string.error_nfc_not_supported, Toast.LENGTH_LONG).show();
            }//from   w  w w .  ja  v  a 2  s  .  c om
            return true;
        case R.id.share:

            try {
                Intent sendIntent = new Intent();
                sendIntent.setAction(Intent.ACTION_SEND);
                sendIntent.putExtra(Intent.EXTRA_TEXT, mProduct.getName() + " - "
                        + getString(R.string.nfc_url, URLEncoder.encode(mProduct.getCode(), "UTF-8")));
                sendIntent.setType("text/plain");
                startActivity(Intent.createChooser(sendIntent, getString(R.string.share_dialog_title)));
            } catch (UnsupportedEncodingException e) {
                LoggingUtils.e(LOG_TAG,
                        "Error trying to encode product code to UTF-8. " + e.getLocalizedMessage(),
                        Hybris.getAppContext());
            }

            return true;
        default:
            return false;
        }
    }
    return handled;
}

From source file:eu.thecoder4.gpl.pleftdroid.EventDetailActivity.java

public void addToCalendar(int i) {
    ADate ad = adates.get(i);//from   w  w  w  .j  a va  2 s . c  o m
    String pd = ad.getD();
    String dpart = pd.substring(0, pd.indexOf('T'));
    String tpart = pd.substring(pd.indexOf('T') + 1);
    SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Calendar cal = Calendar.getInstance();
    Date d = null;
    try {
        d = sdf.parse(dpart + " " + tpart);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    cal.setTime(d);

    Intent intent = new Intent(Intent.ACTION_EDIT);
    intent.setType("vnd.android.cursor.item/event");
    intent.putExtra("beginTime", cal.getTimeInMillis());
    intent.putExtra("endTime", cal.getTimeInMillis() + 60 * 60 * 1000);
    intent.putExtra("title", adesc);
    startActivity(intent);
}

From source file:org.sogrey.frame.utils.FileUtil.java

/**
 * app//from  w  ww  . j  a  v  a2s. c o m
 *
 * @param context
 *
 * @author Sogrey
 * @date 2015-11-27?1:56:55
 */
public static void openFolder(Context context, String path) {
    // Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    // Uri uri = Uri.parse(path);
    // intent.setDataAndType(uri, "text/csv");
    // try {
    // context.startActivity(Intent.createChooser(intent, "Open folder"));
    // } catch (Exception e) {
    // }

    // File root = new File(path);
    // Uri uri = Uri.fromFile(root);
    // Intent intent = new Intent();
    // intent.setAction(android.content.Intent.ACTION_VIEW);
    // intent.setData(uri);
    // context.startActivity(intent);

    // Intent intent = new Intent();
    // String videoPath = path;// 
    // File file = new File(videoPath);
    // Uri uri = Uri.fromFile(file);
    // intent.setData(uri);
    // intent.setAction(android.content.Intent.ACTION_VIEW);// "com.xxx.xxx"
    // ???
    // try {
    // context.startActivity(intent);
    // } catch (ActivityNotFoundException e) {
    // e.printStackTrace();
    // }

    // Intent i = new Intent(Intent.ACTION_GET_CONTENT);
    // // i.setAction(android.content.Intent.ACTION_VIEW);
    // File file = new File(path);
    // i.setDataAndType(Uri.fromFile(file), "file/*");
    // try {
    // context.startActivity(i);
    // } catch (Exception e) {
    // }

    // Intent intent = new Intent();
    // File file = new File(path);
    // intent.setAction(android.content.Intent.ACTION_VIEW);
    // // intent.setData(Uri.fromFile(file));
    // intent.setDataAndType(Uri.fromFile(file), "file/*");
    // try {
    // context.startActivity(intent);
    // } catch (Exception e) {
    // }

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    // intent.setType("*/*");
    intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
    File file = new File(path);
    intent.setData(Uri.fromFile(file));
    // intent.setDataAndType(Uri.fromFile(file), "*/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    try {
        context.startActivity(intent);
    } catch (ActivityNotFoundException ex) {
        ToastUtil.showToast(context, "?");
    }

}

From source file:com.abc.driver.PersonalActivity.java

private void doCrop() {
    Log.d(TAG, "doCrop()");
    final ArrayList<CropOption> cropOptions = new ArrayList<CropOption>();

    Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setType("image/*");

    List<ResolveInfo> list = this.getPackageManager().queryIntentActivities(intent, 0);

    int size = list.size();

    if (size == 0) {
        Log.d(TAG, " Crop activity is not found.  List size is zero.");
        Bitmap tmpBmp = BitmapFactory.decodeFile(imageUri.getPath(), null);
        app.setPortaritBitmap(Bitmap.createScaledBitmap(tmpBmp, CellSiteConstants.IMAGE_WIDTH,
                CellSiteConstants.IMAGE_HEIGHT, false));

        mUserPortraitIv.setImageBitmap(app.getPortaritBitmap());
        isPortraitChanged = true;/*  w ww .  ja v  a 2s.c om*/

        Log.d(TAG, "set bitmap");

        return;
    } else {
        Log.d(TAG, "found the crop activity.");
        intent.setData(imageUri);

        intent.putExtra("outputX", CellSiteConstants.IMAGE_WIDTH);
        intent.putExtra("outputY", CellSiteConstants.IMAGE_HEIGHT);
        intent.putExtra("aspectX", 1);
        intent.putExtra("aspectY", 1);
        intent.putExtra("scale", true);
        intent.putExtra("return-data", true);

        if (size == 1) {
            Log.d(TAG, "Just one as choose it as crop activity.");
            Intent i = new Intent(intent);
            ResolveInfo res = list.get(0);
            i.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));

            startActivityForResult(i, CellSiteConstants.CROP_PICTURE);
        } else {
            Log.d(TAG, "More that one activity for crop  is found . will chooose one");
            for (ResolveInfo res : list) {
                final CropOption co = new CropOption();

                co.title = getPackageManager().getApplicationLabel(res.activityInfo.applicationInfo);
                co.icon = getPackageManager().getApplicationIcon(res.activityInfo.applicationInfo);
                co.appIntent = new Intent(intent);

                co.appIntent
                        .setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));

                cropOptions.add(co);
            }

            CropOptionAdapter adapter = new CropOptionAdapter(getApplicationContext(), cropOptions);

            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Choose Crop App");

            builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    startActivityForResult(cropOptions.get(item).appIntent, CellSiteConstants.CROP_PICTURE);
                }
            });

            builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
                // @Override
                public void onCancel(DialogInterface dialog) {
                    if (imageUri != null) {
                        getContentResolver().delete(imageUri, null, null);
                        imageUri = null;
                        isPortraitChanged = false;
                    }
                }
            });
            AlertDialog alert = builder.create();

            alert.show();
        }
    }
}

From source file:net.kourlas.voipms_sms.activities.ConversationActivity.java

@Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
    if (menuItem.getItemId() == R.id.resend_button) {
        for (int i = 0; i < adapter.getItemCount(); i++) {
            if (adapter.isItemChecked(i)) {
                sendMessage(adapter.getItem(i).getDatabaseId());
                break;
            }/*  w ww  .j  a  v a 2 s  .c o m*/
        }

        actionMode.finish();
        return true;
    } else if (menuItem.getItemId() == R.id.info_button) {
        Message message = null;
        for (int i = 0; i < adapter.getItemCount(); i++) {
            if (adapter.isItemChecked(i)) {
                message = adapter.getItem(i);
                break;
            }
        }

        if (message != null) {
            DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
            String dialogText;
            if (message.getType() == Message.Type.INCOMING) {
                dialogText = (message.getVoipId() == null ? ""
                        : (getString(R.string.conversation_info_id) + " " + message.getVoipId() + "\n"))
                        + getString(R.string.conversation_info_to) + " "
                        + Utils.getFormattedPhoneNumber(message.getDid()) + "\n"
                        + getString(R.string.conversation_info_from) + " "
                        + Utils.getFormattedPhoneNumber(message.getContact()) + "\n"
                        + getString(R.string.conversation_info_date) + " "
                        + dateFormat.format(message.getDate());
            } else {
                dialogText = (message.getVoipId() == null ? ""
                        : (getString(R.string.conversation_info_id) + " " + message.getVoipId() + "\n"))
                        + getString(R.string.conversation_info_to) + " "
                        + Utils.getFormattedPhoneNumber(message.getContact()) + "\n"
                        + getString(R.string.conversation_info_from) + " "
                        + Utils.getFormattedPhoneNumber(message.getDid()) + "\n"
                        + getString(R.string.conversation_info_date) + " "
                        + dateFormat.format(message.getDate());
            }
            Utils.showAlertDialog(this, getString(R.string.conversation_info_title), dialogText,
                    getString(R.string.ok), null, null, null);
        }

        actionMode.finish();
        return true;
    } else if (menuItem.getItemId() == R.id.copy_button) {
        Message message = null;
        for (int i = 0; i < adapter.getItemCount(); i++) {
            if (adapter.isItemChecked(i)) {
                message = adapter.getItem(i);
                break;
            }
        }

        if (message != null) {
            ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("Text message", message.getText());
            clipboard.setPrimaryClip(clip);
        }

        actionMode.finish();
        return true;
    } else if (menuItem.getItemId() == R.id.share_button) {
        Message message = null;
        for (int i = 0; i < adapter.getItemCount(); i++) {
            if (adapter.isItemChecked(i)) {
                message = adapter.getItem(i);
                break;
            }
        }

        if (message != null) {
            Intent intent = new Intent(android.content.Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putExtra(android.content.Intent.EXTRA_TEXT, message.getText());
            startActivity(Intent.createChooser(intent, null));
        }

        actionMode.finish();
        return true;
    } else if (menuItem.getItemId() == R.id.delete_button) {
        List<Long> databaseIds = new ArrayList<>();
        for (int i = 0; i < adapter.getItemCount(); i++) {
            if (adapter.isItemChecked(i)) {
                databaseIds.add(adapter.getItem(i).getDatabaseId());
            }
        }

        Long[] databaseIdsArray = new Long[databaseIds.size()];
        databaseIds.toArray(databaseIdsArray);
        deleteMessages(databaseIdsArray);

        actionMode.finish();
        return true;
    } else {
        return false;
    }
}

From source file:com.anyonavinfo.commonuserregister.MainActivity.java

/**
 * // ww w.ja va2 s  . c  om
 */
private void onOpenImage() {
    /***
     * androidintent? ??
     */
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(intent, 3);
}

From source file:no.nordicsemi.android.nrftoolbox.dfu.DfuActivity.java

/**
 * Called when Select File was pressed//from  w ww  .jav a  2 s. c  o  m
 * 
 * @param view
 *            a button that was pressed
 */
public void onSelectFileClicked(final View view) {
    final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("application/octet-stream");
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    if (intent.resolveActivity(getPackageManager()) != null) {
        // file browser has been found on the device
        startActivityForResult(intent, SELECT_FILE_REQ);
    } else {
        // there is no any file browser app, let's try to download one
        final View customView = getLayoutInflater().inflate(R.layout.app_file_browser, null);
        final ListView appsList = (ListView) customView.findViewById(android.R.id.list);
        appsList.setAdapter(new FileBrowserAppsAdapter(this));
        appsList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        appsList.setItemChecked(0, true);
        new AlertDialog.Builder(this).setTitle(R.string.dfu_alert_no_filebrowser_title).setView(customView)
                .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                        dialog.dismiss();
                    }
                }).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                        final int pos = appsList.getCheckedItemPosition();
                        if (pos >= 0) {
                            final String query = getResources()
                                    .getStringArray(R.array.dfu_app_file_browser_action)[pos];
                            final Intent storeIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(query));
                            startActivity(storeIntent);
                        }
                    }
                }).show();
    }
}

From source file:com.fvd.nimbus.MainActivity.java

public void onButtonClick(View v) {
    switch (v.getId()) {
    case R.id.bTakePhoto:
        showProgress(true);/*www .j  a  va 2 s .c om*/
        getPhoto();
        break;
    case R.id.bFromGallery:
        try {
            showProgress(true);
            Intent fileChooserIntent = new Intent();
            fileChooserIntent.addCategory(Intent.CATEGORY_OPENABLE);
            fileChooserIntent.setType("image/*");
            fileChooserIntent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(fileChooserIntent, "Select Picture"), TAKE_PICTURE);
        } catch (Exception e) {
            appSettings.appendLog("main:onClick  " + e.getMessage());
            showProgress(false);
        }
        break;
    case R.id.bWebClipper:
        Intent iBrowse = new Intent();
        iBrowse.setClassName("com.fvd.nimbus", "com.fvd.nimbus.BrowseActivity");
        startActivity(iBrowse);
        //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );
        overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out);
        break;
    case R.id.bPdfAnnotate:
        Intent ip = new Intent();
        ip.setClassName("com.fvd.nimbus", "com.fvd.nimbus.ChoosePDFActivity");
        startActivity(ip);
        //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );
        overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out);
        break;
    case R.id.ibSettings:
        Intent inten = new Intent(getApplicationContext(), SettingsActivity.class);
        startActivityForResult(inten, SHOW_SETTINGS);
        //overridePendingTransition(R.anim.carbon_slide_in,R.anim.carbon_slide_out);
        overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out);
        break;
    /*case R.id.bssSettings:
       Intent i = new Intent(getApplicationContext(), PrefsActivity.class);
        startActivity(i);
        overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );
       break;
    case R.id.bssRegister:
       Intent intent = new Intent(getApplicationContext(), RegisterDlg.class);
       intent.putExtra("userMail", userMail==null?"":userMail);
       startActivityForResult(intent, 5);
       overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );
       break;   
    case R.id.bssHelp:
       Uri uri = Uri.parse("http://help.everhelper.me/customer/portal/articles/1376820-nimbus-clipper-for-android---quick-guide");
       Intent it = new Intent(Intent.ACTION_VIEW, uri);
       startActivity(it);
       overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );
       break;
    case R.id.bssLogin:
       if(serverHelper.getInstance().getSession().length() == 0) showLogin();
       else {
     String sessionId="";
     serverHelper.getInstance().setSessionId(sessionId);
     appSettings.storeUserData(this, userMail, "", "");
     Editor e = prefs.edit();
     e.putString("userMail", userMail);
       e.putString("userPass", "");
       e.putString("sessionId", sessionId);
       e.commit();
     showLogin();
     }
       break;
    case R.id.bssRateUs:
       try{
       startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getApplicationInfo().packageName)));
    }
    catch(Exception e){
    }
       break;*/
    }
}

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

@Override
public boolean onMenuItemClick(final MenuItem item) {
    final ParcelableStatus status = mSelectedStatus;
    if (status == null)
        return false;
    final long account_id = getDefaultAccountId(mApplication);
    switch (item.getItemId()) {
    case MENU_VIEW: {
        openStatus(getActivity(), status);
        break;/*from   w ww. j  av a  2  s. com*/
    }
    case MENU_SHARE: {
        final Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT, "@" + status.screen_name + ": " + status.text_plain);
        startActivity(Intent.createChooser(intent, getString(R.string.share)));
        break;
    }
    case MENU_TRANSLATE: {
        translate(status);
        break;
    }
    case MENU_RETWEET: {
        if (isMyRetweet(status)) {
            mService.destroyStatus(status.account_id, status.status_id);
        } else {
            final long id_to_retweet = mSelectedStatus.is_retweet && mSelectedStatus.retweet_id > 0
                    ? mSelectedStatus.retweet_id
                    : mSelectedStatus.status_id;
            mService.retweetStatus(status.account_id, id_to_retweet);
        }
        break;
    }
    case MENU_QUOTE: {
        final Intent intent = new Intent(INTENT_ACTION_COMPOSE);
        final Bundle bundle = new Bundle();
        bundle.putLong(INTENT_KEY_ACCOUNT_ID, status.account_id);
        bundle.putBoolean(INTENT_KEY_IS_QUOTE, true);
        bundle.putString(INTENT_KEY_TEXT, getQuoteStatus(getActivity(), status.screen_name, status.text_plain));
        intent.putExtras(bundle);
        startActivity(intent);
        break;
    }
    case MENU_QUOTE_REPLY: {
        final Intent intent = new Intent(INTENT_ACTION_COMPOSE);
        final Bundle bundle = new Bundle();
        bundle.putLong(INTENT_KEY_ACCOUNT_ID, status.account_id);
        bundle.putLong(INTENT_KEY_IN_REPLY_TO_ID, status.status_id);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_SCREEN_NAME, status.screen_name);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_NAME, status.name);
        bundle.putBoolean(INTENT_KEY_IS_QUOTE, true);
        bundle.putString(INTENT_KEY_TEXT, getQuoteStatus(getActivity(), status.screen_name, status.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, status.account_id);
        bundle.putBoolean(INTENT_KEY_IS_BUFFER, true);
        bundle.putString(INTENT_KEY_TEXT, getQuoteStatus(getActivity(), status.screen_name, status.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(status.text_plain);
        mentions.remove(status.screen_name);
        mentions.add(0, status.screen_name);
        bundle.putStringArray(INTENT_KEY_MENTIONS, mentions.toArray(new String[mentions.size()]));
        bundle.putLong(INTENT_KEY_ACCOUNT_ID, status.account_id);
        bundle.putLong(INTENT_KEY_IN_REPLY_TO_ID, status.status_id);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_TWEET, status.text_plain);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_SCREEN_NAME, status.screen_name);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_NAME, status.name);
        intent.putExtras(bundle);
        startActivity(intent);
        break;
    }
    case MENU_FAV: {
        if (mSelectedStatus.is_favorite) {
            mService.destroyFavorite(status.account_id, status.status_id);
        } else {
            mService.createFavorite(status.account_id, status.status_id);
        }
        break;
    }
    case MENU_CONVERSATION: {
        openConversation(getActivity(), status.account_id, status.status_id);
        break;
    }
    case MENU_DELETE: {
        mService.destroyStatus(status.account_id, status.status_id);
        break;
    }
    case MENU_EXTENSIONS: {
        final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_STATUS);
        final Bundle extras = new Bundle();
        extras.putParcelable(INTENT_KEY_STATUS, status);
        intent.putExtras(extras);
        startActivity(Intent.createChooser(intent, getString(R.string.open_with_extensions)));
        break;
    }
    case MENU_MULTI_SELECT: {
        if (!mApplication.isMultiSelectActive()) {
            mApplication.startMultiSelect();
        }
        final NoDuplicatesLinkedList<Object> list = mApplication.getSelectedItems();
        if (!list.contains(status)) {
            list.add(status);
        }
        break;
    }
    case MENU_BLOCK: {
        mService.createBlock(account_id, status.user_id);
        break;
    }
    case MENU_REPORT_SPAM: {
        mService.reportSpam(account_id, status.user_id);
        break;
    }
    case MENU_MUTE_USER: {
        final String screen_name = status.screen_name;
        final Uri uri = Filters.Users.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.Users.TEXT, screen_name);
        resolver.delete(uri, Filters.Users.TEXT + " = '" + screen_name + "'", null);
        resolver.insert(uri, values);
        editor.putBoolean(PREFERENCE_KEY_ENABLE_FILTER, true).commit();
        Toast.makeText(getActivity(), R.string.user_muted, Toast.LENGTH_SHORT).show();
        break;
    }
    case MENU_MAKE_GAP: {
        Uri uri = Statuses.CONTENT_URI;
        final Uri query_uri = buildQueryUri(uri, false);
        ContentResolver mResolver = getContentResolver();
        final ContentValues values = new ContentValues();
        values.put(Statuses.IS_GAP, 1);
        final StringBuilder where = new StringBuilder();
        where.append(Statuses.ACCOUNT_ID + "=" + account_id);
        where.append(" AND " + Statuses.STATUS_ID + "=" + status.status_id);
        mResolver.update(query_uri, values, where.toString(), null);
        getActivity().sendBroadcast(new Intent(BROADCAST_FILTERS_UPDATED).putExtra(INTENT_KEY_SUCCEED, true));
        break;
    }
    case MENU_COPY: {
        final CharSequence text = Html.fromHtml(status.text_html);
        if (ClipboardUtils.setText(getActivity(), text)) {
            Toast.makeText(getActivity(), R.string.text_copied, Toast.LENGTH_SHORT).show();
        }
        break;
    }
    }
    return true;
}

From source file:com.example.zf_android.activity.MerchantEdit.java

private void show2Dialog(int type) {

    AlertDialog.Builder builder = new AlertDialog.Builder(MerchantEdit.this);
    final String[] items = getResources().getStringArray(R.array.apply_detail_upload);

    MerchantEdit.this.type = type;

    builder.setItems(items, new DialogInterface.OnClickListener() {
        @Override//from   ww  w.j  a va  2  s . c o m
        public void onClick(DialogInterface dialog, int which) {
            switch (which) {

            case 0: {

                Intent intent;
                if (Build.VERSION.SDK_INT < 19) {
                    intent = new Intent(Intent.ACTION_GET_CONTENT);
                    intent.setType("image/*");
                } else {
                    intent = new Intent(Intent.ACTION_PICK,
                            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                }
                startActivityForResult(intent, REQUEST_UPLOAD_IMAGE);
                break;
            }
            case 1: {
                String state = Environment.getExternalStorageState();
                if (state.equals(Environment.MEDIA_MOUNTED)) {
                    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    File outDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
                    if (!outDir.exists()) {
                        outDir.mkdirs();
                    }
                    File outFile = new File(outDir, System.currentTimeMillis() + ".jpg");
                    photoPath = outFile.getAbsolutePath();
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(outFile));
                    intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
                    startActivityForResult(intent, REQUEST_TAKE_PHOTO);
                } else {
                    CommonUtil.toastShort(MerchantEdit.this, getString(R.string.toast_no_sdcard));
                }
                break;
            }
            }
        }
    });

    builder.show();
}