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:co.vanir.indecentxposure.IndecentXposure.java

public static void notify(final Context context, final String exampleString) {
    final Resources res = context.getResources();

    final String ticker = exampleString;
    final String title = res.getString(R.string.solve_problems_notification_title); //_template, exampleString);
    final String text = res.getString(R.string.solve_problems_notification_placeholder_text_template);//, exampleString);

    //one button opens the "uninstall app" settings page
    final Intent removeIntent = new Intent();
    removeIntent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
    Uri uri = Uri.fromParts("package", SerialOffender.getPackageName(), null);
    removeIntent.setData(uri);/*from   w w  w .  ja  va  2  s.c  om*/

    //the other option will hide the notification until the user uninstalls and reinstalls
    //  the installer
    final Intent ignoreIntent = new Intent();
    ignoreIntent.setAction("co.vanir.indecentxposure.IGNORE_LIKELY_FUNK");

    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_stat_solve_problems).setContentTitle(title).setContentText(text)
            .setPriority(NotificationCompat.PRIORITY_MAX).setTicker(ticker)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(text).setBigContentTitle(title)
                    .setSummaryText(res.getString(R.string.summary_thanks)))
            .addAction(0, res.getString(R.string.action_remove),
                    PendingIntent.getActivity(context, 0, removeIntent, PendingIntent.FLAG_UPDATE_CURRENT))
            .addAction(0, res.getString(R.string.action_accept_consequences),
                    PendingIntent.getBroadcast(context, 0, ignoreIntent, PendingIntent.FLAG_CANCEL_CURRENT));

    notify(context, builder.build(), true);
}

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

/**
 */
@NonNull
@Override
protected Intent onBuild() {
    return new Intent(Intent.ACTION_DIAL, Uri.fromParts(URI_SCHEME, mPhoneNumber, null));
}

From source file:com.rks.musicx.misc.utils.permissionManager.java

public static void settingPermission(@NonNull Activity activity) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.System.canWrite(activity)) {
        MaterialDialog.Builder builder = new MaterialDialog.Builder(activity).title(R.string.permissions_title)
                .content(R.string.writesetting).positiveText(R.string.btn_continue)
                .negativeText(R.string.btn_cancel).autoDismiss(true)
                .onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override/*from ww  w  . j  a v a2 s.c  o  m*/
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
                            Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS,
                                    Uri.fromParts("package", activity.getPackageName(), null));
                            if (Helper.isActivityPresent(activity, intent)) {
                                activity.startActivityForResult(intent, WRITESETTINGS);
                            } else {
                                Toast.makeText(activity, "No app found to handle settings write permission",
                                        Toast.LENGTH_SHORT).show();
                            }
                        }
                    }
                }).onNegative(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        Toast.makeText(activity, R.string.toast_permissions_not_granted, Toast.LENGTH_SHORT)
                                .show();
                        dialog.dismiss();
                    }
                }).neutralText("Never show again").onNeutral(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        Extras.getInstance().setSettings(true);
                        dialog.dismiss();
                    }
                });
        if (activity.hasWindowFocus() || !activity.isFinishing()) {
            builder.show();
        }
    }
}

From source file:com.github.akinaru.roboticbuttonpusher.menu.MenuUtils.java

/**
 * Execute actions according to selected menu item
 *
 * @param menuItem MenuItem object//  ww w  .  ja  v  a2s.c  om
 * @param mDrawer  navigation drawer
 * @param context  android context
 */
