Example usage for android.content Intent createChooser

List of usage examples for android.content Intent createChooser

Introduction

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

Prototype

public static Intent createChooser(Intent target, CharSequence title) 

Source Link

Document

Convenience function for creating a #ACTION_CHOOSER Intent.

Usage

From source file:com.zertinteractive.wallpaper.activities.DetailActivity.java

public void setAsWallpaperMore() {

    String path = Environment.getExternalStorageDirectory().toString();
    File file = new File(path, "/" + TEMP_WALLPAPER_DIR + "/" + TEMP_WALLPAPER_NAME + ".png");
    Uri uri = Uri.fromFile(file);//from  ww w  .j  a va2s  . com
    Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setDataAndType(uri, "image/png");
    intent.putExtra("mimeType", "image/png");
    startActivity(Intent.createChooser(intent, "Set as : Mood Wallpaper"));

    //        WallpaperManager myWallpaperManager
    //                = WallpaperManager.getInstance(getApplicationContext());
    //        try {
    //            myWallpaperManager.setBitmap(((BitmapDrawable) imageView.getDrawable()).getBitmap());
    //        } catch (IOException e) {
    //            // TODO Auto-generated catch block
    //            e.printStackTrace();
    //        }
}

From source file:co.taqat.call.ChatFragment.java

private void pickImage() {
    List<Intent> cameraIntents = new ArrayList<Intent>();
    Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File file = new File(Environment.getExternalStorageDirectory(),
            getString(R.string.temp_photo_name_with_date).replace("%s",
                    String.valueOf(System.currentTimeMillis())));
    imageToUploadUri = Uri.fromFile(file);
    captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageToUploadUri);
    cameraIntents.add(captureIntent);/*  w w w  .  jav a 2  s  .  c  o m*/

    Intent galleryIntent = new Intent();
    galleryIntent.setType("image/*");
    galleryIntent.setAction(Intent.ACTION_PICK);

    Intent chooserIntent = Intent.createChooser(galleryIntent, getString(R.string.image_picker_title));
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[] {}));

    startActivityForResult(chooserIntent, ADD_PHOTO);
}

From source file:at.alladin.rmbt.android.adapter.result.RMBTResultPagerAdapter.java

/**
 * // w w  w.  j ava2 s  .  c  om
 */
