Example usage for android.content Intent setDataAndType

List of usage examples for android.content Intent setDataAndType

Introduction

In this page you can find the example usage for android.content Intent setDataAndType.

Prototype

public @NonNull Intent setDataAndType(@Nullable Uri data, @Nullable String type) 

Source Link

Document

(Usually optional) Set the data for the intent along with an explicit MIME data type.

Usage

From source file:com.android.contacts.common.list.ShortcutIntentBuilder.java

private void createContactShortcutIntent(Uri contactUri, String contentType, String displayName,
        String lookupKey, byte[] bitmapData) {
    Drawable drawable = getPhotoDrawable(bitmapData, displayName, lookupKey);

    // Use an implicit intent without a package name set. It is reasonable for a disambiguation
    // dialog to appear when opening QuickContacts from the launcher. Plus, this will be more
    // resistant to future package name changes done to Contacts.
    Intent shortcutIntent = new Intent(ContactsContract.QuickContact.ACTION_QUICK_CONTACT);

    // When starting from the launcher, start in a new, cleared task.
    // CLEAR_WHEN_TASK_RESET cannot reset the root of a task, so we
    // clear the whole thing preemptively here since QuickContactActivity will
    // finish itself when launching other detail activities. We need to use
    // Intent.FLAG_ACTIVITY_NO_ANIMATION since not all versions of launcher will respect
    // the INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION intent extra.
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK
            | Intent.FLAG_ACTIVITY_NO_ANIMATION);

    // Tell the launcher to not do its animation, because we are doing our own
    shortcutIntent.putExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION, true);

    shortcutIntent.setDataAndType(contactUri, contentType);
    shortcutIntent.putExtra(ContactsContract.QuickContact.EXTRA_EXCLUDE_MIMES, (String[]) null);

    final Bitmap icon = generateQuickContactIcon(drawable);

    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    if (TextUtils.isEmpty(displayName)) {
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, mContext.getResources().getString(R.string.missing_name));
    } else {//from  w  ww.ja  va  2  s .  com
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, displayName);
    }

    mListener.onShortcutIntentCreated(contactUri, intent);
}

From source file:com.colorchen.qbase.utils.FileUtil.java

/**
 * Intent./* w  w  w.  j a  v  a2s.  c  o m*/
 */
public static Intent getFileIntent(String path, String mimeType) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(new File(path)), mimeType);
    return intent;
}

From source file:com.jamiealtizer.cordova.inappbrowser.InAppBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url           The url to load.
 * @param usePhoneGap   Load url in PhoneGap webview
 * @return              "" if ok, or error message.
 *//*from   w  ww  .  j a  v  a 2s .c o  m*/
public String openExternal(String url) {
    try {
        Intent intent = null;
        intent = new Intent(Intent.ACTION_VIEW);
        // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
        // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
        Uri uri = Uri.parse(url);
        if ("file".equals(uri.getScheme())) {
            intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
        } else {
            intent.setData(uri);
        }
        intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());
        this.cordova.getActivity().startActivity(intent);
        return "";
    } catch (android.content.ActivityNotFoundException e) {
        Log.d(LOG_TAG, "InAppBrowser: Error loading url " + url + ":" + e.toString());
        return e.toString();
    }
}

From source file:br.com.bioscada.apps.biotracks.fragments.MarkerDetailFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    long markerId = getArguments().getLong(KEY_MARKER_ID);
    FragmentActivity fragmentActivity = getActivity();
    Intent intent;

    switch (item.getItemId()) {
    case R.id.marker_detail_show_on_map:
        intent = IntentUtils.newIntent(fragmentActivity, TrackDetailActivity.class)
                .putExtra(TrackDetailActivity.EXTRA_MARKER_ID, markerId);
        startActivity(intent);/*from   www  . j av a2  s .co m*/
        return true;
    case R.id.marker_detail_edit:
        intent = IntentUtils.newIntent(fragmentActivity, MarkerEditActivity.class)
                .putExtra(MarkerEditActivity.EXTRA_MARKER_ID, markerId);
        startActivity(intent);
        return true;
    case R.id.marker_detail_delete:
        DeleteMarkerDialogFragment.newInstance(new long[] { markerId }).show(getChildFragmentManager(),
                DeleteMarkerDialogFragment.DELETE_MARKER_DIALOG_TAG);
        return true;
    case R.id.marker_detail_view_photo:
        intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.parse(waypoint.getPhotoUrl()), "image/*");
        startActivity(intent);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.simonmacdonald.corinthian.VideoPlayer.java

private void playVideo(String url) throws IOException {
    // Create URI
    Uri uri = Uri.parse(url);//  w w w  .  j a va 2s  .c o m

    Intent intent = null;
    // Check to see if someone is trying to play a YouTube page.
    if (url.contains(YOU_TUBE)) {
        // If we don't do it this way you don't have the option for youtube
        uri = Uri.parse("vnd.youtube:" + uri.getQueryParameter("v"));
        intent = new Intent(Intent.ACTION_VIEW, uri);
    } else if (url.contains(ASSETS)) {
        // get file path in assets folder
        String filepath = url.replace(ASSETS, "");
        // get actual filename from path as command to write to internal storage doesn't like folders
        String filename = filepath.substring(filepath.lastIndexOf("/") + 1, filepath.length());

        // Don't copy the file if it already exists
        File fp = new File(this.cordova.getContext().getFilesDir() + "/" + filename);
        if (!fp.exists()) {
            this.copy(filepath, filename);
        }

        // change uri to be to the new file in internal storage
        uri = Uri.parse("file://" + this.cordova.getContext().getFilesDir() + "/" + filename);

        // Display video player
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "video/*");
    } else {
        // Display video player
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "video/*");
    }

    this.cordova.getActivity().startActivity(intent);
}

