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:org.phillyopen.mytracks.cyclephilly.MainInput.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case MENU_USER_INFO:
        startActivity(new Intent(this, UserInfoActivity.class));
        return true;
    case MENU_CONTACT_US:
        Intent myIntent = new Intent(Intent.ACTION_SENDTO,
                Uri.fromParts("mailto", "cyclephilly@gmail.com", null));

        myIntent.putExtra(Intent.EXTRA_SUBJECT, "Cycle Philly Android App");
        startActivity(Intent.createChooser(myIntent, "Send email..."));
        return true;
    case MENU_MAP:
        startActivity(new Intent(this, ShowMapNearby.class));
        return true;
    case MENU_LEGAL_INFO:
        startActivity(new Intent(this, LicenseActivity.class));
        return true;
    }/*from  w w  w  . jav a 2  s. c om*/
    return false;
}

From source file:com.abcvoipsip.ui.dialpad.DialerFragment.java

@Override
public void placeVMCall() {
    Long accountToUse = SipProfile.INVALID_ID;
    SipProfile acc = null;//from w  ww .j a va 2s. c  om
    acc = accountChooserButton.getSelectedAccount();
    if (acc != null) {
        accountToUse = acc.id;
    }

    if (accountToUse >= 0) {
        SipProfile vmAcc = SipProfile.getProfileFromDbId(getActivity(), acc.id,
                new String[] { SipProfile.FIELD_VOICE_MAIL_NBR });
        if (!TextUtils.isEmpty(vmAcc.vm_nbr)) {
            // Account already have a VM number
            try {
                service.makeCall(vmAcc.vm_nbr, (int) acc.id);
            } catch (RemoteException e) {
                Log.e(THIS_FILE, "Service can't be called to make the call");
            }
        } else {
            // Account has no VM number, propose to create one
            final long editedAccId = acc.id;
            LayoutInflater factory = LayoutInflater.from(getActivity());
            final View textEntryView = factory.inflate(R.layout.alert_dialog_text_entry, null);

            missingVoicemailDialog = new AlertDialog.Builder(getActivity()).setTitle(acc.display_name)
                    .setView(textEntryView)
                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {

                            if (missingVoicemailDialog != null) {
                                TextView tf = (TextView) missingVoicemailDialog.findViewById(R.id.vmfield);
                                if (tf != null) {
                                    String vmNumber = tf.getText().toString();
                                    if (!TextUtils.isEmpty(vmNumber)) {
                                        ContentValues cv = new ContentValues();
                                        cv.put(SipProfile.FIELD_VOICE_MAIL_NBR, vmNumber);

                                        int updated = getActivity().getContentResolver()
                                                .update(ContentUris.withAppendedId(
                                                        SipProfile.ACCOUNT_ID_URI_BASE, editedAccId), cv, null,
                                                        null);
                                        Log.d(THIS_FILE, "Updated accounts " + updated);
                                    }
                                }
                                missingVoicemailDialog.hide();
                            }
                        }
                    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (missingVoicemailDialog != null) {
                                missingVoicemailDialog.hide();
                            }
                        }
                    }).create();

            // When the dialog is up, completely hide the in-call UI
            // underneath (which is in a partially-constructed state).
            missingVoicemailDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

            missingVoicemailDialog.show();
        }
    } else if (accountToUse == CallHandler.getAccountIdForCallHandler(getActivity(),
            "com.abcvoipsip/com.abcvoipsip.plugins.telephony.CallHandler")) {
        // Case gsm voice mail
        TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
        String vmNumber = tm.getVoiceMailNumber();

        if (!TextUtils.isEmpty(vmNumber)) {
            OutgoingCall.ignoreNext = vmNumber;
            Intent intent = new Intent(Intent.ACTION_CALL, Uri.fromParts("tel", vmNumber, null));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        } else {

            missingVoicemailDialog = new AlertDialog.Builder(getActivity()).setTitle(R.string.gsm)
                    .setMessage(R.string.no_voice_mail_configured)
                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            if (missingVoicemailDialog != null) {
                                missingVoicemailDialog.hide();
                            }
                        }
                    }).create();

            // When the dialog is up, completely hide the in-call UI
            // underneath (which is in a partially-constructed state).
            missingVoicemailDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

            missingVoicemailDialog.show();
        }
    }
    // TODO : manage others ?... for now, no way to do so cause no vm stored
}

From source file:com.example.sensorsample.MyActivity.java

/**
 * Callback received when a permissions request has been completed.
 *//*from   w ww . j  a  v a  2  s.c om*/
