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.liquid.wallpapers.free.ScroidWallpaperGallery.java

private void handleOnCommunicationChosen(Communication communication) {
    Wallpaper wallpaper = this.selectedWallpaper;

    if (communication.getType().equals(Communication.Type.Email)) {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.putExtra(Intent.EXTRA_EMAIL, new String[] { communication.getValue() });
        intent.putExtra(Intent.EXTRA_SUBJECT, getBaseContext().getString(R.string.applicationName));
        intent.putExtra(Intent.EXTRA_TEXT, String.format(
                getBaseContext().getString(R.string.recommendEmailPattern), wallpaper.getWallpaperUrl()));
        intent.setType(Messages.getString("ScroidWallpaperGallery.0")); //$NON-NLS-1$

        this.startActivity(intent);
    } else if (communication.getType().equals(Communication.Type.Mobile)) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.putExtra(Messages.getString("ScroidWallpaperGallery.1"), communication.getValue()); //$NON-NLS-1$
        intent.putExtra(Messages.getString("ScroidWallpaperGallery.2"), //$NON-NLS-1$
                String.format(getBaseContext().getString(R.string.recommendSmsPattern),
                        wallpaper.getWallpaperUrl()));
        intent.setType(Messages.getString("ScroidWallpaperGallery.3")); //$NON-NLS-1$

        this.startActivity(intent);
    }/*from w w w  .j av a2s. c  om*/
}

From source file:com.ryan.ryanreader.fragments.CommentListingFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {

    final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

    if (info.position <= 0)
        return false;

    final Action action = Action.values()[item.getItemId()];
    final RedditPreparedComment comment = (RedditPreparedComment) lv.getAdapter().getItem(info.position);

    switch (action) {

    case UPVOTE:/* w  w w .  j  a v  a 2s.c om*/
        comment.action(getSupportActivity(), RedditAPI.RedditAction.UPVOTE);
        break;

    case DOWNVOTE:
        comment.action(getSupportActivity(), RedditAPI.RedditAction.DOWNVOTE);
        break;

    case UNVOTE:
        comment.action(getSupportActivity(), RedditAPI.RedditAction.UNVOTE);
        break;

    case REPORT:

        new AlertDialog.Builder(getSupportActivity()).setTitle(R.string.action_report)
                .setMessage(R.string.action_report_sure)
                .setPositiveButton(R.string.action_report, new DialogInterface.OnClickListener() {
                    public void onClick(final DialogInterface dialog, final int which) {
                        comment.action(getSupportActivity(), RedditAPI.RedditAction.REPORT);
                        // TODO update the view to show the result
                    }
                }).setNegativeButton(R.string.dialog_cancel, null).show();

        break;

    case REPLY: {
        final Intent intent = new Intent(getSupportActivity(), CommentReplyActivity.class);
        intent.putExtra("parentIdAndType", comment.idAndType);
        startActivity(intent);
        break;
    }

    case EDIT: {
        final Intent intent = new Intent(getSupportActivity(), CommentEditActivity.class);
        intent.putExtra("commentIdAndType", comment.idAndType);
        intent.putExtra("commentText", comment.src.body);
        startActivity(intent);
        break;
    }

    case COMMENT_LINKS:
        final HashSet<String> linksInComment = comment.computeAllLinks();

        if (linksInComment.isEmpty()) {
            General.quickToast(getSupportActivity(), R.string.error_toast_no_urls_in_comment);

        } else {

            final String[] linksArr = linksInComment.toArray(new String[linksInComment.size()]);

            final AlertDialog.Builder builder = new AlertDialog.Builder(getSupportActivity());
            builder.setItems(linksArr, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    LinkHandler.onLinkClicked(getSupportActivity(), linksArr[which], false);
                    dialog.dismiss();
                }
            });

            final AlertDialog alert = builder.create();
            alert.setTitle(R.string.action_comment_links);
            alert.setCanceledOnTouchOutside(true);
            alert.show();
        }

        break;

    case SHARE:

        final Intent mailer = new Intent(Intent.ACTION_SEND);
        mailer.setType("text/plain");
        mailer.putExtra(Intent.EXTRA_SUBJECT, "Comment by " + comment.src.author + " on Reddit");

        // TODO this currently just dumps the markdown
        mailer.putExtra(Intent.EXTRA_TEXT, StringEscapeUtils.unescapeHtml4(comment.src.body));
        startActivityForResult(Intent.createChooser(mailer, context.getString(R.string.action_share)), 1);

        break;

    case COPY:

        ClipboardManager manager = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
        // TODO this currently just dumps the markdown
        manager.setText(StringEscapeUtils.unescapeHtml4(comment.src.body));
        break;

    case COLLAPSE:
        if (comment.getBoundView() != null)
            handleCommentVisibilityToggle(comment.getBoundView());
        break;

    case USER_PROFILE:
        UserProfileDialog.newInstance(comment.src.author).show(getSupportActivity());
        break;

    case PROPERTIES:
        CommentPropertiesDialog.newInstance(comment.src).show(getSupportActivity());
        break;

    }

    return true;
}