public void startShareResultsIntent() {
    try {
        JSONObject resultListItem = testResult.getJSONObject(0);
        final String shareText = resultListItem.getString("share_text");
        final String shareSubject = resultListItem.getString("share_subject");

        final Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_TEXT, shareText);
        sendIntent.putExtra(Intent.EXTRA_SUBJECT, shareSubject);
        sendIntent.setType("text/plain");
        activity.startActivity(Intent.createChooser(sendIntent, null));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.dwdesign.tweetings.activity.ComposeActivity.java

@SuppressWarnings("deprecation")
@Override/*from ww w  .  j a  v a2 s  .  co  m*/
public boolean onMenuItemClick(final MenuItem item) {
    switch (item.getItemId()) {
    case MENU_TAKE_PHOTO: {
        if (item.getTitle().equals(getString(R.string.remove_photo))) {
            if (mImageUri == null)
                return false;
            removeAttachments();
        } else {
            takePhoto();
        }
        break;
    }
    case MENU_LAST_PHOTO: {
        String[] projection = new String[] { MediaStore.Images.ImageColumns._ID,
                MediaStore.Images.ImageColumns.DATA, MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME,
                MediaStore.Images.ImageColumns.DATE_TAKEN, MediaStore.Images.ImageColumns.MIME_TYPE };
        final Cursor cursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null, null,
                MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC");
        if (cursor.moveToFirst()) {
            String imageLocation = cursor.getString(1);
            File imageFile = new File(imageLocation);
            if (imageFile != null && imageFile.exists()) { // TODO: is there a better way to do this?
                mImageUri = Uri.fromFile(imageFile);
                mIsPhotoAttached = false;
                mIsImageAttached = true;
                mImageThumbnailPreview.setVisibility(View.VISIBLE);
                reloadAttachedImageThumbnail(imageFile);
            } else {
                mIsImageAttached = false;
            }
            setMenu();
            boolean isAutoUpload = mPreferences.getBoolean(PREFERENCE_KEY_AUTO_UPLOAD, false);
            if (!isNullOrEmpty(mUploadProvider) && mIsImageAttached && isAutoUpload) {
                postMedia();
            }
        }
        break;
    }
    case MENU_ADD_IMAGE: {
        if (item.getTitle().equals(getString(R.string.remove_image))) {
            if (mImageUri == null)
                return false;
            removeAttachments();
        } else {
            pickImage();
        }
        break;
    }
    case MENU_SHORTEN_LINKS: {
        String s = parseString(mEditText.getText());
        new UrlShortenerTask().execute(s);
        break;
    }
    case MENU_ADD_TO_BUFFER: {
        if (mIsBuffer) {
            mIsBuffer = false;
        } else {
            mIsBuffer = true;
        }
        setMenu();
        break;
    }
    case MENU_SCHEDULE_TWEET: {
        if (mScheduleDate != null) {
            mScheduleDate = null;
            setMenu();
        } else {
            Intent intent = new Intent(INTENT_ACTION_SCHEDULE_TWEET);
            if (mScheduleDate != null) {
                Bundle bundle = new Bundle();
                bundle.putString(INTENT_KEY_SCHEDULE_DATE_TIME, mScheduleDate);
                intent.putExtras(bundle);
            }
            startActivityForResult(intent, REQUEST_SCHEDULE_DATE);
        }
        break;
    }
    case MENU_UPLOAD: {
        if (!isNullOrEmpty(mUploadProvider) && mIsImageAttached) {
            postMedia(true);
        }
        break;
    }

    case MENU_ADD_LOCATION: {
        final boolean attach_location = mPreferences.getBoolean(PREFERENCE_KEY_ATTACH_LOCATION, false);
        if (!attach_location) {
            getLocation();
        }
        mPreferences.edit().putBoolean(PREFERENCE_KEY_ATTACH_LOCATION, !attach_location).commit();
        setMenu();
        break;
    }
    case MENU_DRAFTS: {
        startActivity(new Intent(INTENT_ACTION_DRAFTS));
        break;
    }
    case MENU_DELETE: {
        if (mImageUri == null)
            return false;
        removeAttachments();
        break;
    }
    case MENU_EDIT: {
        if (mImageUri == null)
            return false;
        final Intent intent = new Intent(INTENT_ACTION_EXTENSION_EDIT_IMAGE);
        intent.setData(mImageUri);
        startActivityForResult(Intent.createChooser(intent, getString(R.string.open_with_extensions)),
                REQUEST_EDIT_IMAGE);
        // Create the intent needed to start feather
        /*Intent newIntent = new Intent( this, FeatherActivity.class );
        // set the source image uri
        newIntent.setData( mImageUri );
        // pass the required api key ( http://developers.aviary.com/ )
        newIntent.putExtra( "API_KEY", AVIARY_SDK_API_KEY );
        // pass the uri of the destination image file (optional)
        // This will be the same uri you will receive in the onActivityResult
        //newIntent.putExtra( "output", mImageUri);
        // format of the destination image (optional)
        newIntent.putExtra( "output-format", Bitmap.CompressFormat.JPEG.name() );
        // output format quality (optional)
        newIntent.putExtra( "output-quality", 85 );
        // you can force feather to display only a certain tools
        // newIntent.putExtra( "tools-list", new String[]{"ADJUST", "BRIGHTNESS" } );
                
        // enable fast rendering preview
        newIntent.putExtra( "effect-enable-fast-preview", true );
                
        // limit the image size
        // You can pass the current display size as max image size because after
        // the execution of Aviary you can save the HI-RES image so you don't need a big
        // image for the preview
        // newIntent.putExtra( "max-image-size", 800 );
                
        // you want to hide the exit alert dialog shown when back is pressed
        // without saving image first
        // newIntent.putExtra( "hide-exit-unsave-confirmation", true );
                
        // ..and start feather
        startActivityForResult( newIntent, ACTION_REQUEST_FEATHER );*/
        break;
    }
    case MENU_VIEW: {
        openImage(this, mImageUri, false);
        break;
    }
    case MENU_TOGGLE_SENSITIVE: {
        final boolean has_media = (mIsImageAttached || mIsPhotoAttached) && mImageUri != null;
        if (!has_media)
            return false;
        mIsPossiblySensitive = !mIsPossiblySensitive;
        setMenu();
        break;
    }
    }
    return true;
}

From source file:com.transistorsoft.cordova.bggeo.CDVBackgroundGeolocation.java

private void emailLog(final CallbackContext callback, final String email) {
    cordova.getThreadPool().execute(new Runnable() {
        public void run() {
            String log = readLog();
            if (log == null) {
                callback.error(500);//from  ww  w. ja  v a 2 s .c  o  m
                return;
            }

            Intent mailer = new Intent(Intent.ACTION_SEND);
            mailer.setType("message/rfc822");
            mailer.putExtra(Intent.EXTRA_EMAIL, new String[] { email });
            mailer.putExtra(Intent.EXTRA_SUBJECT, "BackgroundGeolocation log");

            try {
                JSONObject state = getState();
                if (state.has("license")) {
                    state.put("license", "<SECRET>");
                }
                if (state.has("orderId")) {
                    state.put("orderId", "<SECRET>");
                }
                mailer.putExtra(Intent.EXTRA_TEXT, state.toString(4));
            } catch (JSONException e) {
                Log.w(TAG, "- Failed to write state to email body");
                e.printStackTrace();
            }
            File file = new File(Environment.getExternalStorageDirectory(), "background-geolocation.log");
            try {
                FileOutputStream stream = new FileOutputStream(file);
                try {
                    stream.write(log.getBytes());
                    stream.close();
                    mailer.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
                    file.deleteOnExit();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } catch (FileNotFoundException e) {
                Log.i(TAG, "FileNotFound");
                e.printStackTrace();
            }

            try {
                cordova.getActivity()
                        .startActivityForResult(Intent.createChooser(mailer, "Send log: " + email + "..."), 1);
                callback.success();
            } catch (android.content.ActivityNotFoundException ex) {
                Toast.makeText(cordova.getActivity(), "There are no email clients installed.",
                        Toast.LENGTH_SHORT).show();
                callback.error("There are no email clients installed");
            }
        }
    });
}

From source file:com.justone.android.main.MainActivity.java

public void shareOnClick(View view) {
    String shareTitle = "";
    String shareContent = "    ";
    if (tabs.getCurrentTabTag() == "home tab") {
        shareTitle = "home tab";
        shareContent = shareContent + ((TextView) this.findViewById(R.id.fPage_tView)).getText().toString()
                + ((TextView) this.findViewById(R.id.imageBelow_tView)).getText().toString()
                + "()  " + ((TextView) this.findViewById(R.id.home_share_url)).getText().toString();
    } else if (tabs.getCurrentTabTag() == "QA Tab") {
        shareTitle = "QA Tab";
        shareContent = shareContent + ((TextView) this.findViewById(R.id.question_content)).getText().toString()
                + " -  ()  "
                + ((TextView) this.findViewById(R.id.qa_share_url)).getText().toString();

    } else if (tabs.getCurrentTabTag() == "list tab") {
        shareTitle = "list tab";
        shareContent = shareContent + ""
                + ((TextView) this.findViewById(R.id.one_content_title)).getText().toString() + " by "
                + ((TextView) this.findViewById(R.id.one_content_author)).getText().toString()
                + "- ()  "
                + ((TextView) this.findViewById(R.id.list_share_url)).getText().toString();

    }//from   www.j a  v a 2 s.  c  om

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    // intent.setPackage("com.sina.weibo");
    intent.putExtra(Intent.EXTRA_SUBJECT, "");
    //intent.putExtra(Intent.EXTRA_TEXT, shareTitle+"   VOL.516   () http://caodan.org/516-photo.html ");
    intent.putExtra(Intent.EXTRA_TEXT, shareContent);
    intent.putExtra(Intent.EXTRA_TITLE, shareTitle);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(Intent.createChooser(intent, ""));
}

From source file:com.android.music.TrackBrowserFragment.java

void doSearch() {
    CharSequence title = null;/*ww w.  ja  va  2  s. c  o  m*/
    String query = null;

    Intent i = new Intent();
    i.setAction(MediaStore.INTENT_ACTION_MEDIA_SEARCH);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    title = mCurrentTrackName;
    if (MediaStore.UNKNOWN_STRING.equals(mCurrentArtistNameForAlbum)) {
        query = mCurrentTrackName;
    } else {
        query = mCurrentArtistNameForAlbum + " " + mCurrentTrackName;
        i.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, mCurrentArtistNameForAlbum);
    }
    if (MediaStore.UNKNOWN_STRING.equals(mCurrentAlbumName)) {
        i.putExtra(MediaStore.EXTRA_MEDIA_ALBUM, mCurrentAlbumName);
    }
    i.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, "audio/*");
    title = getString(R.string.mediasearch, title);
    i.putExtra(SearchManager.QUERY, query);

    startActivity(Intent.createChooser(i, title));

}

