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.peptrack.gps.locationupdatesforegroundservice.MainActivity.java

/**
 * Callback received when a permissions request has been completed.
 *//*from ww  w. j a v a 2s.c  o  m*/
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    Log.i(TAG, "onRequestPermissionResult");
    if (requestCode == REQUEST_PERMISSIONS_LOCATION_REQUEST_CODE
            || requestCode == REQUEST_PERMISSIONS_INTERNET_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:com.olearyp.gusto.Expsetup.java

protected void sendCommand(final String command, final String description, final String state) {
    final Intent runCmd = new Intent("com.olearyp.gusto.SUEXEC");
    runCmd.setData(/*  w  w  w.  j a va2s. c  o m*/
            Uri.fromParts("command", ". /system/bin/exp_script.sh.lib && read_in_ep_config && " + command, ""))
            .putExtra("com.olearyp.gusto.STATE", state);
    final Notification note = new Notification(R.drawable.icon,
            description.substring(0, 1).toUpperCase() + description.substring(1) + "...",
            System.currentTimeMillis());
    note.setLatestEventInfo(Expsetup.this, getString(R.string.app_name),
            getString(R.string.app_name) + " is " + description + "...",
            PendingIntent.getBroadcast(Expsetup.this, 0, null, 0));
    runCmd.putExtra("com.olearyp.gusto.RUN_NOTIFICATION", note);
    startService(runCmd);
    setServerState(state);
    if (getServerState().equals(getString(R.string.reboot_manual_flash_required))) {
        final Intent intent = new Intent("com.olearyp.gusto.SUEXEC")
                .setData(Uri.fromParts("commandid", Integer.toString(R.string.reboot_recovery), ""));
        final PendingIntent contentIntent = PendingIntent.getService(this, 0, intent, 0);
        final Notification rebootNote = new Notification(R.drawable.status_reboot,
                getString(R.string.reboot_recovery_required_msg), System.currentTimeMillis());
        rebootNote.setLatestEventInfo(this, "GUSTO reboot request",
                getString(R.string.reboot_recovery_doit_msg), contentIntent);
        rebootNote.deleteIntent = PendingIntent.getBroadcast(this, 0,
                new Intent("com.olearyp.gusto.RESET_SERVER_STATE"), 0);
        rebootNote.flags |= Notification.FLAG_SHOW_LIGHTS;
        rebootNote.ledOnMS = 200;
        rebootNote.ledOffMS = 400;
        rebootNote.ledARGB = Color.argb(255, 255, 0, 0);
        nm.notify(REBOOT_NOTIFICATION, rebootNote);
    } else if (getServerState().equals(getString(R.string.reboot_recovery_required))) {
        final Intent intent = new Intent("com.olearyp.gusto.SUEXEC")
                .setData(Uri.fromParts("commandid", Integer.toString(R.string.reboot), ""));
        final PendingIntent contentIntent = PendingIntent.getService(this, 0, intent, 0);
        final Notification rebootNote = new Notification(R.drawable.status_reboot,
                getString(R.string.reboot_autoflash_required_msg), System.currentTimeMillis());
        rebootNote.setLatestEventInfo(this, "GUSTO reboot request",
                getString(R.string.reboot_autoflash_doit_msg), contentIntent);
        rebootNote.deleteIntent = PendingIntent.getBroadcast(this, 0,
                new Intent("com.olearyp.gusto.RESET_SERVER_STATE"), 0);
        rebootNote.flags |= Notification.FLAG_SHOW_LIGHTS;
        rebootNote.ledOnMS = 200;
        rebootNote.ledOffMS = 600;
        rebootNote.ledARGB = Color.argb(255, 255, 255, 0);
        nm.notify(REBOOT_NOTIFICATION, rebootNote);
    } else if (getServerState().equals(getString(R.string.reboot_required))) {
        final Intent intent = new Intent("com.olearyp.gusto.SUEXEC")
                .setData(Uri.fromParts("commandid", Integer.toString(R.string.reboot), ""));
        final PendingIntent contentIntent = PendingIntent.getService(this, 0, intent, 0);
        final Notification rebootNote = new Notification(R.drawable.status_reboot,
                getString(R.string.reboot_required_msg), System.currentTimeMillis());
        rebootNote.setLatestEventInfo(this, "GUSTO reboot request", getString(R.string.reboot_doit_msg),
                contentIntent);
        rebootNote.deleteIntent = PendingIntent.getBroadcast(this, 0,
                new Intent("com.olearyp.gusto.RESET_SERVER_STATE"), 0);
        rebootNote.flags |= Notification.FLAG_SHOW_LIGHTS;
        rebootNote.ledOnMS = 200;
        rebootNote.ledOffMS = 600;
        rebootNote.ledARGB = Color.argb(255, 255, 255, 0);
        nm.notify(REBOOT_NOTIFICATION, rebootNote);
    }
}

From source file:com.tasomaniac.openwith.resolver.ResolverActivity.java

@SuppressWarnings("deprecation")
void showAppDetails(ResolveInfo ri) {
    Intent in = new Intent().setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
            .setData(Uri.fromParts("package", ri.activityInfo.packageName, null))
            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    startActivity(in);//from  w  w w .j a va 2  s.  c o  m
}

From source file:ac.robinson.ticqr.TicQRActivity.java

private void sendOrder() {
    try {//from w w w.ja va2s.  c o  m
        Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
                Uri.fromParts("mailto", TextUtils.isEmpty(mDestinationEmail) ? "" : mDestinationEmail, null));
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.email_subject));
        emailIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.email_body, mEmailContents));
        startActivity(Intent.createChooser(emailIntent, getString(R.string.email_prompt)));
    } catch (ActivityNotFoundException e) {
        // copy to clipboard instead if no email client found
        String clipboardText = getString(R.string.email_backup_sender,
                TextUtils.isEmpty(mDestinationEmail) ? "" : mDestinationEmail,
                getString(R.string.email_body, mEmailContents));

        // see: http://stackoverflow.com/a/11012443
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            @SuppressLint("ServiceCast")
            @SuppressWarnings("deprecation")
            android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(
                    Context.CLIPBOARD_SERVICE);
            clipboard.setText(clipboardText);
        } else {
            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                    Context.CLIPBOARD_SERVICE);
            android.content.ClipData clip = android.content.ClipData
                    .newPlainText(getString(R.string.email_subject), clipboardText);
            clipboard.setPrimaryClip(clip);
        }

        Toast.makeText(TicQRActivity.this, getString(R.string.hint_no_email_client), Toast.LENGTH_LONG).show();
    }
}