From source file:com.rainmakerlabs.bleepsample.BleepService.java

private Intent createIntent(String intentAction, String intentUri, String intentType, String intentExtras) {
    Intent launchIntent;
    if (intentUri.equalsIgnoreCase("")) {
        launchIntent = getPackageManager().getLaunchIntentForPackage(intentAction);
        launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    } else {//from  w  ww.j ava 2s .  c  om
        launchIntent = new Intent(intentAction, Uri.parse(intentUri));
    }
    if (!intentType.equalsIgnoreCase(""))
        launchIntent.setType(intentType);
    if (!intentExtras.equalsIgnoreCase("")) {
        try {
            JSONObject intentExtrasDict = new JSONObject(intentExtras);
            Iterator<?> keys = intentExtrasDict.keys();
            while (keys.hasNext()) {
                String key = (String) keys.next();
                launchIntent.putExtra(key, intentExtrasDict.get(key).toString());
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    return launchIntent;
}

From source file:fi.mikuz.boarder.gui.DropboxMenu.java

@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_share:
        Thread thread = new Thread() {
            public void run() {
                Looper.prepare();//from  ww  w . j  a v a  2s .c  o  m
                try {
                    final ArrayList<String> boards = mCbla.getAllSelectedTitles();
                    if (!(mOperation == DOWNLOAD_OPERATION)) {
                        mToastMessage = "Select 'Download' mode";
                        mHandler.post(mShowToast);
                    } else if (boards.size() < 1) {
                        mToastMessage = "Select boards to share";
                        mHandler.post(mShowToast);
                    } else {
                        String shareString = "I want to share some cool soundboards to you!\n\n"
                                + "To use the boards you need to have Boarder for Android:\n"
                                + ExternalIntent.mExtLinkMarket + "\n\n" + "Here are the boards:\n";

                        for (String board : boards) {
                            shareString += board + " - " + mApi.createCopyRef("/" + board).copyRef + "\n";
                        }

                        shareString += "\n\n" + "Importing a board:\n" + "1. Open Boarder'\n"
                                + "2. Open Dropbox from menu in 'Soundboard Menu'\n"
                                + "3. Open 'Import share' from menu\n"
                                + "4. Copy a reference from above to textfield\n";

                        Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
                        sharingIntent.setType("text/plain");
                        sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Sharing boards");
                        sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareString);
                        startActivity(Intent.createChooser(sharingIntent, "Share via"));
                    }
                } catch (DropboxException e) {
                    Log.e(TAG, "Unable to share", e);
                }
            }
        };
        thread.start();
        return true;

    case R.id.menu_import_share:
        LayoutInflater removeInflater = (LayoutInflater) DropboxMenu.this
                .getSystemService(LAYOUT_INFLATER_SERVICE);
        View importLayout = removeInflater.inflate(R.layout.dropbox_menu_alert_import_share,
                (ViewGroup) findViewById(R.id.alert_remove_sound_root));

        AlertDialog.Builder importBuilder = new AlertDialog.Builder(DropboxMenu.this);
        importBuilder.setView(importLayout);
        importBuilder.setTitle("Import share");

        final EditText importCodeInput = (EditText) importLayout.findViewById(R.id.importCodeInput);
        final EditText importNameInput = (EditText) importLayout.findViewById(R.id.importNameInput);

        importBuilder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                t = new Thread() {
                    public void run() {
                        Looper.prepare();
                        try {
                            mApi.addFromCopyRef(importCodeInput.getText().toString(),
                                    "/" + importNameInput.getText().toString());
                            mToastMessage = "Download the board from 'Download'";
                            mHandler.post(mShowToast);
                        } catch (DropboxException e) {
                            Log.e(TAG, "Unable to get shared board", e);
                        }
                    }
                };
                t.start();
            }
        });

        importBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
            }
        });
        importBuilder.show();
        return true;
    }

    return super.onMenuItemSelected(featureId, item);
}

From source file:de.ub0r.android.callmeter.ui.prefs.Preferences.java

/**
 * Export data./*from  www.j  a v a 2s .c  o m*/
 * 
 * @param descr
 *            description of the exported rule set
 * @param fn
 *            one of the predefined file names from {@link DataProvider}.
 */