@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.
            buildApiClient();
        } 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), 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:org.opensmc.mytracks.cyclesmc.MainInput.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case MENU_USER_INFO:
        startActivity(new Intent(this, UserInfoActivity.class));
        return true;
    case MENU_CONTACT_US:
        Intent myIntent = new Intent(Intent.ACTION_SENDTO,
                Uri.fromParts("mailto", "org.opensmc.mytracks.cyclesmc@gmail.com", null));

        myIntent.putExtra(Intent.EXTRA_SUBJECT, String.format("%s Android App", getString(R.string.app_name)));
        startActivity(Intent.createChooser(myIntent, "Send email..."));
        return true;
    /*case MENU_MAP:/* www  .ja v  a2 s .  c om*/
       startActivity(new Intent(this, ShowMapNearby.class));
       return true;*/
    case MENU_LEGAL_INFO:
        startActivity(new Intent(this, LicenseActivity.class));
        return true;
    }
    return false;
}

From source file:com.android.email.activity.MessageView.java

/**
 * Handle clicks on sender, which shows {@link QuickContact} or prompts to add
 * the sender as a contact.//from  ww  w.ja v  a2 s  .  co  m
 */
private void onClickSender() {
    // Bail early if message or sender not present
    if (mMessage == null)
        return;

    final Address senderEmail = Address.unpackFirst(mMessage.mFrom);
    if (senderEmail == null)
        return;

    // First perform lookup query to find existing contact
    final ContentResolver resolver = getContentResolver();
    final String address = senderEmail.getAddress();
    final Uri dataUri = Uri.withAppendedPath(CommonDataKinds.Email.CONTENT_FILTER_URI, Uri.encode(address));
    final Uri lookupUri = ContactsContract.Data.getContactLookupUri(resolver, dataUri);

    if (lookupUri != null) {
        // Found matching contact, trigger QuickContact
        QuickContact.showQuickContact(this, mSenderPresenceView, lookupUri, QuickContact.MODE_LARGE, null);
    } else {
        // No matching contact, ask user to create one
        final Uri mailUri = Uri.fromParts("mailto", address, null);
        final Intent intent = new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT, mailUri);

        // Pass along full E-mail string for possible create dialog
        intent.putExtra(ContactsContract.Intents.EXTRA_CREATE_DESCRIPTION, senderEmail.toString());

        // Only provide personal name hint if we have one
        final String senderPersonal = senderEmail.getPersonal();
        if (!TextUtils.isEmpty(senderPersonal)) {
            intent.putExtra(ContactsContract.Intents.Insert.NAME, senderPersonal);
        }
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);

        startActivity(intent);
    }
}

From source file:com.google.android.gms.fit.samples.basichistorysessions.MainActivity.java

/**
 * Callback received when a permissions request has been completed.
 *///  w  w  w.j  av a  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), 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.google.android.apps.muzei.settings.ChooseSourceFragment.java

private void redrawSources() {
    if (mSourceContainerView == null || !isAdded()) {
        return;/*from  ww w  .ja v a2  s . com*/
    }

    mSourceContainerView.removeAllViews();
    for (final Source source : mSources) {
        source.rootView = LayoutInflater.from(getContext()).inflate(R.layout.settings_choose_source_item,
                mSourceContainerView, false);

        source.selectSourceButton = source.rootView.findViewById(R.id.source_image);
        source.selectSourceButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (source.componentName.equals(mSelectedSource)) {
                    if (getContext() instanceof Callbacks) {
                        ((Callbacks) getContext()).onRequestCloseActivity();
                    } else if (getParentFragment() instanceof Callbacks) {
                        ((Callbacks) getParentFragment()).onRequestCloseActivity();
                    }
                } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
                        && source.targetSdkVersion >= Build.VERSION_CODES.O) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getContext())
                            .setTitle(R.string.action_source_target_too_high_title)
                            .setMessage(R.string.action_source_target_too_high_message)
                            .setNegativeButton(R.string.action_source_target_too_high_learn_more,
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(
                                                    "https://medium.com/@ianhlake/the-muzei-plugin-api-and-androids-evolution-9b9979265cfb")));
                                        }
                                    })
                            .setPositiveButton(R.string.action_source_target_too_high_dismiss, null);
                    final Intent sendFeedbackIntent = new Intent(Intent.ACTION_VIEW,
                            Uri.parse("https://play.google.com/store/apps/details?id="
                                    + source.componentName.getPackageName()));
                    if (sendFeedbackIntent.resolveActivity(getContext().getPackageManager()) != null) {
                        builder.setNeutralButton(
                                getString(R.string.action_source_target_too_high_send_feedback, source.label),
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        startActivity(sendFeedbackIntent);
                                    }
                                });
                    }
                    builder.show();
                } else if (source.setupActivity != null) {
                    Bundle bundle = new Bundle();
                    bundle.putString(FirebaseAnalytics.Param.ITEM_ID,
                            source.componentName.flattenToShortString());
                    bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, source.label);
                    bundle.putString(FirebaseAnalytics.Param.ITEM_CATEGORY, "sources");
                    FirebaseAnalytics.getInstance(getContext()).logEvent(FirebaseAnalytics.Event.VIEW_ITEM,
                            bundle);
                    mCurrentInitialSetupSource = source.componentName;
                    launchSourceSetup(source);
                } else {
                    Bundle bundle = new Bundle();
                    bundle.putString(FirebaseAnalytics.Param.ITEM_ID,
                            source.componentName.flattenToShortString());
                    bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "sources");
                    FirebaseAnalytics.getInstance(getContext()).logEvent(FirebaseAnalytics.Event.SELECT_CONTENT,
                            bundle);
                    SourceManager.selectSource(getContext(), source.componentName);
                }
            }
        });

        source.selectSourceButton.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                final String pkg = source.componentName.getPackageName();
                if (TextUtils.equals(pkg, getContext().getPackageName())) {
                    // Don't open Muzei's app info
                    return false;
                }
                // Otherwise open third party extensions
                try {
                    startActivity(new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
                            Uri.fromParts("package", pkg, null)));
                } catch (final ActivityNotFoundException e) {
                    return false;
                }
                return true;
            }
        });

        float alpha = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
                && source.targetSdkVersion >= Build.VERSION_CODES.O ? ALPHA_DISABLED : ALPHA_UNSELECTED;
        source.rootView.setAlpha(alpha);

        source.icon.setColorFilter(source.color, PorterDuff.Mode.SRC_ATOP);
        source.selectSourceButton.setBackground(source.icon);

        TextView titleView = source.rootView.findViewById(R.id.source_title);
        titleView.setText(source.label);
        titleView.setTextColor(source.color);

        updateSourceStatusUi(source);

        source.settingsButton = source.rootView.findViewById(R.id.source_settings_button);
        TooltipCompat.setTooltipText(source.settingsButton, source.settingsButton.getContentDescription());
        source.settingsButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                launchSourceSettings(source);
            }
        });

        animateSettingsButton(source.settingsButton, false, false);

        mSourceContainerView.addView(source.rootView);
    }

    updateSelectedItem(mCurrentSourceLiveData.getValue(), false);
}