public static void selectDrawerItem(MenuItem menuItem, DrawerLayout mDrawer, Context context,
        final IButtonPusher buttonPusher) {

    switch (menuItem.getItemId()) {
    case R.id.exit_item: {
        if (buttonPusher.giveUpNoPermission()) {
            buttonPusher.disassociate();
        } else {
            buttonPusher.requestPermission();
        }
        break;
    }
    case R.id.password_item: {
        if (buttonPusher != null) {
            if (buttonPusher.giveUpNoPermission()) {
                DevicePasswordDialog dialog = new DevicePasswordDialog(buttonPusher);
                dialog.show();
            } else {
                buttonPusher.requestPermission();
            }
        }
        break;
    }
    case R.id.keys_item: {
        if (buttonPusher != null) {
            if (buttonPusher.giveUpNoPermission()) {
                KeysDialog dialog = new KeysDialog(buttonPusher);
                dialog.show();
            } else {
                buttonPusher.requestPermission();
            }
        }
        break;
    }
    case R.id.message_item: {
        if (buttonPusher != null) {
            if (buttonPusher.giveUpNoPermission()) {
                DeviceMessageDialog dialog = new DeviceMessageDialog(buttonPusher);
                dialog.show();
            } else {
                buttonPusher.requestPermission();
            }
        }
        break;
    }
    case R.id.debug_mode_item: {

        CharSequence[] array = { "enabled", "disabled" };

        int indexCheck = buttonPusher.getDebugMode() ? 0 : 1;

        new AlertDialog.Builder(context).setSingleChoiceItems(array, indexCheck, null)
                .setPositiveButton(buttonPusher.getContext().getResources().getString(R.string.dialog_ok),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                dialog.dismiss();
                                int selectedPosition = ((AlertDialog) dialog).getListView()
                                        .getCheckedItemPosition();
                                if (selectedPosition == 0) {
                                    buttonPusher.setDebugMode(true);
                                } else {
                                    buttonPusher.setDebugMode(false);
                                }
                            }
                        })
                .setNegativeButton(buttonPusher.getContext().getResources().getString(R.string.cancel),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                dialog.dismiss();
                            }
                        })
                .show();
        break;
    }
    case R.id.report_bugs: {
        Intent intent = new Intent(Intent.ACTION_SENDTO,
                Uri.fromParts("mailto", context.getResources().getString(R.string.email_addr), null));
        intent.putExtra(Intent.EXTRA_SUBJECT, context.getResources().getString(R.string.issue_subject));
        intent.putExtra(Intent.EXTRA_TEXT, context.getResources().getString(R.string.report_hint));
        context.startActivity(
                Intent.createChooser(intent, context.getResources().getString(R.string.issue_title)));
        break;
    }
    case R.id.open_source_components: {
        OpenSourceItemsDialog d = new OpenSourceItemsDialog(context);
        d.show();
        break;
    }
    case R.id.rate_app: {
        context.startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse("market://details?id=" + context.getApplicationContext().getPackageName())));
        break;
    }
    case R.id.about_app: {
        AboutDialog dialog = new AboutDialog(context);
        dialog.show();
        break;
    }
    }
    mDrawer.closeDrawers();
}

From source file:com.asksven.betterbatterystats.PackageFragmentActivity.java

public static void showAppOps(Context context, String packageName) {

    Intent intent = null;//w w w .ja va2 s  .  co m
    // JB
    if (Build.VERSION.SDK_INT == 18) {
        intent = new Intent("android.settings.APP_OPS_SETTINGS");
        Uri uri = Uri.fromParts(SCHEME, packageName, null);
    } else if (Build.VERSION.SDK_INT >= 19) {
        // @see http://brightechno.com/blog/archives/211
        intent = new Intent();
        intent.setClassName("com.android.settings", "com.android.settings.Settings");
        intent.setAction(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK
                | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        intent.putExtra(":android:show_fragment", "com.android.settings.applications.AppOpsSummary");
    }

    if (intent != null) {
        try {
            context.startActivity(intent);
        } catch (ActivityNotFoundException e) {
            Toast.makeText(context, context.getString(R.string.message_no_appops), Toast.LENGTH_SHORT).show();
        }

    }
}

From source file:com.ieeecsvit.riviera17android.activity.MainActivity.java

public Intent createEmailOnlyChooserIntent(Intent source, CharSequence chooserTitle) {
    Stack<Intent> intents = new Stack<Intent>();
    Intent i = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "tushar.narula17@live.com", null));
    List<ResolveInfo> activities = getPackageManager().queryIntentActivities(i, 0);

    for (ResolveInfo ri : activities) {
        Intent target = new Intent(source);
        target.setPackage(ri.activityInfo.packageName);
        intents.add(target);//from  ww  w. j a v  a2 s .com
    }

    if (!intents.isEmpty()) {
        Intent chooserIntent = Intent.createChooser(intents.remove(0), chooserTitle);
        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intents.toArray(new Parcelable[intents.size()]));

        return chooserIntent;
    } else {
        return Intent.createChooser(source, chooserTitle);
    }
}