private void exportData(final String descr, final String fn) {
    if (descr == null) {
        final EditText et = new EditText(this);
        Builder builder = new Builder(this);
        builder.setView(et);
        builder.setCancelable(true);
        builder.setTitle(R.string.export_rules_descr);
        builder.setNegativeButton(android.R.string.cancel, null);
        builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
            @Override
            public void onClick(final DialogInterface dialog, final int which) {
                Preferences.this.exportData(et.getText().toString(), fn);
            }
        });
        builder.show();
    } else {
        final ProgressDialog d = new ProgressDialog(this);
        d.setIndeterminate(true);
        d.setMessage(this.getString(R.string.export_progr));
        d.setCancelable(false);
        d.show();

        // run task in background
        final AsyncTask<Void, Void, String> task = // .
                new AsyncTask<Void, Void, String>() {
                    @Override
                    protected String doInBackground(final Void... params) {
                        if (fn.equals(DataProvider.EXPORT_RULESET_FILE)) {
                            return DataProvider.backupRuleSet(Preferences.this, descr);
                        } else if (fn.equals(DataProvider.EXPORT_LOGS_FILE)) {
                            return DataProvider.backupLogs(Preferences.this, descr);
                        } else if (fn.equals(DataProvider.EXPORT_NUMGROUPS_FILE)) {
                            return DataProvider.backupNumGroups(Preferences.this, descr);
                        } else if (fn.equals(DataProvider.EXPORT_HOURGROUPS_FILE)) {
                            return DataProvider.backupHourGroups(Preferences.this, descr);
                        }
                        return null;
                    }

                    @Override
                    protected void onPostExecute(final String result) {
                        Log.d(TAG, "export:\n" + result);
                        System.out.println("\n" + result);
                        d.dismiss();
                        if (result != null && result.length() > 0) {
                            Uri uri = null;
                            int resChooser = -1;
                            if (fn.equals(DataProvider.EXPORT_RULESET_FILE)) {
                                uri = DataProvider.EXPORT_RULESET_URI;
                                resChooser = R.string.export_rules_;
                            } else if (fn.equals(DataProvider.EXPORT_LOGS_FILE)) {
                                uri = DataProvider.EXPORT_LOGS_URI;
                                resChooser = R.string.export_logs_;
                            } else if (fn.equals(DataProvider.EXPORT_NUMGROUPS_FILE)) {
                                uri = DataProvider.EXPORT_NUMGROUPS_URI;
                                resChooser = R.string.export_numgroups_;
                            } else if (fn.equals(DataProvider.EXPORT_HOURGROUPS_FILE)) {
                                uri = DataProvider.EXPORT_HOURGROUPS_URI;
                                resChooser = R.string.export_hourgroups_;
                            }
                            final Intent intent = new Intent(Intent.ACTION_SEND);
                            intent.setType(DataProvider.EXPORT_MIMETYPE);
                            intent.putExtra(Intent.EXTRA_STREAM, uri);
                            intent.putExtra(Intent.EXTRA_SUBJECT, // .
                                    "Call Meter 3G export");
                            intent.addCategory(Intent.CATEGORY_DEFAULT);

                            try {
                                final File d = Environment.getExternalStorageDirectory();
                                final File f = new File(d, DataProvider.PACKAGE + File.separator + fn);
                                f.mkdirs();
                                if (f.exists()) {
                                    f.delete();
                                }
                                f.createNewFile();
                                FileWriter fw = new FileWriter(f);
                                fw.append(result);
                                fw.close();
                                // call an exporting app with the uri to the
                                // preferences
                                Preferences.this.startActivity(
                                        Intent.createChooser(intent, Preferences.this.getString(resChooser)));
                            } catch (IOException e) {
                                Log.e(TAG, "error writing export file", e);
                                Toast.makeText(Preferences.this, R.string.err_export_write, Toast.LENGTH_LONG)
                                        .show();
                            }
                        }
                    }
                };
        task.execute((Void) null);
    }
}