From source file:com.cypress.cysmart.CommonFragments.ProfileScanningFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    // Handle action bar item clicks here.
    switch (item.getItemId()) {
    case R.id.log:
        // DataLogger
        File file = new File(Environment.getExternalStorageDirectory() + File.separator + "CySmart"
                + File.separator + Utils.GetDate() + ".txt");
        String path = file.getAbsolutePath();
        Bundle bundle = new Bundle();
        bundle.putString(Constants.DATA_LOGGER_FILE_NAAME, path);
        bundle.putBoolean(Constants.DATA_LOGGER_FLAG, false);
        /**//from w w w  .  j  a  v  a 2s.c o m
         * Adding new fragment DataLoggerFragment to the view
         */
        FragmentManager fragmentManager = getFragmentManager();
        Fragment currentFragment = fragmentManager.findFragmentById(R.id.container);
        DataLoggerFragment dataloggerfragment = new DataLoggerFragment().create(currentFragment.getTag());
        dataloggerfragment.setArguments(bundle);
        fragmentManager.beginTransaction().add(R.id.container, dataloggerfragment).addToBackStack(null)
                .commit();
        return true;
    case R.id.share:
        // Share
        HomePageActivity.containerView.invalidate();
        View v1 = getActivity().getWindow().getDecorView().getRootView();
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        String temporaryPath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator
                + "CySmart" + File.separator + "file.jpg";
        File filetoshare = new File(temporaryPath);
        if (filetoshare.exists()) {
            filetoshare.delete();
        }
        try {
            filetoshare.createNewFile();
            Utils.screenShotMethod(v1);
            Logger.i("temporaryPath>" + temporaryPath);
            shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(temporaryPath)));
            shareIntent.setType("image/jpg");
            startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));
        } catch (IOException e) {
            e.printStackTrace();
        }

        return true;
    case R.id.clearcache:
        showWarningMessage();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:ca.uwaterloo.magic.goodhikes.MapsActivity.java

