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.fsa.en.dron.activity.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    RateThisApp.Config config = new RateThisApp.Config(5, 10);
    config.setTitle(R.string.my_own_title);
    config.setMessage(R.string.my_own_message);
    config.setYesButtonText(R.string.my_own_rate);
    config.setNoButtonText(R.string.my_own_thanks);
    config.setCancelButtonText(R.string.my_own_cancel);
    RateThisApp.init(config);/*from w ww  .j a v a2s .  c  om*/
    RateThisApp.setCallback(new RateThisApp.Callback() {
        @Override
        public void onYesClicked() {
            final String appPackageName = getPackageName(); // getPackageName() from Context or Activity  object
            try {
                startActivity(
                        new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
            } catch (android.content.ActivityNotFoundException anfe) {
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName)));
            }
        }

        @Override
        public void onNoClicked() {
            TastyToast.makeText(getApplicationContext(), "Vuelve pronto!", TastyToast.LENGTH_LONG,
                    TastyToast.INFO);
        }

        @Override
        public void onCancelClicked() {
            TastyToast.makeText(getApplicationContext(), "Prometo tomar mejores fotografias!",
                    TastyToast.LENGTH_LONG, TastyToast.ERROR);
        }
    });
    button = (Button) findViewById(R.id.button);
    button.setVisibility(View.INVISIBLE);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            checkConnection();
        }
    });
    BottomNavigationBar bottomNavigationBar = (BottomNavigationBar) findViewById(R.id.bottom_navigation_bar);
    bottomNavigationBar.setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_RIPPLE);
    bottomNavigationBar.setMode(BottomNavigationBar.MODE_FIXED);
    bottomNavigationBar.setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_STATIC);
    bottomNavigationBar.setBarBackgroundColor(R.color.material_light_blue_800);
    bottomNavigationBar.setActiveColor(R.color.material_grey_900);
    bottomNavigationBar.setInActiveColor(R.color.material_blue_grey_200);
    bottomNavigationBar.addItem(new BottomNavigationItem(R.drawable.compose, "Mensaje"))
            .addItem(new BottomNavigationItem(R.drawable.sociales, "Sociales"))
            .addItem(new BottomNavigationItem(R.drawable.share, "Cuntale a un amigo")).initialise();
    bottomNavigationBar.setTabSelectedListener(new BottomNavigationBar.OnTabSelectedListener() {
        @Override
        public void onTabSelected(int position) {
            switch (position) {
            case 0:
                Intent email = new Intent(Intent.ACTION_SEND);
                email.putExtra(Intent.EXTRA_EMAIL, new String[] { "marceloespinoza00@gmail.com" });
                email.putExtra(Intent.EXTRA_SUBJECT, "Formosa en dron");
                email.putExtra(Intent.EXTRA_TEXT, "Dej tu mensaje");
                email.setType("message/rfc822");
                startActivity(Intent.createChooser(email, "Elige un cliente :"));
                break;
            case 1:
                Intent intent = new Intent(getApplication(), FacebookActivity.class);
                startActivity(intent);
                break;
            case 2:

                Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
                sharingIntent.setType("text/plain");
                sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Formosa en dron");
                sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT,
                        "https://play.google.com/store/apps/details?id=com.fsa.en.dron");
                startActivity(Intent.createChooser(sharingIntent, "Compartir via"));
                break;

            }

        }

        @Override
        public void onTabUnselected(int position) {

        }

        @Override
        public void onTabReselected(int position) {
            switch (position) {
            case 0:

                break;
            case 1:
                Intent intent = new Intent(getApplication(), FacebookActivity.class);
                startActivity(intent);
                break;
            case 2:

                break;

            }
        }
    });
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    LayoutInflater inflator = LayoutInflater.from(this);
    View v = inflator.inflate(R.layout.toolbar_title, null);
    Typeface budget = Typeface.createFromAsset(getAssets(), "fonts/Budget.otf");
    Typeface typographica = Typeface.createFromAsset(getAssets(), "fonts/TypoGraphica.otf");
    TextView mToolbarCustomTitle = (TextView) v.findViewById(R.id.title);
    TextView mToolbarCustomSubTitle = (TextView) v.findViewById(R.id.subtitle);
    mToolbarCustomTitle.setText("Formosa");
    mToolbarCustomSubTitle.setText("en dron");
    mToolbarCustomTitle.setTypeface(typographica);
    mToolbarCustomSubTitle.setTypeface(budget);
    getSupportActionBar().setCustomView(v);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setDisplayShowCustomEnabled(true);
    toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            int id = item.getItemId();
            if (id == R.id.recargar) {
                checkConnection();
            }
            if (id == R.id.info) {
                showDialog();
            }
            return false;
        }
    });
    recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    recyclerView.addOnItemTouchListener(new GalleryAdapter.RecyclerTouchListener(getApplicationContext(),
            recyclerView, new GalleryAdapter.ClickListener() {
                @Override
                public void onClick(View view, int position) {
                    Bundle bundle = new Bundle();
                    bundle.putSerializable("images", images);
                    bundle.putInt("position", position);

                    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
                    SlideshowDialogFragment newFragment = SlideshowDialogFragment.newInstance();
                    newFragment.setArguments(bundle);
                    newFragment.show(ft, "slideshow");
                }

                @Override
                public void onLongClick(View view, int position) {

                }
            }));
    pDialog = new ProgressDialog(this);
    images = new ArrayList<>();
    mAdapter = new GalleryAdapter(getApplicationContext(), images);
    RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(getApplicationContext(), 2);
    recyclerView.setLayoutManager(mLayoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setAdapter(mAdapter);

}

