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.conferenceengineer.android.iosched.util.SessionsHelper.java

public void shareSession(Context context, int messageTemplateResId, String title, String hashtags, String url) {
    LOGD("Tracker", "Shared: " + title);
    context.startActivity(Intent.createChooser(createShareIntent(messageTemplateResId, title, hashtags, url),
            context.getString(R.string.title_share)));
}

From source file:id.zelory.tanipedia.activity.BacaActivity.java

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

    tmp = getIntent().getParcelableExtra("berita");

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/* w  ww . j a  v  a  2s. c o  m*/
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
    collapsingToolbar.setTitle("TaniPedia");

    animation = AnimationUtils.loadAnimation(this, R.anim.simple_grow);
    gambar = (ImageView) findViewById(R.id.gambar);
    judul = (TextView) findViewById(R.id.judul);
    tanggal = (TextView) findViewById(R.id.tanggal);
    isi = (DocumentView) findViewById(R.id.isi);
    root = (LinearLayout) findViewById(R.id.ll_root_berita);

    fabButton = (FabButton) findViewById(R.id.determinate);
    fabButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_SUBJECT, berita.getJudul());
            intent.putExtra(Intent.EXTRA_TEXT, berita.getJudul() + "\n" + berita.getAlamat());
            startActivity(Intent.createChooser(intent, "Bagikan"));
        }
    });

    generateBeritaLainnya();

    new DownloadData().execute();
}

From source file:com.bordengrammar.bordengrammarapp.ParentsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_parents, container, false);
    mail = (LinearLayout) root.findViewById(R.id.linmail);
    call = (LinearLayout) root.findViewById(R.id.lincall);
    call.setOnClickListener(new View.OnClickListener() {
        @Override/*from ww w  .  ja v  a  2 s .co m*/
        public void onClick(View arg0) {
            Intent cally = new Intent(Intent.ACTION_CALL);
            cally.setData(Uri.parse("tel:01795424192"));
            startActivity(cally);
        }
    });
    mail.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
            alert.setTitle("Send a email to Borden Grammar");
            alert.setMessage("Message: ");
            final EditText input = new EditText(getActivity());
            alert.setView(input);
            alert.setPositiveButton("Send", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    String value = input.getText().toString();
                    // Do something with value!
                    Intent email = new Intent(Intent.ACTION_SEND);
                    email.setType("plain/text");
                    email.putExtra(android.content.Intent.EXTRA_EMAIL,
                            new String[] { "school@bordengrammar.kent.sch.uk" });
                    email.putExtra(Intent.EXTRA_SUBJECT, "Email (Sent From BGS APP) ");
                    email.putExtra(Intent.EXTRA_TEXT, value);
                    startActivity(Intent.createChooser(email, "Choose an Email client :"));
                }
            });
            alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // Canceled.
                }
            });
            alert.show();
        }

    });

    URL url = null;
    try {
        url = new URL(
                "http://website.bordengrammar.kent.sch.uk/index.php?option=com_rubberdoc&view=category&id=63%3Aletters&Itemid=241&format=feed&type=rss");
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }

    Feed feed = null;
    try {
        feed = FeedParser.parse(url);
    } catch (FeedIOException e) {
        e.printStackTrace();
    } catch (FeedXMLParseException e) {
        e.printStackTrace();
    } catch (UnsupportedFeedException e) {
        e.printStackTrace();
    }
    Boolean nully = false;
    for (int i = 0; i < 3; i++) {
        try {
            FeedItem item = feed.getItem(i);
        } catch (NullPointerException e) {
            e.printStackTrace();
            nully = true;
            Toast.makeText(getActivity().getApplicationContext(),
                    "Some features of this app require a internet connection", Toast.LENGTH_LONG).show();
        }
    }
    if (!nully) {
        final FeedItem post1 = feed.getItem(1);
        final FeedItem post2 = feed.getItem(2);
        final FeedItem post3 = feed.getItem(3);
        TextView title1 = (TextView) root.findViewById(R.id.title1);
        TextView title2 = (TextView) root.findViewById(R.id.title2);
        TextView title3 = (TextView) root.findViewById(R.id.title3);
        title1.setText(post1.getTitle());
        title2.setText(post2.getTitle());
        title3.setText(post3.getTitle());
        TextView link1 = (TextView) root.findViewById(R.id.link1);
        TextView link2 = (TextView) root.findViewById(R.id.link2);
        TextView link3 = (TextView) root.findViewById(R.id.link3);
        link1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String url1 = post1.getLink().toString();
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(Uri.parse(url1), "text/html");
                startActivity(intent);
            }
        });
        link2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String url1 = post2.getLink().toString();
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(Uri.parse(url1), "text/html");
                startActivity(intent);
            }
        });
        link3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String url1 = post3.getLink().toString();
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(Uri.parse(url1), "text/html");
                startActivity(intent);
            }
        });

    } else {
        TextView title1 = (TextView) root.findViewById(R.id.title1);
        TextView title2 = (TextView) root.findViewById(R.id.title2);
        TextView title3 = (TextView) root.findViewById(R.id.title3);
        title1.setText("No connection");
        title2.setText("No connection");
        title3.setText("No connection");
    }
    TextView reader = (TextView) root.findViewById(R.id.reader);
    reader.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final String appPackageName = "com.adobe.reader"; // 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)));
            }
        }
    });

    return root;
}

