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:net.networksaremadeofstring.rhybudd.ViewZenossEvent.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home: {
        finish();// w ww.  j  ava 2s.c o m
        return true;
    }

    case R.id.AddLog: {
        addMessageDialog = new Dialog(ViewZenossEvent.this);
        addMessageDialog.setContentView(R.layout.add_message);
        addMessageDialog.setTitle("Add Message to Event Log");
        ((Button) addMessageDialog.findViewById(R.id.SaveButton)).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                AddLogMessage(((EditText) addMessageDialog.findViewById(R.id.LogMessage)).getText().toString());
                addMessageDialog.dismiss();
            }
        });

        addMessageDialog.show();
        return true;
    }

    case R.id.escalate: {
        Intent intent = new Intent(android.content.Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);

        // Add data to the intent, the receiving app will decide what to do with it.
        intent.putExtra(Intent.EXTRA_SUBJECT,
                "Escalation of Zenoss Event on " + getIntent().getStringExtra("Device"));
        String EventDetails = getIntent().getStringExtra("Summary") + "\r\r\n"
                + getIntent().getStringExtra("LastTime") + "\r\r\n" + "Count: "
                + getIntent().getIntExtra("Count", 0);

        intent.putExtra(Intent.EXTRA_TEXT, EventDetails);

        startActivity(Intent.createChooser(intent, "How would you like to escalate this event?"));
    }

    default: {
        return false;
    }
    }
}

From source file:ca.rmen.android.networkmonitor.app.about.AboutActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        NavUtils.navigateUpFromSameTask(this);
        return true;
    case R.id.action_send_logs:
        new AsyncTask<Void, Void, Boolean>() {

            @Override/*from ww w .j a v  a2s .co  m*/
            protected Boolean doInBackground(Void... params) {
                if (!Log.prepareLogFile()) {
                    return false;
                }
                // Bring up the chooser to share the file.
                Intent sendIntent = new Intent();
                sendIntent.setAction(Intent.ACTION_SEND);
                //sendIntent.setData(Uri.fromParts("mailto", getString(R.string.send_logs_to), null));
                sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.support_send_debug_logs_subject));
                String messageBody = getString(R.string.support_send_debug_logs_body);
                File f = new File(getExternalFilesDir(null), Log.FILE);
                sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + f.getAbsolutePath()));
                sendIntent.setType("message/rfc822");
                sendIntent.putExtra(Intent.EXTRA_TEXT, messageBody);
                sendIntent.putExtra(Intent.EXTRA_EMAIL,
                        new String[] { getString(R.string.support_send_debug_logs_to) });
                startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.action_share)));
                return true;
            }

            @Override
            protected void onPostExecute(Boolean result) {
                if (!result)
                    Toast.makeText(AboutActivity.this, R.string.support_error, Toast.LENGTH_LONG).show();
            }

        }.execute();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:de.appplant.cordova.plugin.emailcomposer.EmailComposer.java

/**
 * Zeigt den ViewController zum Versenden/Bearbeiten der Mail an.
 *///from   w ww .  j  a  va  2 s.  c  o  m
private void openDraft(final Intent draft) {
    final EmailComposer plugin = this;

    cordova.getThreadPool().execute(new Runnable() {
        public void run() {
            cordova.startActivityForResult(plugin, Intent.createChooser(draft, "Select Email App"), 0);
        }
    });
}

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