From source file:ac.robinson.bettertogether.ConnectionSetupActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[],
        @NonNull int[] grantResults) {
    switch (requestCode) {
    case CAMERA_PERMISSION_RESULT:
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            restartCaptureManager();//from   w  w  w.j  av  a  2s  . c  om
        } else {
            AlertDialog.Builder builder = new AlertDialog.Builder(ConnectionSetupActivity.this);
            builder.setTitle(R.string.title_camera_access);
            builder.setMessage(R.string.hint_enable_camera_access);
            builder.setPositiveButton(R.string.hint_edit_permissions, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Intent intent = new Intent();
                    intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                    intent.setData(
                            Uri.fromParts("package", ConnectionSetupActivity.this.getPackageName(), null));
                    try {
                        startActivity(intent);
                    } catch (ActivityNotFoundException e) {
                        // we've tried everything by this point!
                        Log.d(TAG,
                                "Camera permission denied and request failed - will not be able to scan codes");
                        Toast.makeText(ConnectionSetupActivity.this, R.string.error_accessing_camera,
                                Toast.LENGTH_LONG).show();
                    }
                    restartCaptureManager();
                }
            });
            builder.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Toast.makeText(ConnectionSetupActivity.this, R.string.error_accessing_location,
                            Toast.LENGTH_LONG).show();
                    restartCaptureManager(); // reset capture UI and try again
                }
            });
            builder.show();
        }
        break;

    case COARSE_LOCATION_PERMISSION_RESULT:
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            createClient();
        } else {
            AlertDialog.Builder builder = new AlertDialog.Builder(ConnectionSetupActivity.this);
            builder.setTitle(R.string.title_coarse_location_access);
            builder.setMessage(R.string.hint_enable_coarse_location_access);
            builder.setPositiveButton(R.string.hint_edit_permissions, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Intent intent = new Intent();
                    intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                    intent.setData(
                            Uri.fromParts("package", ConnectionSetupActivity.this.getPackageName(), null));
                    try {
                        startActivity(intent);
                    } catch (ActivityNotFoundException e) {
                        // we've tried everything by this point!
                        Log.d(TAG,
                                "Coarse location permission denied and request failed - will not be able to connect");
                        Toast.makeText(ConnectionSetupActivity.this, R.string.error_accessing_location,
                                Toast.LENGTH_LONG).show();
                    }
                    restartCaptureManager();
                }
            });
            builder.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Toast.makeText(ConnectionSetupActivity.this, R.string.error_accessing_location,
                            Toast.LENGTH_LONG).show();
                    restartCaptureManager(); // reset capture UI and try again
                }
            });
            builder.show();
        }
        break;

    default:
        if (mCaptureManager != null && requestCode == CaptureManager.getCameraPermissionReqCode()) {
            // ignored - CaptureManager's default is to exit on permission denial, so we handle permissions ourselves
            // mCaptureManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
        }
        break;
    }
}

