Example usage for android.net Uri fromParts

List of usage examples for android.net Uri fromParts

Introduction

In this page you can find the example usage for android.net Uri fromParts.

Prototype

public static Uri fromParts(String scheme, String ssp, String fragment) 

Source Link

Document

Creates an opaque Uri from the given components.

Usage

From source file:com.garyhu.citypickerdemo.widget.permission.easyPermission.EasyPermission.java

/**
 * OnActivityResult???//  w w w  .  j a  v  a2  s.  c o  m
 * {@link EasyPermission#hasPermissions(Context, String...)}
 *
 * If user denied permissions with the flag NEVER ASK AGAIN, open a dialog explaining the
 * permissions rationale again and directing the user to the app settings. After the user
 * returned to the app, {@link Activity#onActivityResult(int, int, Intent)} or
 * {@link Fragment#onActivityResult(int, int, Intent)} or
 * {@link android.app.Fragment#onActivityResult(int, int, Intent)} will be called with
 * {@value #SETTINGS_REQ_CODE} as requestCode
 * <p>
 *
 * NOTE: use of this method is optional, should be called from
 * {@link PermissionCallback#onEasyPermissionDenied(int, String[])}
 *
 * @return {@code true} if user denied at least one permission with the flag NEVER ASK AGAIN.
 */
public static boolean checkDeniedPermissionsNeverAskAgain(final Object object, String rationale,
        @StringRes int positiveButton, @StringRes int negativeButton,
        @Nullable DialogInterface.OnClickListener negativeButtonOnClickListener, String... deniedPerms) {
    boolean shouldShowRationale;
    for (String perm : deniedPerms) {
        shouldShowRationale = Utils.shouldShowRequestPermissionRationale(object, perm);

        if (!shouldShowRationale) {
            final Activity activity = Utils.getActivity(object);
            if (null == activity) {
                return true;
            }

            new AlertDialog.Builder(activity).setMessage(rationale)
                    .setPositiveButton(positiveButton, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                            Uri uri = Uri.fromParts("package", activity.getPackageName(), null);
                            intent.setData(uri);
                            startAppSettingsScreen(object, intent);
                        }
                    }).setNegativeButton(negativeButton, negativeButtonOnClickListener).create().show();

            return true;
        }
    }

    return false;
}

From source file:com.abcvoipsip.ui.calllog.CallLogListFragment.java

@Override
public void placeCall(String number, Long accId) {
    if (!TextUtils.isEmpty(number)) {
        Intent it = new Intent(Intent.ACTION_CALL);
        it.setData(Uri.fromParts("csip", SipUri.getCanonicalSipContact(number, false), null));
        it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (accId != null) {
            it.putExtra(SipProfile.FIELD_ACC_ID, accId);
        }/*from   w w  w .  j  a  v  a 2 s .  c  o m*/
        getActivity().startActivity(it);
    }
}

From source file:com.google.android.apps.muzei.gallery.GallerySettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gallery_activity);
    Toolbar appBar = (Toolbar) findViewById(R.id.app_bar);
    setSupportActionBar(appBar);/*w w w.  ja va  2  s  .  co m*/

    getSupportLoaderManager().initLoader(0, null, this);

    bindService(new Intent(this, GalleryArtSource.class).setAction(GalleryArtSource.ACTION_BIND_GALLERY),
            mServiceConnection, BIND_AUTO_CREATE);

    mPlaceholderDrawable = new ColorDrawable(
            ContextCompat.getColor(this, R.color.gallery_chosen_photo_placeholder));

    mPhotoGridView = (RecyclerView) findViewById(R.id.photo_grid);
    DefaultItemAnimator itemAnimator = new DefaultItemAnimator();
    itemAnimator.setSupportsChangeAnimations(false);
    mPhotoGridView.setItemAnimator(itemAnimator);
    setupMultiSelect();

    final GridLayoutManager gridLayoutManager = new GridLayoutManager(GallerySettingsActivity.this, 1);
    mPhotoGridView.setLayoutManager(gridLayoutManager);

    final ViewTreeObserver vto = mPhotoGridView.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            int width = mPhotoGridView.getWidth() - mPhotoGridView.getPaddingStart()
                    - mPhotoGridView.getPaddingEnd();
            if (width <= 0) {
                return;
            }

            // Compute number of columns
            int maxItemWidth = getResources()
                    .getDimensionPixelSize(R.dimen.gallery_chosen_photo_grid_max_item_size);
            int numColumns = 1;
            while (true) {
                if (width / numColumns > maxItemWidth) {
                    ++numColumns;
                } else {
                    break;
                }
            }

            int spacing = getResources().getDimensionPixelSize(R.dimen.gallery_chosen_photo_grid_spacing);
            mItemSize = (width - spacing * (numColumns - 1)) / numColumns;

            // Complete setup
            gridLayoutManager.setSpanCount(numColumns);
            mChosenPhotosAdapter.setHasStableIds(true);
            mPhotoGridView.setAdapter(mChosenPhotosAdapter);

            mPhotoGridView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            tryUpdateSelection(false);
        }
    });

    ViewCompat.setOnApplyWindowInsetsListener(mPhotoGridView, new OnApplyWindowInsetsListener() {
        @Override
        public WindowInsetsCompat onApplyWindowInsets(final View v, final WindowInsetsCompat insets) {
            int gridSpacing = getResources().getDimensionPixelSize(R.dimen.gallery_chosen_photo_grid_spacing);
            ViewCompat.onApplyWindowInsets(v,
                    insets.replaceSystemWindowInsets(insets.getSystemWindowInsetLeft() + gridSpacing,
                            gridSpacing, insets.getSystemWindowInsetRight() + gridSpacing,
                            insets.getSystemWindowInsetBottom() + insets.getSystemWindowInsetTop() + gridSpacing
                                    + getResources().getDimensionPixelSize(R.dimen.gallery_fab_space)));

            return insets;
        }
    });

    Button enableRandomImages = (Button) findViewById(R.id.gallery_enable_random);
    enableRandomImages.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View view) {
            ActivityCompat.requestPermissions(GallerySettingsActivity.this,
                    new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, REQUEST_STORAGE_PERMISSION);
        }
    });
    Button permissionSettings = (Button) findViewById(R.id.gallery_edit_permission_settings);
    permissionSettings.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View view) {
            Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
                    Uri.fromParts("package", getPackageName(), null));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
    });
    mAddButton = findViewById(R.id.add_photos_button);
    mAddButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // Use ACTION_OPEN_DOCUMENT by default for adding photos.
            // This allows us to use persistent URI permissions to access the underlying photos
            // meaning we don't need to use additional storage space and will pull in edits automatically
            // in addition to syncing deletions.
            // (There's a separate 'Import photos' option which uses ACTION_GET_CONTENT to support legacy apps)
            Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
            intent.setType("image/*");
            intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
            startActivityForResult(intent, REQUEST_CHOOSE_PHOTOS);
        }
    });
}