@Override
public void onClick(final View view) {
    final Uri uri = getIntent().getData();
    switch (view.getId()) {
    case R.id.close: {
        onBackPressed();/*from  ww  w  .  j  a v a 2s  . c om*/
        break;
    }
    case R.id.refresh_stop_save: {
        if (!mImageLoaded && !mImageLoading) {
            loadImage();
        } else if (!mImageLoaded && mImageLoading) {
            stopLoading();
        } else if (mImageLoaded) {
            saveImage();
        }
        break;
    }
    case R.id.share: {
        if (uri == null) {
            break;
        }
        final Intent intent = new Intent(Intent.ACTION_SEND);
        final String scheme = uri.getScheme();
        if ("file".equals(scheme)) {
            intent.setType("image/*");
            intent.putExtra(Intent.EXTRA_STREAM, uri);
        } else {
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, uri.toString());
        }
        startActivity(Intent.createChooser(intent, getString(R.string.share)));
        break;
    }
    case R.id.open_in_browser: {
        if (uri == null) {
            break;
        }
        final String scheme = uri.getScheme();
        if ("http".equals(scheme) || "https".equals(scheme)) {
            final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            try {
                startActivity(intent);
            } catch (final ActivityNotFoundException e) {
                // Ignore.
            }
        }
        break;
    }
    }
}

From source file:de.appplant.cordova.emailcomposer.EmailComposer.java

/**
 * Sends an intent to the email app./*from   w w  w  . ja  va2s. c o m*/
 *
 * @param args
 * The email properties like subject or body
 * @throws JSONException
 */
private void open(JSONArray args) throws JSONException {
    JSONObject props = args.getJSONObject(0);
    String appId = props.getString("app");

    if (!(impl.canSendMail(appId, getContext()))[0]) {
        LOG.i("EmailComposer", "Cannot send mail. No client or account found for.");
        return;
    }

    Intent draft = impl.getDraftWithProperties(props, getContext());
    String header = props.optString("chooserHeader", "Open with");

    final Intent chooser = Intent.createChooser(draft, header);
    final EmailComposer plugin = this;

    cordova.getThreadPool().execute(new Runnable() {
        public void run() {
            cordova.startActivityForResult(plugin, chooser, 0);
        }
    });
}

From source file:at.bitfire.davdroid.ui.DebugInfoActivity.java

public void onShare(MenuItem item) {
    if (!TextUtils.isEmpty(report)) {
        Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.setType("text/plain");
        sendIntent.putExtra(Intent.EXTRA_SUBJECT,
                getString(R.string.app_name) + " " + BuildConfig.VERSION_NAME + " debug info");

        // since Android 4.1, FileProvider permissions are handled in a useful way (using ClipData)
        boolean asAttachment = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;

        if (asAttachment)
            try {
                File debugInfoDir = new File(getCacheDir(), "debug-info");
                debugInfoDir.mkdir();/* w  w w  .jav a 2 s  .c  o m*/

                reportFile = new File(debugInfoDir, "debug.txt");
                App.log.fine("Writing debug info to " + reportFile.getAbsolutePath());
                FileWriter writer = new FileWriter(reportFile);
                writer.write(report);
                writer.close();

                sendIntent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(this,
                        getString(R.string.authority_log_provider), reportFile));
                sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

            } catch (IOException e) {
                // creating an attachment failed, so send it inline
                asAttachment = false;

                StringBuilder builder = new StringBuilder();
                builder.append("Couldn't write debug info file:\n").append(ExceptionUtils.getStackTrace(e))
                        .append("\n\n").append(report);
                report = builder.toString();
            }

        if (!asAttachment)
            sendIntent.putExtra(Intent.EXTRA_TEXT, report);

        startActivity(Intent.createChooser(sendIntent, null));
    }
}

From source file:br.com.PartoHumanizado.fragment.EnviarPlanoDePartoFragment.java

@OnClick(R.id.enviar)
public void enviar() {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("message/rfc822");
    //        intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_EMAIL, "");
    intent.putExtra(Intent.EXTRA_SUBJECT, "Plano de Parto");
    intent.putExtra(Intent.EXTRA_TEXT, texto.getText().toString());

    startActivity(Intent.createChooser(intent, "Enviar email"));
    //        startActivity(intent);
}

From source file:edu.mit.mobile.android.livingpostcards.data.Card.java