public void CaptureMapScreen() {
    GoogleMap.SnapshotReadyCallback callback = new GoogleMap.SnapshotReadyCallback() {
        Bitmap bitmap;//from w w w . j  a  va2  s  .  com

        @Override
        public void onSnapshotReady(Bitmap snapshot) {
            // TODO Auto-generated method stub
            bitmap = snapshot;
            String path = MediaStore.Images.Media.insertImage(getContentResolver(), bitmap, "route_screenshot",
                    null);
            Uri uri_image = Uri.parse(path);

            // share intent
            Intent sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_STREAM, uri_image);
            sendIntent.putExtra(Intent.EXTRA_TEXT, "My Route");
            sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Hey! Check out my route on Goodhikes");
            sendIntent.setType("image/*");
            startActivity(Intent.createChooser(sendIntent, "Share to..."));

        }
    };

    mMap.snapshot(callback);

}

From source file:cliq.com.cliqgram.fragments.CameraFragment.java

@Override
public void onClick(View view) {
    switch (view.getId()) {
    case R.id.button_capture:
        takePicture();//from www.ja  v  a2s.c o m
        break;
    case R.id.button_flash:
        if (flashOn) {
            flashOn = false;
            ImageUtil.loadResToView(getActivity(), R.drawable.icon_flash_off, buttonFlash, 0.7f);
        } else {
            flashOn = true;
            ImageUtil.loadResToView(getActivity(), R.drawable.icon_flash_on, buttonFlash, 0.7f);
        }
        break;
    case R.id.button_grid:
        // TODO
        if (gridOn) {
            gridOn = false;
            myGridView.setVisibility(View.INVISIBLE);
            ImageUtil.loadResToView(getActivity(), R.drawable.icon_grid_off, buttonGrid, 0.7f);
        } else {
            gridOn = true;
            myGridView.setVisibility(View.VISIBLE);
            ImageUtil.loadResToView(getActivity(), R.drawable.icon_grid_on, buttonGrid, 0.7f);
        }
        break;
    case R.id.button_gallery:

        Intent intent = new Intent();
        // Show only images, no videos or anything else
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        // Always show the chooser (if there are multiple options available)
        startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);

        break;
    }
}