From source file:net.bluecarrot.lite.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    switch (id) {
    case R.id.top: {//scroll on the top of the page
        webViewFacebook.scrollTo(0, 0);//from   www.java 2s .  co m
        break;
    }
    case R.id.openInBrowser: {//open the actual page into using the browser
        webViewFacebook.getContext()
                .startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(webViewFacebook.getUrl())));
        break;
    }
    case R.id.refresh: {//refresh the page
        refreshPage();
        break;
    }
    case R.id.home: {//go to the home
        goHome();
        break;
    }
    case R.id.share: {//share this app
        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        sharingIntent.putExtra(Intent.EXTRA_TEXT, getResources().getString(R.string.downloadThisApp));
        startActivity(Intent.createChooser(sharingIntent, getResources().getString(R.string.share)));

        Toast.makeText(getApplicationContext(), getResources().getString(R.string.thanks), Toast.LENGTH_SHORT)
                .show();
        break;
    }
    case R.id.settings: {//open settings
        startActivity(new Intent(this, ShowSettingsActivity.class));
        return true;
    }

    case R.id.exit: {//open settings
        android.os.Process.killProcess(Process.myPid());
        System.exit(1);
        return true;
    }

    default:
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.sweetiepiggy.raspberrybusmalaysia.SubmitTripActivity.java

private void send_email(String msg) {
    Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    intent.putExtra(Intent.EXTRA_EMAIL, new String[] { EMAIL_ADDRESS });
    intent.putExtra(Intent.EXTRA_SUBJECT, EMAIL_SUBJECT);
    intent.putExtra(Intent.EXTRA_TEXT, msg);
    intent.setType("text/plain");
    startActivity(Intent.createChooser(intent, getResources().getString(R.string.send_email)));
}

From source file:com.zia.freshdocs.widget.CMISAdapter.java

/**
 * Send the content using a built-in Android activity which can handle the content type.
 * @param position//  w  ww .  java  2 s.com
 */
public void shareContent(int position) {
    final NodeRef ref = getItem(position);
    downloadContent(ref, new Handler() {
        public void handleMessage(Message msg) {
            Context context = getContext();
            boolean done = msg.getData().getBoolean("done");

            if (done) {
                dismissProgressDlg();

                File file = (File) _dlThread.getResult();

                if (file != null) {
                    Resources res = context.getResources();
                    Uri uri = Uri.fromFile(file);
                    Intent emailIntent = new Intent(Intent.ACTION_SEND);
                    emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
                    emailIntent.putExtra(Intent.EXTRA_SUBJECT, ref.getName());
                    emailIntent.putExtra(Intent.EXTRA_TEXT, res.getString(R.string.email_text));
                    emailIntent.setType(ref.getContentType());

                    try {
                        context.startActivity(
                                Intent.createChooser(emailIntent, res.getString(R.string.email_title)));
                    } catch (ActivityNotFoundException e) {
                        String text = "No suitable applications registered to send " + ref.getContentType();
                        int duration = Toast.LENGTH_SHORT;
                        Toast toast = Toast.makeText(context, text, duration);
                        toast.show();
                    }
                }
            } else {
                int value = msg.getData().getInt("progress");
                if (value > 0) {
                    _progressDlg.setProgress(value);
                }
            }
        }
    });
}

From source file:com.rsltc.profiledata.main.MainActivity.java

private void exportFile(List<JSONObject> jsonObjects, String dataset_name) {
    final String date = new SimpleDateFormat("yyyyMMdd-HHmmss", Locale.getDefault()).format(new Date());
    final String filename = String.format("%s_%s.txt", dataset_name, date);

    final String directory = Environment.getExternalStorageDirectory().getAbsolutePath() + "/AndroidTesting/";

    final File logfile = new File(directory, filename);
    final File logPath = logfile.getParentFile();

    if (!logPath.isDirectory() && !logPath.mkdirs()) {
        Log.e("SensorDashbaord", "Could not create directory for log files");
    }/*w  ww  .  j a v a2  s. c  o m*/

    try {
        FileWriter filewriter = new FileWriter(logfile);
        BufferedWriter bw = new BufferedWriter(filewriter);

        //            for (JSONObject object : jsonObjects) {
        bw.write(jsonObjects.toString());
        //            }
        bw.flush();
        bw.close();

        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.setType("*/*");

        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, dataset_name + ".csv");
        emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(logfile));
        startActivity(Intent.createChooser(emailIntent, "Send mail..."));

        Log.i(TAG, "export finished!");
    } catch (IOException ioe) {
        Log.e(TAG, "IOException while writing Logfile");
        Log.e("Enias", ioe.getMessage());
    }
}

From source file:com.yi4all.rupics.ImageDetailActivity.java

private Intent createShareIntent() {
    String path = Utils.convertUrl2Path(this, imgList.get(imageSequence).getUrl());
    if (path != null && new File(path).exists()) {
        Intent sendIntent = new Intent(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.sendShareMmsSubject));
        sendIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.sendShareMmsBody));
        sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(path));
        sendIntent.setType("image/*");
        return sendIntent;
    }//from  w  ww  . j a va2  s . c  o  m

    return null;
}