/**
 * Creates an {@link Intent#ACTION_SEND} intent to share the given card.
 *
 * @param context/* w  w  w  . j a  va2s. com*/
 * @param webUrl
 *            the content of the card's {@link Card#COL_WEB_URL} field. Can be a relative URL.
 * @param title
 *            the title of the card
 * @return an intent, within a chooser, that can be used with
 *         {@link Context#startActivity(Intent)}
 */
public static Intent createShareIntent(Context context, String webUrl, CharSequence title) {
    final NetworkClient nc = LocastApplication.getNetworkClient(context,
            Authenticator.getFirstAccount(context));
    final Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.setType("text/plain");
    sendIntent.putExtra(Intent.EXTRA_TEXT,
            context.getString(R.string.send_intent_message, nc.getFullUrlAsString(webUrl)));
    sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.send_intent_subject, title));
    return Intent.createChooser(sendIntent, context.getString(R.string.send_intent_chooser_title));

}

From source file:org.ueu.uninet.it.IragarkiaBidali.java

/**
 * Prestatu iragarki berria bidaltzeko formularioa
 *///  w  w  w.j ava2 s .  c  om
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.iragarkia_bidali);

    this.ekintza = this;
    this.izena = (EditText) findViewById(R.id.editTextIzena);
    this.izenburua = (EditText) findViewById(R.id.editTextIzenburua);
    this.eposta = (EditText) findViewById(R.id.editTextEposta);
    this.telefonoa = (EditText) findViewById(R.id.editTextTelefonoa);
    this.mezua = (EditText) findViewById(R.id.editTextDeskribapena);
    this.ohar_legala = (CheckBox) findViewById(R.id.checkBoxlegalAdviceBidali);
    this.errobota = (EditText) findViewById(R.id.editTextErrobota);

    this.atala = (Spinner) findViewById(R.id.spinnerAtala);
    imgView = (ImageView) findViewById(R.id.ImageView);
    upload = (Button) findViewById(R.id.Upload);
    bidali = (Button) findViewById(R.id.iragarkiaBidali);

    // Iragarkiak irudirik badu galeriatik kargatu
    upload.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Toast.makeText(getApplicationContext(), "Aukeratu irudi bat.", Toast.LENGTH_SHORT).show();
            try {
                Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(Intent.createChooser(intent, "Irudia aukeratu"), PICK_IMAGE);
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
            }
        }
    });

    // Formularioa bidali
    bidali.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            if (balidatu()) {
                dialog = ProgressDialog.show(IragarkiaBidali.this, "Fitxategia igotzen eta mezua bidaltzen",
                        "Itxaron mesedez...", true);
                //Formularioa eta irudia bidali
                new ImageUploadTask().execute();
            }

        }
    });

    ArrayAdapter<String> iragarki_motak = new ArrayAdapter<String>(this, R.layout.spinner_view,
            getResources().getStringArray(R.array.iragarki_kategoriak));
    iragarki_motak.setDropDownViewResource(R.layout.spinner_view_dropdown);
    this.atala.setAdapter(iragarki_motak);

    // Sareko monitora prestatu
    NetworkConnectivity.sharedNetworkConnectivity().configure(this);
    NetworkConnectivity.sharedNetworkConnectivity().addNetworkMonitorListener(this);
    NetworkConnectivity.sharedNetworkConnectivity().startNetworkMonitor();

}

From source file:org.mrquiz.android.tinyurl.SendTinyUrlActivity.java

private void send() {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");

    Intent originalIntent = getIntent();
    if (Intent.ACTION_SEND.equals(originalIntent.getAction())) {
        // Copy extras from the original intent because they miht contain
        // additional information about the URL (e.g., the title of a
        // YouTube video). Do this before setting Intent.EXTRA_TEXT to avoid
        // overwriting the TinyShare.
        intent.putExtras(originalIntent.getExtras());
    }/*from  ww w.  j a  v a  2  s  .c  o  m*/

    intent.putExtra(Intent.EXTRA_TEXT, mTinyUrl);
    try {
        CharSequence template = getText(R.string.title_send);
        String title = String.format(String.valueOf(template), mTinyUrl);
        startActivity(Intent.createChooser(intent, title));
    } catch (ActivityNotFoundException e) {
        handleError(e);
    }
}