From source file:com.qiscus.sdk.util.QiscusPermissionsUtil.java

public static boolean checkDeniedPermissionsNeverAskAgain(Object object, String rationale,
        @StringRes int positiveButton, @StringRes int negativeButton, 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;
            }/* w  ww .j  av  a 2  s .c  o  m*/

            AlertDialog dialog = new AlertDialog.Builder(activity).setMessage(rationale)
                    .setPositiveButton(positiveButton, (dialog1, which) -> {
                        Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                        Uri uri = Uri.fromParts("package", activity.getPackageName(), null);
                        intent.setData(uri);
                        activity.startActivity(intent);
                    }).setNegativeButton(negativeButton, null).create();
            dialog.show();

            return true;
        }
    }

    return false;
}

From source file:me.egorand.contactssync.ui.activities.MainActivity.java

private void goToSettings() {
    Uri uri = Uri.fromParts("package", getPackageName(), null);
    Intent settingsIntent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, uri);
    settingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(settingsIntent);/* w ww  . j  a  va  2  s  .c  om*/
}

From source file:com.xiaodu.permission.util2.ESPermission.java

public static boolean checkDeniedPermissionsNeverAskAgain(final Activity activity, String rationale,
        @StringRes int positiveButton, @StringRes int negativeButton, List<String> deniedPerms) {
    boolean shouldShowRationale;
    for (String perm : deniedPerms) {
        shouldShowRationale = shouldShowRequestPermissionRationale(activity, perm);
        if (!shouldShowRationale) {
            if (null == getActivity(activity)) {
                return true;
            }//  w w w .j  ava 2s . 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(activity, intent);
                        }
                    }).setNegativeButton(negativeButton, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                        }
                    }).create();
            dialog.show();

            return true;
        }
    }

    return false;
}

From source file:com.dm.material.dashboard.candybar.fragments.dialog.AboutFragment.java

@Override
public void onClick(View view) {
    int id = view.getId();
    Intent intent = null;//from  w  w w.  j  a  v  a  2  s .c o m
    if (id == R.id.email) {
        try {
            final Intent email = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto",
                    getActivity().getResources().getString(R.string.about_email), null));
            email.putExtra(Intent.EXTRA_SUBJECT, (getActivity().getResources().getString(R.string.app_name)));
            getActivity().startActivity(
                    Intent.createChooser(email, getActivity().getResources().getString(R.string.email_client)));
            dismiss();
        } catch (ActivityNotFoundException e) {
            Log.d(Tag.LOG_TAG, Log.getStackTraceString(e));
        }
        return;
    } else if (id == R.id.link1) {
        intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse(getActivity().getResources().getString(R.string.about_link_1_url)));
    } else if (id == R.id.link2) {
        intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse(getActivity().getResources().getString(R.string.about_link_2_url)));
    } else if (id == R.id.dev_link1) {
        intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse(getActivity().getResources().getString(R.string.about_dashboard_dev_github_url)));
    } else if (id == R.id.dev_link2) {
        intent = new Intent(Intent.ACTION_VIEW, Uri
                .parse(getActivity().getResources().getString(R.string.about_dashboard_dev_google_plus_url)));
    }

    try {
        getActivity().startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Log.d(Tag.LOG_TAG, Log.getStackTraceString(e));
    }
}