From source file:com.chale22.ico01.fragments.FragmentTheme.java

private void applyAdwExTheme() {
    try {/*ww  w  .j a  v a 2  s. c o  m*/
        Intent adwexlauncherIntent = new Intent("org.adw.launcher.SET_THEME");
        adwexlauncherIntent.putExtra("org.adw.launcher.theme.NAME", getActivity().getPackageName());
        startActivity(Intent.createChooser(adwexlauncherIntent, "ADW Not Installed"));
    } catch (ActivityNotFoundException e5) {
        e5.printStackTrace();
        makeToast("ADW EX is not installed!");
        applyAdwTheme();
    }
    //finish();
}

From source file:com.google.android.apps.muzei.featuredart.FeaturedArtSource.java

@Override
protected void onCustomCommand(int id) {
    super.onCustomCommand(id);
    if (COMMAND_ID_SHARE == id) {
        Artwork currentArtwork = getCurrentArtwork();
        if (currentArtwork == null) {
            LOGW(TAG, "No current artwork, can't share.");
            new Handler(Looper.getMainLooper()).post(new Runnable() {
                @Override//from w  ww.j  a  v  a 2s . c o m
                public void run() {
                    Toast.makeText(FeaturedArtSource.this,
                            R.string.featuredart_source_error_no_artwork_to_share, Toast.LENGTH_SHORT).show();
                }
            });
            return;
        }

        String detailUrl = ("initial".equals(currentArtwork.getToken()))
                ? "http://www.wikipaintings.org/en/vincent-van-gogh/the-starry-night-1889"
                : currentArtwork.getViewIntent().getDataString();
        String artist = currentArtwork.getByline().replaceFirst("\\.\\s*($|\\n).*", "").trim();

        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.setType("text/plain");
        shareIntent.putExtra(Intent.EXTRA_TEXT, "My Android wallpaper today is '"
                + currentArtwork.getTitle().trim() + "' by " + artist + ". #MuzeiFeaturedArt\n\n" + detailUrl);
        shareIntent = Intent.createChooser(shareIntent, "Share artwork");
        shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(shareIntent);

    } else if (COMMAND_ID_DEBUG_INFO == id) {
        long nextUpdateTimeMillis = getSharedPreferences().getLong("scheduled_update_time_millis", 0);
        final String nextUpdateTime;
        if (nextUpdateTimeMillis > 0) {
            Date d = new Date(nextUpdateTimeMillis);
            nextUpdateTime = SimpleDateFormat.getDateTimeInstance().format(d);
        } else {
            nextUpdateTime = "None";
        }

        new Handler(Looper.getMainLooper()).post(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(FeaturedArtSource.this, "Next update time: " + nextUpdateTime, Toast.LENGTH_LONG)
                        .show();
            }
        });
    }
}

