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:de.appplant.cordova.plugin.emailcomposer.EmailComposer.java

/**
 * Gibt an, ob es eine Anwendung gibt, welche E-Mails versenden kann.
 *///  ww w  . j  a va  2s  .co  m
private Boolean isEmailAccountConfigured() {
    Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "max@mustermann.com", null));
    Boolean available = cordova.getActivity().getPackageManager().queryIntentActivities(intent, 0).size() > 1;

    return available;
}

From source file:at.wada811.utils.IntentUtils.java

/**
 * ???Intent??//from   www .jav a 2s . com
 *
 * @param packageName
 */
public static Intent createOpenUninstallIntent(String packageName) {
    return new Intent(Intent.ACTION_DELETE, Uri.fromParts("package", packageName, null));
}

From source file:ru.dublgis.androidhelpers.DesktopUtils.java

public static boolean sendEmail(final Context ctx, final String to, final String subject, final String body,
        final String attach_file, final boolean force_content_provider, final String authorities) {
    //Log.d(TAG, "Will send email with subject \"" +
    //    subject + "\" to \"" + to + "\" with attach_file = \"" + attach_file + "\"" +
    //    ", force_content_provider = " + force_content_provider +
    //    ", authorities = \"" + authorities + "\"");
    try {//from  w  w w .  j av  a2s . c o  m
        // TODO: support multiple recipients
        String[] recipients = new String[] { to };

        final Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", to, null));
        List<ResolveInfo> resolveInfos = ctx.getPackageManager().queryIntentActivities(intent, 0);
        Intent chooserIntent = null;
        List<Intent> intentList = new ArrayList<Intent>();

        Intent i = new Intent(Intent.ACTION_SEND);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        i.setType("message/rfc822");
        i.putExtra(Intent.EXTRA_EMAIL, recipients);
        i.putExtra(Intent.EXTRA_SUBJECT, subject);
        i.putExtra(Intent.EXTRA_TEXT, body);

        Uri workaround_grant_permission_for_uri = null;
        if (attach_file != null && !attach_file.isEmpty()) {
            if (!force_content_provider && android.os.Build.VERSION.SDK_INT < 23) {
                i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(attach_file)));
            } else {
                // Android 6+: going the longer route.
                // For more information, please see:
                // http://stackoverflow.com/questions/32981194/android-6-cannot-share-files-anymore
                i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                workaround_grant_permission_for_uri = FileProvider.getUriForFile(ctx, authorities,
                        new File(attach_file));
                i.putExtra(Intent.EXTRA_STREAM, workaround_grant_permission_for_uri);
            }
        }

        for (ResolveInfo resolveInfo : resolveInfos) {
            String packageName = resolveInfo.activityInfo.packageName;
            String name = resolveInfo.activityInfo.name;

            // Some mail clients will not read the URI unless this is done.
            // See here: https://stackoverflow.com/questions/24467696/android-file-provider-permission-denial
            if (workaround_grant_permission_for_uri != null) {
                try {
                    ctx.grantUriPermission(packageName, workaround_grant_permission_for_uri,
                            Intent.FLAG_GRANT_READ_URI_PERMISSION);
                } catch (final Throwable e) {
                    Log.e(TAG, "grantUriPermission error: ", e);
                }
            }

            Intent fakeIntent = (Intent) i.clone();
            fakeIntent.setComponent(new ComponentName(packageName, name));
            if (chooserIntent == null) {
                chooserIntent = fakeIntent;
            } else {
                intentList.add(fakeIntent);
            }
        }

        if (chooserIntent == null) {
            chooserIntent = Intent.createChooser(i, null // "Select email application."
            );
            chooserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        } else if (!intentList.isEmpty()) {
            Intent fakeIntent = chooserIntent;
            chooserIntent = new Intent(Intent.ACTION_CHOOSER);
            chooserIntent.putExtra(Intent.EXTRA_INTENT, fakeIntent);
            Intent[] extraIntents = intentList.toArray(new Intent[intentList.size()]);
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
        }

        ctx.startActivity(chooserIntent);
        return true;
    } catch (final Throwable e) {
        Log.e(TAG, "sendEmail exception: ", e);
        return false;
    }
}