From source file:net.nym.napply.library.common.NBasePermissionActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    if (verifyPermissions(grantResults)) {
        switch (requestCode) {
        case REQUEST_CAMERA:
            // Camera permission has been granted, preview can be displayed
            showCamera();/*from   w  ww  . j a va2  s .  c o  m*/
            break;
        case REQUEST_CONTACTS:
            showContacts();
            break;
        case REQUEST_CALENDAR:
            showCalendar();
            break;
        case REQUEST_LOCATION:
            showLocation();
            break;
        case REQUEST_STORAGE:
            showStorage();
            break;
        case REQUEST_MICROPHONE:
            showMicrophone();
            break;
        case REQUEST_SENSORS:
            showSensors();
            break;
        case REQUEST_PHONE:
            showPhone();
            break;
        case REQUEST_SMS:
            showSms();
            break;
        case REQUEST_CAMERA_AND_STORAGE:
            showCameraAndStorage();
            break;

        default:
            super.onRequestPermissionsResult(requestCode, permissions, grantResults);
            break;
        }

    } else {

        //                    Log.i(TAG, "CAMERA permission was NOT granted.");
        Log.i("???%s", Arrays.toString(permissions));
        String permission = "";
        switch (requestCode) {
        case REQUEST_CAMERA:
            permission = "?";
            break;
        case REQUEST_CONTACTS:
            permission = "";
            break;
        case REQUEST_CALENDAR:
            permission = "";
            break;
        case REQUEST_LOCATION:
            permission = "??";
            break;
        case REQUEST_STORAGE:
            permission = "";
            break;
        case REQUEST_MICROPHONE:
            permission = "";
            break;
        case REQUEST_SENSORS:
            permission = "";
            break;
        case REQUEST_PHONE:
            permission = "?";
            break;
        case REQUEST_SMS:
            permission = "";
            break;
        case REQUEST_CAMERA_AND_STORAGE:
            permission = "?";
            break;
        default:
            super.onRequestPermissionsResult(requestCode, permissions, grantResults);
            break;
        }

        final Dialog dialog = new AlertDialog.Builder(this).setTitle(R.string.napply_hint)
                .setMessage(String.format("?%s", permission))
                .setNegativeButton(R.string.napply_cancel, null)
                .setPositiveButton(R.string.napply_toSet, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent();
                        intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                        Uri uri = Uri.fromParts("package", getApplicationInfo().packageName, null);
                        intent.setData(uri);
                        startActivity(intent);
                    }
                }).create();
        dialog.show();
    }

}

From source file:com.birdeye.MainActivity.java