From source file:com.davidmiguel.gobees.apiaries.ApiariesActivity.java

/**
 * Opens share app option./*w w  w .j  a  v  a 2  s  .c  o m*/
 */
private void openShareApp() {
    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT,
            getString(R.string.share_app_text) + Uri.parse(getString(R.string.share_app_url)));
    sendIntent.setType("text/plain");
    startActivity(Intent.createChooser(sendIntent, getString(R.string.share_app_title)));
}

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

@Override
public boolean onMenuItemClick(final MenuItem item) {
    if (mSelectedUser == null)
        return false;
    switch (item.getItemId()) {
    case MENU_DELETE: {
        mService.deleteUserListMember(getAccountId(), mUserListId, mSelectedUser.user_id);
        break;/*from   ww  w.  j  av  a 2s  .  c o  m*/
    }
    case MENU_VIEW_PROFILE: {
        openUserProfile(mSelectedUser.user_id, mSelectedUser.screen_name);
        break;
    }
    case MENU_EXTENSIONS: {
        final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER);
        final Bundle extras = new Bundle();
        extras.putParcelable(INTENT_KEY_USER, mSelectedUser);
        intent.putExtras(extras);
        startActivity(Intent.createChooser(intent, getString(R.string.open_with_extensions)));
        break;
    }
    }
    return false;
}

From source file:com.phonegap.CameraLauncher.java

/**
 * Get image from photo library./*from  w ww  . ja  v a 2  s. co  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. 
 */
// TODO: Images selected from SDCARD don't display correctly, but from CAMERA ALBUM do!
public void getImage(int quality, int srcType, int returnType) {
    this.mQuality = quality;

    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    this.ctx.startActivityForResult((Plugin) this, Intent.createChooser(intent, new String("Get Picture")),
            (srcType + 1) * 16 + returnType + 1);
}

From source file:com.poinsart.votar.VotarMain.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    System.loadLibrary("VotAR");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    assetMgr = this.getAssets();

    imageView = (ImageView) findViewById(R.id.imageView);
    bar[0] = (ProgressBar) findViewById(R.id.bar_a);
    bar[1] = (ProgressBar) findViewById(R.id.bar_b);
    bar[2] = (ProgressBar) findViewById(R.id.bar_c);
    bar[3] = (ProgressBar) findViewById(R.id.bar_d);

    barLabel[0] = (TextView) findViewById(R.id.label_a);
    barLabel[1] = (TextView) findViewById(R.id.label_b);
    barLabel[2] = (TextView) findViewById(R.id.label_c);
    barLabel[3] = (TextView) findViewById(R.id.label_d);

    wifiLabel = (TextView) findViewById(R.id.label_wifi);

    mainLayout = ((LinearLayout) findViewById(R.id.mainLayout));
    controlLayout = ((LinearLayout) findViewById(R.id.controlLayout));
    imageLayout = ((LinearLayout) findViewById(R.id.imageLayout));

    adjustLayoutForOrientation(getResources().getConfiguration().orientation);

    findViewById(R.id.buttonCamera).setOnClickListener(new View.OnClickListener() {
        @Override// w w  w .ja  v a  2  s  .c o  m
        public void onClick(View v) {
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

            cameraFileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image
            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, cameraFileUri); // set the image file name

            startActivityForResult(cameraIntent, CAMERA_REQUEST);
        }
    });
    findViewById(R.id.buttonGallery).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent, "Select Picture"), GALLERY_REQUEST);
        }
    });
    votarwebserver = new VotarWebServer(51285, this);
    try {
        votarwebserver.start();
    } catch (IOException e) {
        Log.w("Votar MainAct", "The webserver could not be started, remote display wont be available");
    }
}