From source file:com.ideateam.plugin.Emailer.java

private void SendEmail(String email, String subject, String text, String attachFile) {

    String attachPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/UAR2015/" + attachFile;
    File file = new File(attachPath);

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_EMAIL, new String[] { email });
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
    intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(text));

    this.cordova.getActivity().startActivity(Intent.createChooser(intent, "Send email..."));

}

From source file:com.digitalarx.android.files.FileOperationsHelper.java

public void openFile(OCFile file) {
    if (file != null) {
        String storagePath = file.getStoragePath();
        String encodedStoragePath = WebdavUtils.encodePath(storagePath);

        Intent intentForSavedMimeType = new Intent(Intent.ACTION_VIEW);
        intentForSavedMimeType.setDataAndType(Uri.parse("file://" + encodedStoragePath), file.getMimetype());
        intentForSavedMimeType// www .ja  va 2s .c  o  m
                .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);

        Intent intentForGuessedMimeType = null;
        if (storagePath.lastIndexOf('.') >= 0) {
            String guessedMimeType = MimeTypeMap.getSingleton()
                    .getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1));
            if (guessedMimeType != null && !guessedMimeType.equals(file.getMimetype())) {
                intentForGuessedMimeType = new Intent(Intent.ACTION_VIEW);
                intentForGuessedMimeType.setDataAndType(Uri.parse("file://" + encodedStoragePath),
                        guessedMimeType);
                intentForGuessedMimeType.setFlags(
                        Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            }
        }

        Intent chooserIntent = null;
        if (intentForGuessedMimeType != null) {
            chooserIntent = Intent.createChooser(intentForGuessedMimeType,
                    mFileActivity.getString(R.string.actionbar_open_with));
        } else {
            chooserIntent = Intent.createChooser(intentForSavedMimeType,
                    mFileActivity.getString(R.string.actionbar_open_with));
        }

        mFileActivity.startActivity(chooserIntent);

    } else {
        Log_OC.wtf(TAG, "Trying to open a NULL OCFile");
    }
}

From source file:com.activiti.android.app.fragments.task.TaskFormFragment.java

@Subscribe
public void onDownloadTransferEvent(DownloadTransferEvent event) {
    if (event.hasException) {
        Snackbar.make(getActivity().findViewById(R.id.left_panel), event.exception.getMessage(),
                Snackbar.LENGTH_SHORT).show();
        return;/* w ww  .ja  va 2 s  .c  o m*/
    }

    hideWaiting();

    try {
        switch (event.mode) {
        case ContentTransferSyncAdapter.MODE_SHARE:
            Intent sendIntent = new Intent(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_SUBJECT, event.data.getName());
            sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(event.data));
            sendIntent.setType(event.mimetype);
            getActivity().startActivity(
                    Intent.createChooser(sendIntent, getResources().getText(R.string.action_send_file)));
            break;
        case ContentTransferSyncAdapter.MODE_OPEN_IN:
            Intent viewIntent = new Intent(Intent.ACTION_VIEW);
            viewIntent.putExtra(Intent.EXTRA_SUBJECT, event.data.getName());
            viewIntent.setDataAndType(Uri.fromFile(event.data), event.mimetype);
            startActivity(viewIntent);
            break;
        }
    } catch (ActivityNotFoundException e) {
        Snackbar.make(getActivity().findViewById(R.id.left_panel), R.string.file_editor_error_open,
                Snackbar.LENGTH_SHORT).show();
    }
}