@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {

    switch (item.getItemId()) {
    case R.id.logout:

        fullReset();/*from w  ww  .j  a  va  2  s.co m*/
        startActivity(LoginActivity.create(this));
        finish();

        return true;

    case R.id.About:

        final Dialog dialog2 = new Dialog(MainActivity.this);
        dialog2.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog2.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
        dialog2.setContentView(R.layout.about);
        dialog2.setCancelable(false);

        dialog2.show();

        return true;

    case R.id.ShareApp:

        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setType("text/html");
        sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(
                "<p>Hey, am using this really cool hashtag activated camera app. Get it here #birdeyecamera.</p>"));
        startActivity(Intent.createChooser(sharingIntent, "Share using"));

        return true;

    case R.id.Recommend:

        Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
                Uri.fromParts("BirdEyeCamera", "birdeyecamera@digitalbabi.es", null));
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Feature Recommendation");
        startActivity(Intent.createChooser(emailIntent, "Send email..."));

        return true;

    case R.id.rateApp:

        final Uri uri = Uri.parse("market://details?id=" + getApplicationContext().getPackageName());
        final Intent rateAppIntent = new Intent(Intent.ACTION_VIEW, uri);

        if (getPackageManager().queryIntentActivities(rateAppIntent, 0).size() > 0) {
            startActivity(rateAppIntent);
        } else {
            /* handle your error case: the device has no way to handle market urls */
        }

        return true;

    case R.id.RemoveAds:

        if (Globals.hasPaid) {
            Toast.makeText(MainActivity.this, "You already are in a premium account", Toast.LENGTH_SHORT)
                    .show();

        } else {

            removeAdsDialog();

        }

        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.barbrdo.app.activities.SignUpActivity.java

@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) {
            Log.i(TAG, "User interaction was cancelled.");
        } else if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            if (mRequestingLocationUpdates) {
                Log.i(TAG, "Permission granted, updates requested, starting location updates");
                startLocationUpdates();//w w  w.  j a v  a  2 s . c  om
            }
        } else {
            showSnackBar(R.string.permission_denied_explanation, R.string.settings, new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    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);
                }
            });
            return;
        }
    }
}

From source file:org.ale.openwatch.FeedFragmentActivity.java

private void selectItem(View v, int position) {
    // Highlight the selected item, update the title, and close the drawer
    mDrawerList.setItemChecked(position, true);
    String tag = ((TextView) v.findViewById(R.id.title)).getText().toString().replace("# ", "");
    if (mTitleToTabId.containsKey(tag)) {
        mTitleIndicator.setCurrentItem(mTitleToTabId.get(tag));
    } else if (v.getTag(R.id.list_item_model) != null
            && ((String) v.getTag(R.id.list_item_model)).compareTo("divider") == 0) {
        return;//from  w w w.  ja v a2 s  .com
    } else if (mTitleToTabId.containsKey(v.getTag(R.id.list_item_model))) {
        mTitleIndicator.setCurrentItem(mTitleToTabId.get((String) v.getTag(R.id.list_item_model)));
    } else {
        if (tag.compareTo("Settings") == 0) {
            Intent i = new Intent(this, SettingsActivity.class);
            startActivity(i);
        } else if (tag.compareTo("Send Feedback") == 0) {
            Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
                    Uri.fromParts("mailto", Constants.SUPPORT_EMAIL, null));
            emailIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_email_subject));
            emailIntent.putExtra(Intent.EXTRA_TEXT,
                    getString(R.string.share_email_text) + OWUtils.getPackageVersion(getApplicationContext()));
            startActivity(Intent.createChooser(emailIntent, getString(R.string.share_chooser_title)));
        } else if (tag.compareTo("Profile") == 0) {
            Intent profileIntent = new Intent(this, OWProfileActivity.class);
            startActivity(profileIntent);
        }
    }

    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:com.chhavi.envisionproductivity.FitnessActivity.java

/**
 * Callback received when a permissions request has been completed.
 *//*  w w  w  .  ja  va  2  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.
            buildFitnessClient();
        } else {
            // Permission denied.

            // In this Activity we've chosen to notify the user that they
            // have rejected a core permission for the app since it makes the Activity useless.
            // We're communicating this message in a Snackbar since this is a sample app, but
            // core permissions would typically be best requested during a welcome-screen flow.

            // Additionally, it is important to remember that a permission might have been
            // rejected without asking the user for permission (device policy or "Never ask
            // again" prompts). Therefore, a user interface affordance is typically implemented
            // when permissions are denied. Otherwise, your app could appear unresponsive to
            // touches or interactions which have required permissions.
            Snackbar.make(findViewById(R.id.main_activity_view), "Permission denied", Snackbar.LENGTH_LONG)
                    .setAction("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();
        }
    }
}