From source file:me.piebridge.prevent.ui.PreventActivity.java

private boolean requestLog() {
    if (getExternalCacheDir() != null) {
        Intent intent = new Intent();
        intent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND);
        intent.setAction(PreventIntent.ACTION_SYSTEM_LOG);
        intent.setData(Uri.fromParts(PreventIntent.SCHEME, getPackageName(), null));
        UILog.i("sending request log broadcast");
        showProcessDialog(R.string.retrieving);
        sendOrderedBroadcast(intent, PreventIntent.PERMISSION_SYSTEM, receiver, mHandler, 0, null, null);
    }//ww  w  .  j a v  a  2 s  . c om
    return false;
}

From source file:com.albedinsky.android.support.intent.MapIntent.java

/**
 *//*from  w  w w  . j  a v  a 2 s .  c  o  m*/
@NonNull
@Override
protected Intent onBuild() {
    final StringBuilder uriBuilder = new StringBuilder(64);
    if (mLatLngSet) {
        if (!TextUtils.isEmpty(mLabel)) {
            uriBuilder.append("0,0?q=");
            uriBuilder.append(mLat);
            uriBuilder.append(",");
            uriBuilder.append(mLng);
            this.appendLabel(uriBuilder);
        } else {
            uriBuilder.append(mLat);
            uriBuilder.append(",");
            uriBuilder.append(mLng);

            if (mZoomLevel != 0) {
                uriBuilder.append("?z=");
                uriBuilder.append(mZoomLevel);
            }

            if (!TextUtils.isEmpty(mLocationQuery)) {
                uriBuilder.append(mZoomLevel != 0 ? "&" : "?");
                this.appendLocationQuery(uriBuilder);
            }
        }
    } else {
        uriBuilder.append("0,0?");
        this.appendLocationQuery(uriBuilder);
        if (!TextUtils.isEmpty(mLabel)) {
            this.appendLabel(uriBuilder);
        }
    }

    final Uri locationUri = Uri.fromParts(URI_SCHEME, uriBuilder.toString(), null);
    if (IntentsConfig.DEBUG_LOG_ENABLED) {
        Log.d(TAG, "Building intent with uri('" + locationUri.toString() + "').");
    }
    return new Intent(Intent.ACTION_VIEW, locationUri);
}

From source file:com.google.android.gms.location.sample.locationupdatesforegroundservice.MainActivity.java

/**
 * Callback received when a permissions request has been completed.
 *///from w w  w. ja  v  a2  s. c  o  m
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    Log.i(TAG, "onRequestPermissionResult");
    if (requestCode == REQUEST_PERMISSIONS_REQUEST_CODE) {
        if (grantResults.length <= 0) {
            // If user interaction was interrupted, the permission request is cancelled and you
            // receive empty arrays.
            Log.i(TAG, "User interaction was cancelled.");
        } else if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            // Permission was granted.
            mService.requestLocationUpdates();
        } else {
            // Permission denied.
            setButtonsState(false);
            Snackbar.make(findViewById(R.id.activity_main), R.string.permission_denied_explanation,
                    Snackbar.LENGTH_INDEFINITE).setAction(R.string.settings, new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            // Build intent that displays the App settings screen.
                            Intent intent = new Intent();
                            intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                            Uri uri = Uri.fromParts("package", BuildConfig.APPLICATION_ID, null);
                            intent.setData(uri);
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                        }
                    }).show();
        }
    }
}