From source file:cm.aptoide.pt.ApkInfo.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
    case 0://  w  w w  . j a v a  2  s .  co m
        Uri uri = Uri.fromParts("package", viewApk.getApkid(), null);
        Intent intent = new Intent(Intent.ACTION_DELETE, uri);
        startActivity(intent);
        finish();
        break;
    case 1:
        Intent i = new Intent();
        i.setAction(android.content.Intent.ACTION_VIEW);
        i.setData(Uri.parse("market://details?id=" + viewApk.getApkid()));
        try {
            startActivity(i);
        } catch (ActivityNotFoundException e) {
            Toast toast = Toast.makeText(context, context.getString(R.string.error_no_market),
                    Toast.LENGTH_SHORT);
            toast.show();
        }
        break;
    default:
        break;
    }

    return true;
}

From source file:cn.suishen.email.activity.MessageViewFragmentBase.java

/**
 * Handle clicks on sender, which shows {@link QuickContact} or prompts to add
 * the sender as a contact./*from  ww w  .  j  a  v  a  2s. c  o  m*/
 */
private void onClickSender() {
    if (!isMessageOpen())
        return;
    final Address senderEmail = Address.unpackFirst(mMessage.mFrom);
    if (senderEmail == null)
        return;

    if (mContactStatusState == CONTACT_STATUS_STATE_UNLOADED) {
        // Status not loaded yet.
        mContactStatusState = CONTACT_STATUS_STATE_UNLOADED_TRIGGERED;
        return;
    }
    if (mContactStatusState == CONTACT_STATUS_STATE_UNLOADED_TRIGGERED) {
        return; // Already clicked, and waiting for the data.
    }

    if (mQuickContactLookupUri != null) {
        QuickContact.showQuickContact(mContext, mFromBadge, mQuickContactLookupUri, QuickContact.MODE_MEDIUM,
                null);
    } else {
        // No matching contact, ask user to create one
        final Uri mailUri = Uri.fromParts("mailto", senderEmail.getAddress(), null);
        final Intent intent = new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT, mailUri);

        // Only provide personal name hint if we have one
        final String senderPersonal = senderEmail.getPersonal();
        if (!TextUtils.isEmpty(senderPersonal)) {
            intent.putExtra(ContactsContract.Intents.Insert.NAME, senderPersonal);
        }
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);

        startActivity(intent);
    }
}

From source file:com.yeldi.yeldibazaar.AppDetails.java

private void removeApk(String id) {
    PackageInfo pkginfo;/*from   w  ww .  ja  va2 s .  c  om*/
    try {
        pkginfo = mPm.getPackageInfo(id, 0);
    } catch (NameNotFoundException e) {
        Log.d("FDroid", "Couldn't find package " + id + " to uninstall.");
        return;
    }
    Uri uri = Uri.fromParts("package", pkginfo.packageName, null);
    Intent intent = new Intent(Intent.ACTION_DELETE, uri);
    startActivityForResult(intent, REQUEST_UNINSTALL);
    ((FDroidApp) getApplication()).invalidateApp(id);

}