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.buddi.client.dfu.DfuActivity.java

private void openFileChooser() {
    final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType(mFileTypeTmp == DfuService.TYPE_AUTO ? DfuService.MIME_TYPE_ZIP : DfuService.MIME_TYPE_HEX);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    if (intent.resolveActivity(getPackageManager()) != null) {
        // file browser has been found on the device
        startActivityForResult(intent, SELECT_FILE_REQ);
    } else {/*w w w  . ja v  a 2 s . c  o  m*/
        // there is no any file browser app, let's try to download one
        final View customView = getLayoutInflater().inflate(R.layout.app_file_browser, null);
        final ListView appsList = (ListView) customView.findViewById(android.R.id.list);
        appsList.setAdapter(new FileBrowserAppsAdapter(this));
        appsList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        appsList.setItemChecked(0, true);
        new AlertDialog.Builder(this).setTitle(R.string.dfu_alert_no_filebrowser_title).setView(customView)
                .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                        dialog.dismiss();
                    }
                }).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                        final int pos = appsList.getCheckedItemPosition();
                        if (pos >= 0) {
                            final String query = getResources()
                                    .getStringArray(R.array.dfu_app_file_browser_action)[pos];
                            final Intent storeIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(query));
                            startActivity(storeIntent);
                        }
                    }
                }).show();
    }
}

From source file:com.sim2dial.dialer.ChatFragment.java

private void pickImage() {
    final List<Intent> cameraIntents = new ArrayList<Intent>();
    final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File file = new File(Environment.getExternalStorageDirectory(), getString(R.string.temp_photo_name));
    imageToUploadUri = Uri.fromFile(file);
    captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageToUploadUri);
    cameraIntents.add(captureIntent);/* w ww .j  a v  a  2  s  .com*/

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

    final 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:net.bytten.comicviewer.ComicViewerActivity.java

public void shareComicLink() {
    Intent intent = new Intent(Intent.ACTION_SEND, null);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TEXT, getCurrentComicUrl());
    startActivity(Intent.createChooser(intent, "Share Link..."));
}

From source file:org.openintents.updatechecker.UpdateChecker.java

public void parseVeeCheck(String uri) {
    VeecheckResult result = null;/*from w w w .ja v  a  2  s  . co  m*/
    try {
        VeecheckVersion version = new VeecheckVersion(mPackageName, String.valueOf(mCurrentVersion),
                mCurrentVersionName);
        try {
            result = performRequest(version, uri);
        } catch (Exception e) {
            Log.v(LOG_TAG, "Failed to process versions.", e);
            return;
        } finally {
        }

        if (result.matched) {
            Log.d(LOG_TAG, "Matching intent found.");
            if (result.latestVersion.getVersionCode() != null) {
                try {
                    mLatestVersion = Integer.parseInt(result.latestVersion.getVersionCode());
                } catch (NumberFormatException e) {
                    mLatestVersion = 0;
                }
            } else {
                mLatestVersion = 0;
            }
            mLatestVersionName = result.latestVersion.getVersionName();
            mComment = null;

            // create intent
            Intent intent = new Intent();
            if (Intent.ACTION_VIEW.equals(result.action)) {
                intent.setAction(result.action);
                if (result.data != null) {
                    Uri intentUri = Uri.parse(result.data);
                    if (result.type != null) {
                        intent.setDataAndType(intentUri, result.type);
                    } else {
                        intent.setData(intentUri);
                    }
                } else {
                    if (result.type != null) {
                        intent.setType(result.type);
                    }
                }

                if (result.extras != null) {
                    for (Entry<String, String> e : result.extras.entrySet()) {
                        intent.putExtra(e.getKey(), e.getValue());
                    }
                }
                ResolveInfo info = mContext.getPackageManager().resolveActivity(intent, 0);
                if (info != null) {
                    mUpdateIntent = intent;
                }
            } else {
                Log.v(TAG, "no view action but " + result.action);
            }

        } else {
            result = null;
            Log.d(LOG_TAG, "No matching intent found.");
        }

    } finally {

    }
}

From source file:eu.intermodalics.tango_ros_streamer.activities.RunningActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.settings:
        if (mParameterNode != null) {
            try {
                mParameterNode.setPreferencesFromParameterServer();
            } catch (RuntimeException e) {
                e.printStackTrace();/*from   w  w w  . j  av a  2 s  . c o m*/
            }
        }
        Intent settingsActivityIntent = new Intent(this, SettingsActivity.class);
        settingsActivityIntent.putExtra(getString(R.string.uuids_names_map), mUuidsNamesHashMap);
        startActivityForResult(settingsActivityIntent, StartSettingsActivityRequest.STANDARD_RUN);
        return true;
    case R.id.share:
        mLogger.saveLogToFile();
        Intent shareFileIntent = new Intent(Intent.ACTION_SEND);
        shareFileIntent.setType("text/plain");
        shareFileIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(mLogger.getLogFile()));
        startActivity(shareFileIntent);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:key.secretkey.crypto.PgpHandler.java

public void shareAsPlaintext() {

    if (findViewById(R.id.share_password_as_plaintext) == null)
        return;//from   w  w  w .ja va2  s  .  co  m

    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT, decodedPassword);
    sendIntent.setType("text/plain");
    startActivity(
            Intent.createChooser(sendIntent, getResources().getText(R.string.send_plaintext_password_to)));//Always show a picker to give the user a chance to cancel
}

From source file:com.logilite.vision.camera.CameraLauncher.java