From source file:com.emotiona.study.listviewpage.SwipeMenuListViewFragment.java

private void delete(ApplicationInfo item) {
    // delete app
    try {/*from  w ww  .j av a  2  s.co  m*/
        Intent intent = new Intent(Intent.ACTION_DELETE);
        intent.setData(Uri.fromParts("package", item.packageName, null));
        startActivity(intent);
    } catch (Exception e) {
    }
}

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

private void retrievePrevents() {
    Intent intent = new Intent();
    intent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND);
    intent.setAction(PreventIntent.ACTION_GET_PACKAGES);
    intent.setData(Uri.fromParts(PreventIntent.SCHEME, getPackageName(), null));
    UILog.i("sending get prevent packages broadcast");
    sendOrderedBroadcast(intent, PreventIntent.PERMISSION_SYSTEM, receiver, mHandler, 0, null, null);
}

From source file:la.xiong.mylibrary.EasyPermissions.java

public static void goSettingsPermissions(final Object object, int dialogType, final int requestCode,
        final int requestCodeForResult, boolean isAppDialog) {
    checkCallingObjectSuitability(object);

    final Activity activity = getActivity(object);
    if (null == activity) {
        return;//from w  w  w  . j  ava  2  s .  c o  m
    }

    //appdialog
    if (isAppDialog == true) {
        if (object instanceof PermissionWithDialogCallbacks) {
            ((PermissionWithDialogCallbacks) object).onDialog(requestCode, dialogType, new DialogCallback() {

                @Override
                public void onGranted() {
                    Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                    Uri uri = Uri.fromParts("package", activity.getPackageName(), null);
                    intent.setData(uri);
                    startForResult(object, intent, requestCodeForResult);
                }
            });
        }
    } else {
        //TODO easypermissiondialog
    }

}

From source file:de.tu_berlin.snet.commstat.SensorFragment.java

private void sendMail() {
    Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
            Uri.fromParts("mailto", "ssakar@mailbox.tu-berlin.de", null));
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "[Commstat] ");
    startActivity(Intent.createChooser(emailIntent, "Send email..."));
}

From source file:org.fdroid.fdroid.installer.Installer.java

void sendBroadcastUninstall(String packageName, String action, PendingIntent pendingIntent,
        String errorMessage) {//from  www. ja v  a2 s. co  m
    Uri uri = Uri.fromParts("package", packageName, null);

    Intent intent = new Intent(action);
    intent.setData(uri); // for broadcast filtering
    intent.putExtra(Installer.EXTRA_PACKAGE_NAME, packageName);
    intent.putExtra(Installer.EXTRA_USER_INTERACTION_PI, pendingIntent);
    if (!TextUtils.isEmpty(errorMessage)) {
        intent.putExtra(Installer.EXTRA_ERROR_MESSAGE, errorMessage);
    }
    localBroadcastManager.sendBroadcast(intent);
}

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

private void retrieveRunning() {
    Intent intent = new Intent();
    intent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND);
    intent.setAction(PreventIntent.ACTION_GET_PROCESSES);
    intent.setData(Uri.fromParts(PreventIntent.SCHEME, getPackageName(), null));
    UILog.i("sending get processes broadcast");
    sendOrderedBroadcast(intent, PreventIntent.PERMISSION_SYSTEM, receiver, mHandler, 0, null, null);
}

From source file:net.arvin.pictureselectordemo.EasyPermissions.java

public static boolean checkDeniedPermissionsNeverAskAgain(final Object object, String rationale,
        String positiveButton, String 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;
            }/*from   w w  w  .j a v a2  s . c o m*/

            AlertDialog dialog = 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();
            dialog.show();

            return true;
        }
    }

    return false;
}