From source file:com.codebutler.farebot.fragments.CardsFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    try {/*from  ww  w  .j a va 2  s .  c  o  m*/
        if (item.getItemId() == R.id.import_clipboard) {
            @SuppressWarnings("deprecation")
            ClipboardManager clipboard = (ClipboardManager) getActivity()
                    .getSystemService(Activity.CLIPBOARD_SERVICE);
            onCardsImported(ExportHelper.importCardsXml(getActivity(), clipboard.getText().toString()));
            return true;

        } else if (item.getItemId() == R.id.import_file) {
            Uri uri = Uri.fromFile(Environment.getExternalStorageDirectory());
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);
            i.putExtra(Intent.EXTRA_STREAM, uri);
            i.setType("application/xml");
            startActivityForResult(Intent.createChooser(i, "Select File"), REQUEST_SELECT_FILE);
            return true;

        } else if (item.getItemId() == R.id.import_sd) {
            String xml = FileUtils.readFileToString(new File(SD_EXPORT_PATH));
            onCardsImported(ExportHelper.importCardsXml(getActivity(), xml));
            return true;

        } else if (item.getItemId() == R.id.copy_xml) {
            @SuppressWarnings("deprecation")
            ClipboardManager clipboard = (ClipboardManager) getActivity()
                    .getSystemService(Activity.CLIPBOARD_SERVICE);
            clipboard.setText(ExportHelper.exportCardsXml(getActivity()));
            Toast.makeText(getActivity(), "Copied to clipboard.", 5).show();
            return true;

        } else if (item.getItemId() == R.id.share_xml) {
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, ExportHelper.exportCardsXml(getActivity()));
            startActivity(intent);
            return true;

        } else if (item.getItemId() == R.id.save_xml) {
            String xml = ExportHelper.exportCardsXml(getActivity());
            File file = new File(SD_EXPORT_PATH);
            FileUtils.writeStringToFile(file, xml, "UTF-8");
            Toast.makeText(getActivity(), "Wrote FareBot-Export.xml to USB Storage.", 5).show();
            return true;
        }
    } catch (Exception ex) {
        Utils.showError(getActivity(), ex);
    }
    return false;
}

From source file:com.crimsonrgames.titanium.htmltester.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mSourceCode = readHTMLFromDefaultFile();
    if (mEditorFragment == null) {
        mEditorFragment = EditorFragment.newInstance(mSourceCode);
    }//from  ww w.java 2 s. c o  m
    if (mPreviewFragment == null) {
        mPreviewFragment = PreviewFragment.newInstance(mSourceCode);
    }
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            mEditorFragment = ((EditorFragment) mSectionsPagerAdapter.getRegisteredFragment(0));
            if (mEditorFragment == null)
                return;
            mSourceCode = mEditorFragment.getmSourceCode();
            mPreviewFragment = ((PreviewFragment) mSectionsPagerAdapter.getRegisteredFragment(1));
            if (mPreviewFragment == null)
                return;
            mPreviewFragment.setmSourceCode(mSourceCode);

        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mEditorFragment = ((EditorFragment) mSectionsPagerAdapter.getRegisteredFragment(0));
            Intent sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_TEXT, mEditorFragment.getmSourceCode());
            sendIntent.setType("text/html");
            startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));
        }
    });

}

From source file:com.abhijitvalluri.android.fitnotifications.HomeFragment.java

private void initializeButtons() {
    initializeServiceButtons();/*from   w  ww  .  j ava 2  s . c  o m*/
    initializeDemoButton();
    initializeEnableNotificationButton();

    mImproveTransliterationTV.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String uriText = "mailto:android@abhijitvalluri.com" + "?subject="
                    + Uri.encode("Improve Transliterations for <SPECIFY_LANGUAGE>") + "&body="
                    + Uri.encode("<MESSAGE>");

            Uri uri = Uri.parse(uriText);

            Intent sendIntent = new Intent(Intent.ACTION_SENDTO);
            sendIntent.setData(uri);
            startActivity(Intent.createChooser(sendIntent, "Send email"));
        }
    });

    mRateAppTV.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Uri uri = Uri.parse("market://details?id=" + Constants.PACKAGE_NAME);
            Intent gotoPlayStore = new Intent(Intent.ACTION_VIEW, uri);
            // To count with Play market backstack, After pressing back button,
            // to taken back to our application, we need to add following flags to intent.
            gotoPlayStore.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
            try {
                startActivity(gotoPlayStore);
            } catch (ActivityNotFoundException e) {
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("http://play.google.com/store/apps/details?id=" + Constants.PACKAGE_NAME)));
            }
        }
    });
}