/**
 * Get image from photo library.//from  www . j a  v  a 2s  . 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 srcType, int returnType) {
    Intent intent = new Intent();
    String title = GET_PICTURE;
    if (this.mediaType == PICTURE) {
        intent.setType("image/*");
    } else if (this.mediaType == VIDEO) {
        intent.setType("video/*");
        title = GET_VIDEO;
    } else if (this.mediaType == ALLMEDIA) {
        // I wanted to make the type 'image/*, video/*' but this does not work on all versions
        // of android so I had to go with the wildcard search.
        intent.setType("*/*");
        title = GET_All;
    }

    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    if (this.cordova != null) {
        this.cordova.startActivityForResult((CordovaPlugin) this,
                Intent.createChooser(intent, new String(title)), (srcType + 1) * 16 + returnType + 1);
    }
}

From source file:com.farmerbb.notepad.activity.MainActivity.java

@TargetApi(Build.VERSION_CODES.KITKAT)
private void reallyExportNotes() {
    String filename = "";

    try {/*from w ww.  j  ava 2  s.c  o  m*/
        filename = loadNoteTitle(filesToExport[fileBeingExported].toString());
    } catch (IOException e) {
        /* Gracefully fail */ }

    Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TITLE, generateFilename(filename));

    try {
        startActivityForResult(intent, EXPORT);
    } catch (ActivityNotFoundException e) {
        showToast(R.string.error_exporting_notes);
    }
}

From source file:nl.sogeti.android.gpstracker.actions.ShareTrack.java

private void sendFile(Uri fileUri, String body, String contentType) {
    Intent sendActionIntent = new Intent(Intent.ACTION_SEND);
    sendActionIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.email_subject));
    sendActionIntent.putExtra(Intent.EXTRA_TEXT, body);
    sendActionIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
    sendActionIntent.setType(contentType);
    startActivity(Intent.createChooser(sendActionIntent, getString(R.string.sender_chooser)));
}

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

/**
 * {@inheritDoc}//from w ww . j a va2 s . com
 */
@Override
public final void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Utils.setLocale(this);
    this.setTitle(R.string.settings);
    this.addPreferencesFromResource(R.xml.prefs);

    Preference p = this.findPreference(PREFS_ADVANCED);
    if (p != null) {
        p.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(final Preference preference, final Object newValue) {
                if (newValue.equals(true)) {
                    Preferences.this.startActivity(new Intent(Preferences.this, Help.class));
                }
                return true;
            }
        });
    }
    Market.setOnPreferenceClickListener(this, this.findPreference("more_apps"), null, "Felix+Bechstein",
            "http://code.google.com/u/felix.bechstein/");
    p = this.findPreference("send_logs");
    if (p != null) {
        p.setOnPreferenceClickListener(// .
                new Preference.OnPreferenceClickListener() {
                    public boolean onPreferenceClick(final Preference preference) {
                        Log.collectAndSendLog(Preferences.this);
                        return true;
                    }
                });
    }
    p = this.findPreference("send_devices");
    if (p != null) {
        p.setOnPreferenceClickListener(// .
                new Preference.OnPreferenceClickListener() {
                    @Override
                    public boolean onPreferenceClick(final Preference preference) {
                        final Intent intent = new Intent(// .
                                Intent.ACTION_SEND);
                        intent.setType("text/plain");
                        intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "android+callmeter@ub0r.de", "" });
                        intent.putExtra(Intent.EXTRA_TEXT, Device.debugDeviceList());
                        intent.putExtra(Intent.EXTRA_SUBJECT, "Call Meter 3G: Device List");
                        try {
                            Preferences.this.startActivity(intent);
                        } catch (ActivityNotFoundException e) {
                            Log.e(TAG, "no mail", e);
                            Toast.makeText(Preferences.this, "no mail app found", Toast.LENGTH_LONG).show();
                        }
                        return true;
                    }
                });
    }
    p = this.findPreference("reset_data");
    if (p != null) {
        p.setOnPreferenceClickListener(// .
                new Preference.OnPreferenceClickListener() {
                    public boolean onPreferenceClick(final Preference preference) {
                        Preferences.this.resetDataDialog();
                        return true;
                    }
                });
    }
    p = this.findPreference("export_rules");
    if (p != null) {
        p.setOnPreferenceClickListener(// .
                new Preference.OnPreferenceClickListener() {
                    public boolean onPreferenceClick(final Preference preference) {
                        Preferences.this.exportData(null, DataProvider.EXPORT_RULESET_FILE);
                        return true;
                    }
                });
    }
    p = this.findPreference("export_logs");
    if (p != null) {
        p.setOnPreferenceClickListener(// .
                new Preference.OnPreferenceClickListener() {
                    public boolean onPreferenceClick(final Preference preference) {
                        Preferences.this.exportData(null, DataProvider.EXPORT_LOGS_FILE);
                        return true;
                    }
                });
    }
    p = this.findPreference("export_numgroups");
    if (p != null) {
        p.setOnPreferenceClickListener(// .
                new Preference.OnPreferenceClickListener() {
                    public boolean onPreferenceClick(final Preference preference) {
                        Preferences.this.exportData(null, DataProvider.EXPORT_NUMGROUPS_FILE);
                        return true;
                    }
                });
    }
    p = this.findPreference("export_hourgroups");
    if (p != null) {
        p.setOnPreferenceClickListener(// .
                new Preference.OnPreferenceClickListener() {
                    public boolean onPreferenceClick(final Preference preference) {
                        Preferences.this.exportData(null, DataProvider.EXPORT_HOURGROUPS_FILE);
                        return true;
                    }
                });
    }
    p = this.findPreference("import_rules");
    if (p != null) {
        p.setOnPreferenceClickListener(// .
                new Preference.OnPreferenceClickListener() {
                    public boolean onPreferenceClick(final Preference preference) {
                        Preferences.this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(// .
                                Preferences.this.getString(// .
                                        R.string.url_rulesets))));
                        return true;
                    }
                });
    }

    this.onNewIntent(this.getIntent());
}