From source file:texus.autozoneuaenew.fragments.FragmentProductDetails.java

public void sendMail() {

    Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
            Uri.fromParts("mailto", "cars@autozoneuae.com", null));
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Enquire about " + product.product_name);
    emailIntent.putExtra(Intent.EXTRA_TEXT, "");
    getActivity().startActivity(Intent.createChooser(emailIntent, "Send email to AutozoneUAE"));

}

From source file:com.google.android.gms.nearby.messages.samples.hellobeacons.MainActivity.java

/**
 * Displays {@link Snackbar} instructing user to visit Settings to grant permissions required by
 * this application./*  w  w  w .j a va2  s . c om*/
 */
private void showLinkToSettingsSnackbar() {
    if (mContainer == null) {
        return;
    }
    Snackbar.make(mContainer, R.string.permission_denied_explanation, Snackbar.LENGTH_INDEFINITE)
            .setAction(R.string.settings, new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    // Build intent that displays the App settings screen.
                    Intent intent = new Intent();
                    intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                    Uri uri = Uri.fromParts("package", BuildConfig.APPLICATION_ID, null);
                    intent.setData(uri);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                }
            }).show();
}

From source file:co.tinode.tindroid.ContactsFragment.java

private void handleItemClick(final ContactsAdapter.ViewHolder tag) {
    boolean done = false;
    if (mPhEmImData != null) {
        Utils.ContactHolder holder = mPhEmImData.get(tag.contact_id);
        if (holder != null) {
            String address = holder.getIm();
            if (address != null) {
                Intent it = new Intent(getActivity(), MessageActivity.class);
                it.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                it.putExtra("topic", address);
                startActivity(it);/*from www .  j ava  2s  .  c  o  m*/
                done = true;
            }

            if (!done && ((address = holder.getPhone()) != null)) {
                // Send an SMS with an invitation
                Uri uri = Uri.fromParts("smsto", address, null);
                Intent it = new Intent(Intent.ACTION_SENDTO, uri);
                it.putExtra("sms_body", getString(R.string.tinode_invite_body));
                startActivity(it);
                done = true;
            }
            if (!done && ((address = holder.getEmail()) != null)) {
                Uri uri = Uri.fromParts("mailto", address, null);
                Intent it = new Intent(Intent.ACTION_SENDTO, uri);
                it.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.tinode_invite_subject));
                it.putExtra(Intent.EXTRA_TEXT, getString(R.string.tinode_invite_body));
                startActivity(it);
                done = true;
            }
        }
    }

    if (!done) {
        Toast.makeText(getContext(), R.string.failed_to_invite, Toast.LENGTH_SHORT).show();
    }
}

From source file:com.are.photophone.utils.permissionutils.EasyPermissions.java

/**
 * If user denied permissions with the flag NEVER ASK AGAIN, open a dialog explaining the
 * permissions rationale again and directing the user to the app settings. After the user
 * returned to the app, {@link Activity#onActivityResult(int, int, Intent)} or
 * {@link Fragment#onActivityResult(int, int, Intent)} or
 * {@link android.app.Fragment#onActivityResult(int, int, Intent)} will be called with
 * {@value #SETTINGS_REQ_CODE} as requestCode
 * <p>/*from w w  w .  java  2s . c  o m*/
 * NOTE: use of this method is optional, should be called from
 * {@link PermissionCallbacks#onPermissionsDenied(int, List)}
 *
 * @param object                        the calling Activity or Fragment.
 * @param deniedPerms                   the set of denied permissions.
 * @param negativeButtonOnClickListener negative button on click listener. If the
 *                                      user click the negative button, then this listener will
 *                                      be called. Pass null if you don't want to handle it.
 * @return {@code true} if user denied at least one permission with the flag NEVER ASK AGAIN.
 */
public static boolean checkDeniedPermissionsNeverAskAgain(final Object object, String rationale,
        @StringRes int positiveButton, @StringRes int negativeButton,
        @Nullable DialogInterface.OnClickListener negativeButtonOnClickListener, List<String> deniedPerms) {
    boolean shouldShowRationale;
    for (String perm : deniedPerms) {
        shouldShowRationale = shouldShowRequestPermissionRationale(object, perm);
        if (!shouldShowRationale) {
            final Activity activity = getActivity(object);
            if (null == activity) {
                return true;
            }

            AlertDialog dialog = new AlertDialog.Builder(activity).setIcon(R.drawable.ic_alert)
                    .setMessage(rationale)
                    .setPositiveButton(positiveButton, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                            Uri uri = Uri.fromParts("package", activity.getPackageName(), null);
                            intent.setData(uri);
                            startAppSettingsScreen(object, intent);
                        }
                    }).setNegativeButton(negativeButton, negativeButtonOnClickListener).create();
            dialog.show();

            return true;
        }
    }

    return false;
}