From source file:com.ccxt.whl.activity.SettingsFragment.java

/**
 * ?/*from  w w w  . j a va2  s  .c  om*/
 * @param uri
 * @param outputX
 * @param outputY
 * @param requestCode
 */
private void cropImageUri(Uri uri, int outputX, int outputY, int requestCode) {

    /*Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setDataAndType(uri, "image/*");
    intent.putExtra("crop", "true");
    //aspectX aspectY
    intent.putExtra("aspectX", 1);
    intent.putExtra("aspectY", 1);
    // outputX outputY ?
    intent.putExtra("outputX", outputX);
    intent.putExtra("outputY", outputY);
    intent.putExtra("scale", true);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
    intent.putExtra("return-data", false);
    intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
    intent.putExtra("noFaceDetection", true); // no face detection
    startActivityForResult(intent, requestCode);*/

    Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setDataAndType(uri, "image/*");
    intent.putExtra("crop", "true");
    intent.putExtra("aspectX", 1);
    intent.putExtra("aspectY", 1);
    intent.putExtra("outputX", outputX);
    intent.putExtra("outputY", outputY);
    intent.putExtra("scale", true);
    intent.putExtra("return-data", true);
    intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
    intent.putExtra("noFaceDetection", true); // no face detection
    startActivityForResult(intent, requestCode);
}

From source file:com.abeo.tia.noordin.AddCaseStep2of4.java

@Override
public void onClick(View v) {
    if (v == btnpdf1) {
        //initiatePopupWindow();

        String pdfurl = "http://54.251.51.69:3878" + TITLELINK; //YOUR URL TO PDF
        String googleDocsUrl = "http://docs.google.com/viewer?url=" + pdfurl;
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.parse(googleDocsUrl), "text/html");
        startActivity(intent);//  w w  w. ja va 2s  .  c om

    } else if (v == btnpdf2) {
        String pdfurl = "http://54.251.51.69:3878" + LSTCHG_PRSTLINK; //YOUR URL TO PDF
        String googleDocsUrl = "http://docs.google.com/viewer?url=" + pdfurl;
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.parse(googleDocsUrl), "text/html");
        startActivity(intent);
    } else if (v == buttonconfirm) {
        if (val())
            btnconfirm();
    } else if (v == walkin) {
        Intent i = new Intent(AddCaseStep2of4.this, WalkInActivity.class);
        startActivity(i);
    }
}

From source file:com.zertinteractive.wallpaper.activities.DetailActivity.java

public void setAsWallpaper(long mImageId) {
    if (mImageId == -1) {
        setAsWallpaperMore();/*  w  w w. ja v  a2s  .co m*/
    } else {
        Intent intent = new Intent(DetailActivity.this, SetWallpaperActivity.class);
        Uri base_uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
        Uri item_uri = ContentUris.withAppendedId(base_uri, mImageId);
        intent.putExtra(Intent.EXTRA_STREAM, item_uri);
        Cursor cur = getContentResolver().query(item_uri, null, null, null, null);
        if (cur.moveToFirst()) {
            int colMimetype = cur.getColumnIndex(MediaStore.Images.ImageColumns.MIME_TYPE);
            intent.setDataAndType(item_uri, cur.getString(colMimetype));
        }
        cur.close();
        startActivity(intent);
    }
}

From source file:com.amaze.filemanager.utils.Futils.java

private boolean isSelfDefault(File f, Context c) {
    Intent intent = new Intent();
    intent.setAction(android.content.Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(f), MimeTypes.getMimeType(f));
    String s = "";
    ResolveInfo rii = c.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
    if (rii != null && rii.activityInfo != null)
        s = rii.activityInfo.packageName;
    if (s.equals("com.amaze.filemanager") || rii == null)
        return true;
    else/* ww  w  .j  a  v  a 2 s . co  m*/
        return false;
}

From source file:com.intuit.qboecoui.email.SalesFormEmail.java

/**
 * invoke the pdf viewer to show the downloaded PDF.
 *//* w w  w.  j  a v a2  s .c  o m*/
private void startExternalPreviewActivity() {

    if (hasPreviewLaunched) {
        return;
    }
    hasPreviewLaunched = true;
    // track the launch of external pdf viewer
    //SalesFormEmail.SFM_Flow_tracking = Util.buildTrackingFlow(SalesFormEmail.SFM_Flow_tracking, QBMTrackConstants.SFM_OPEN_PDF );
    BaseApplicationModule.getTrackingModule().trackLink(QBMTrackConstants.SALES_FORM_EMAIL_PAGE_NAME,
            QBMTrackConstants.SFM_OPEN_PDF);

    try {
        mPDFFileName = AppPreferences.getStringPreference(this.getApplicationContext(),
                BaseAppPreferences.PREFS_QBSHAREDLIB, QBODocumentLinkEntity.KEY_PDF_FILENAME, null);
        File file = new File(mPDFFileName);
        Uri fileUri = FileProvider.getUriForFile(this,
                this.getApplicationContext().getResources().getString(R.string.file_provider_authorities),
                file);
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.setDataAndType(fileUri, this.getContentResolver().getType(fileUri));
        startActivity(intent);
    } catch (final ActivityNotFoundException e) {
        displayError(R.string.error_pdf_viewer_not_present, R.string.error_title_error, false);
    }
}