From source file:com.accia77.mockey.ui.PickBackgroundImagesActivity.java

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

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // get the large image view
    picView = (ImageView) findViewById(R.id.picture);

    // get the gallery view
    picGallery = (Gallery) findViewById(R.id.gallery);

    // create a new adapter
    imgAdapt = new PicAdapter(this);

    // set the gallery adapter
    picGallery.setAdapter(imgAdapt);//  w  w w .ja  v a2  s. com

    // set long click listener for each gallery thumbnail item
    picGallery.setOnItemLongClickListener(new OnItemLongClickListener() {
        // handle long clicks
        public boolean onItemLongClick(AdapterView<?> parent, View v, int position, long id) {
            // take user to choose an image
            // update the currently selected position so that we assign the
            // imported bitmap to correct item

            // take the user to their chosen image selection app (gallery or
            // file manager)
            Intent pickIntent = new Intent();
            pickIntent.setType("image/*");
            pickIntent.setAction(Intent.ACTION_GET_CONTENT);

            // position's value if the request code for startActivityForResult
            startActivityForResult(Intent.createChooser(pickIntent,
                    getResources().getString(R.string.select_background_image)), position);

            return true;

        }
    });

    // set the click listener for each item in the thumbnail gallery
    picGallery.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            // set the larger image view to display the chosen bitmap
            // calling method of adapter class
            picView.setImageBitmap(imgAdapt.getPic(position));
        }
    });

}

From source file:com.dm.material.dashboard.candybar.helpers.ReportBugsHelper.java

public static void checkForBugs(@NonNull Context context) {
    new AsyncTask<Void, Void, Boolean>() {

        MaterialDialog dialog;//from   w  w w. ja va 2s  . c o m
        StringBuilder sb;
        File folder;
        String file;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            sb = new StringBuilder();
            folder = FileHelper.getCacheDirectory(context);
            file = folder.toString() + "/" + "reportbugs.zip";

            MaterialDialog.Builder builder = new MaterialDialog.Builder(context);
            builder.content(R.string.report_bugs_building).progress(true, 0).progressIndeterminateStyle(true);

            dialog = builder.build();
            dialog.show();
        }

        @Override
        protected Boolean doInBackground(Void... voids) {
            while (!isCancelled()) {
                try {
                    Thread.sleep(1);
                    SparseArrayCompat<String> files = new SparseArrayCompat<>();
                    sb.append(DeviceHelper.getDeviceInfo(context));

                    String brokenAppFilter = buildBrokenAppFilter(context, folder);
                    if (brokenAppFilter != null)
                        files.append(files.size(), brokenAppFilter);

                    String activityList = buildActivityList(context, folder);
                    if (activityList != null)
                        files.append(files.size(), activityList);

                    String stackTrace = Preferences.getPreferences(context).getLatestCrashLog();
                    String crashLog = buildCrashLog(context, folder, stackTrace);
                    if (crashLog != null)
                        files.append(files.size(), crashLog);

                    FileHelper.createZip(files, file);
                    return true;
                } catch (Exception e) {
                    Log.d(Tag.LOG_TAG, Log.getStackTraceString(e));
                    return false;
                }
            }
            return false;
        }

        @Override
        protected void onPostExecute(Boolean aBoolean) {
            super.onPostExecute(aBoolean);
            dialog.dismiss();
            if (aBoolean) {
                File zip = new File(file);

                final Intent intent = new Intent(Intent.ACTION_SEND);
                intent.setType("message/rfc822");
                intent.putExtra(Intent.EXTRA_EMAIL,
                        new String[] { context.getResources().getString(R.string.dev_email) });
                intent.putExtra(Intent.EXTRA_SUBJECT, "Report Bugs " + (context.getString(R.string.app_name)));
                intent.putExtra(Intent.EXTRA_TEXT, sb.toString());
                Uri uri = FileHelper.getUriFromFile(context, context.getPackageName(), zip);
                intent.putExtra(Intent.EXTRA_STREAM, uri);

                context.startActivity(
                        Intent.createChooser(intent, context.getResources().getString(R.string.email_client)));

            } else {
                Toast.makeText(context, R.string.report_bugs_failed, Toast.LENGTH_LONG).show();
            }

            dialog = null;
            sb.setLength(0);
        }
    }.execute();
}

From source file:com.battlelancer.seriesguide.ui.HelpActivity.java

private void sendEmail() {
    Intent intent = new Intent(android.content.Intent.ACTION_SEND);
    intent.setType(HTTP.PLAIN_TEXT_TYPE);
    intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { SeriesGuidePreferences.SUPPORT_MAIL });
    intent.putExtra(android.content.Intent.EXTRA_SUBJECT,
            "SeriesGuide " + Utils.getVersion(this) + " Feedback");
    intent.putExtra(android.content.Intent.EXTRA_TEXT, "");

    Intent chooser = Intent.createChooser(intent, getString(R.string.feedback));
    Utils.tryStartActivity(this, chooser, true);
}

From source file:com.vrem.wifianalyzer.navigation.items.ExportItem.java

Intent createChooserIntent(@NonNull Intent intent, @NonNull String title) {
    return Intent.createChooser(intent, title);
}