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.deviceconnect.android.manager.setting.DevicePluginInfoFragment.java

/**
 * Open uninstall dialog.//w ww  .ja  v  a2 s  .com
 */
private void openUninstall() {
    Uri uri = Uri.fromParts("package", mPluginInfo.getPackageName(), null);
    Intent intent = new Intent(Intent.ACTION_DELETE, uri);
    startActivityForResult(intent, REQUEST_CODE);
}

From source file:org.telegram.ui.ContactsActivity.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (fragmentView == null) {

        fragmentView = inflater.inflate(R.layout.contacts_layout, container, false);

        epmtyTextView = (TextView) fragmentView.findViewById(R.id.searchEmptyView);
        searchListViewAdapter = new SearchAdapter(parentActivity);

        listView = (PinnedHeaderListView) fragmentView.findViewById(R.id.listView);
        listView.setEmptyView(epmtyTextView);
        listView.setVerticalScrollBarEnabled(false);

        listView.setAdapter(listViewAdapter = new ListAdapter(parentActivity));
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override/*from   ww  w.  ja v a2s  .  c  o m*/
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                if (searching && searchWas) {
                    TLRPC.User user = searchResult.get(i);
                    if (user.id == UserConfig.clientUserId) {
                        return;
                    }
                    if (returnAsResult) {
                        if (ignoreUsers != null && ignoreUsers.containsKey(user.id)) {
                            return;
                        }
                        didSelectResult(user, true);
                    } else {
                        if (createSecretChat) {
                            creatingChat = true;
                            MessagesController.Instance.startSecretChat(parentActivity, user);
                        } else {
                            ChatActivity fragment = new ChatActivity();
                            Bundle bundle = new Bundle();
                            bundle.putInt("user_id", user.id);
                            fragment.setArguments(bundle);
                            ((ApplicationActivity) parentActivity).presentFragment(fragment,
                                    "chat" + Math.random(), destroyAfterSelect, false);
                        }
                    }
                } else {
                    int section = listViewAdapter.getSectionForPosition(i);
                    int row = listViewAdapter.getPositionInSectionForPosition(i);
                    if (row < 0 || section < 0) {
                        return;
                    }
                    TLRPC.User user = null;
                    if (usersAsSections) {
                        if (section < ContactsController.Instance.sortedUsersSectionsArray.size()) {
                            ArrayList<TLRPC.TL_contact> arr = ContactsController.Instance.usersSectionsDict
                                    .get(ContactsController.Instance.sortedUsersSectionsArray.get(section));
                            if (row < arr.size()) {
                                TLRPC.TL_contact contact = arr.get(row);
                                user = MessagesController.Instance.users.get(contact.user_id);
                            } else {
                                return;
                            }

                        }
                    } else {
                        if (section == 0) {
                            if (row == 0) {
                                try {
                                    Intent intent = new Intent(Intent.ACTION_SEND);
                                    intent.setType("text/plain");
                                    intent.putExtra(Intent.EXTRA_TEXT, inviteText != null ? inviteText
                                            : getStringEntry(R.string.InviteText));
                                    startActivity(intent);
                                } catch (Exception e) {
                                    FileLog.e("tmessages", e);
                                }
                                return;
                            } else {
                                if (row - 1 < ContactsController.Instance.contacts.size()) {
                                    user = MessagesController.Instance.users
                                            .get(ContactsController.Instance.contacts.get(row - 1).user_id);
                                } else {
                                    return;
                                }
                            }
                        }
                    }

                    if (user != null) {
                        if (user.id == UserConfig.clientUserId) {
                            return;
                        }
                        if (returnAsResult) {
                            if (ignoreUsers != null && ignoreUsers.containsKey(user.id)) {
                                return;
                            }
                            didSelectResult(user, true);
                        } else {
                            if (createSecretChat) {
                                creatingChat = true;
                                MessagesController.Instance.startSecretChat(parentActivity, user);
                            } else {
                                ChatActivity fragment = new ChatActivity();
                                Bundle bundle = new Bundle();
                                bundle.putInt("user_id", user.id);
                                fragment.setArguments(bundle);
                                ((ApplicationActivity) parentActivity).presentFragment(fragment,
                                        "chat" + Math.random(), destroyAfterSelect, false);
                            }
                        }
                    } else {
                        ArrayList<ContactsController.Contact> arr = ContactsController.Instance.contactsSectionsDict
                                .get(ContactsController.Instance.sortedContactsSectionsArray.get(section - 1));
                        ContactsController.Contact contact = arr.get(row);
                        String usePhone = null;
                        if (!contact.phones.isEmpty()) {
                            usePhone = contact.phones.get(0);
                        }
                        if (usePhone == null) {
                            return;
                        }
                        AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
                        builder.setMessage(getStringEntry(R.string.InviteUser));
                        builder.setTitle(getStringEntry(R.string.AppName));
                        final String arg1 = usePhone;
                        builder.setPositiveButton(getStringEntry(R.string.OK),
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialogInterface, int i) {
                                        try {
                                            Intent intent = new Intent(Intent.ACTION_VIEW,
                                                    Uri.fromParts("sms", arg1, null));
                                            intent.putExtra("sms_body", getStringEntry(R.string.InviteText));
                                            startActivity(intent);
                                        } catch (Exception e) {
                                            FileLog.e("tmessages", e);
                                        }
                                    }
                                });
                        builder.setNegativeButton(getStringEntry(R.string.Cancel), null);
                        builder.show().setCanceledOnTouchOutside(true);
                    }
                }
            }
        });

        listView.setOnTouchListener(new OnSwipeTouchListener() {
            public void onSwipeRight() {
                finishFragment(true);
                if (searchItem != null) {
                    if (searchItem.isActionViewExpanded()) {
                        searchItem.collapseActionView();
                    }
                }
            }
        });
        epmtyTextView.setOnTouchListener(new OnSwipeTouchListener() {
            public void onSwipeRight() {
                finishFragment(true);
                if (searchItem != null) {
                    if (searchItem.isActionViewExpanded()) {
                        searchItem.collapseActionView();
                    }
                }
            }
        });
    } else {
        ViewGroup parent = (ViewGroup) fragmentView.getParent();
        if (parent != null) {
            parent.removeView(fragmentView);
        }
    }
    return fragmentView;
}

From source file:net.networksaremadeofstring.rhybudd.ViewZenossEventsListActivity.java

private void ProcessDrawerClick(int position) {
    switch (position) {
    case SETTINGS: {
        try {//from  ww  w.j a v a2 s  .c om
            Intent SettingsIntent = new Intent(ViewZenossEventsListActivity.this, SettingsFragment.class);
            this.startActivityForResult(SettingsIntent, 99);
        } catch (Exception e) {
            BugSenseHandler.sendExceptionMessage("ViewZenossEventsListActivity", "ProcessDrawerClick settings",
                    e);
        }

    }
        break;

    case CONFIGURERHYBUDDPUSH: {
        try {
            Intent PushSettingsIntent = new Intent(ViewZenossEventsListActivity.this, PushConfigActivity.class);
            this.startActivityForResult(PushSettingsIntent, ZenossAPI.ACTIVITYRESULT_PUSHCONFIG);
        } catch (Exception e) {
            BugSenseHandler.sendExceptionMessage("ViewZenossEventsListActivity",
                    "ProcessDrawerClick CONFIGURERHYBUDDPUSH", e);
        }
    }
        break;

    case HELP: {
        try {
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse("http://wiki.zenoss.org/Android"));
            startActivity(i);
        } catch (Exception e) {
            BugSenseHandler.sendExceptionMessage("ViewZenossEventsListActivity", "ProcessDrawerClick HELP", e);
        }

    }
        break;

    case INFRASTRUCTURE: {
        try {
            Intent DeviceList = new Intent(ViewZenossEventsListActivity.this,
                    ViewZenossDeviceListActivity.class);
            ViewZenossEventsListActivity.this.startActivity(DeviceList);
        } catch (Exception e) {
            BugSenseHandler.sendExceptionMessage("ViewZenossEventsListActivity",
                    "ProcessDrawerClick INFRASTRUCTURE", e);
        }
    }
        break;

    case GROUPS: {
        try {
            Intent GroupsIntent = new Intent(ViewZenossEventsListActivity.this, ViewZenossGroupsActivity.class);
            ViewZenossEventsListActivity.this.startActivity(GroupsIntent);
        } catch (Exception e) {
            BugSenseHandler.sendExceptionMessage("ViewZenossEventsListActivity", "ProcessDrawerClick GROUPS",
                    e);
        }
    }
        break;

    case MANAGEDATABASE: {
        try {
            Intent MangeDBIntent = new Intent(ViewZenossEventsListActivity.this, ManageDatabase.class);
            ViewZenossEventsListActivity.this.startActivity(MangeDBIntent);
        } catch (Exception e) {
            BugSenseHandler.sendExceptionMessage("ViewZenossEventsListActivity",
                    "ProcessDrawerClick MANAGEDATABASE", e);
        }
    }
        break;

    case FEEDBACK: {
        try {
            Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
                    Uri.fromParts("mailto", "Gareth@DataSift.com", null));
            emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback suggestion for Rhybudd");
            startActivity(Intent.createChooser(emailIntent, "Send feedback as email"));
        } catch (Exception e) {
            BugSenseHandler.sendExceptionMessage("ViewZenossEventsListActivity", "ProcessDrawerClick FEEDBACK",
                    e);

            try {
                Toast.makeText(ViewZenossEventsListActivity.this,
                        "There was a problem launching your email client.\n\nPlease email Gareth@DataSift.com with your feedback.",
                        Toast.LENGTH_LONG).show();
            } catch (Exception e1) {
                BugSenseHandler.sendExceptionMessage("ViewZenossEventsListActivity",
                        "ProcessDrawerClick FEEDBACK Toast", e1);
            }

        }
    }
        break;

    case SEARCH: {
        try {
            onSearchRequested();
        } catch (Exception e) {
            BugSenseHandler.sendExceptionMessage("ViewZenossEventsListActivity", "ProcessDrawerClick SEARCH",
                    e);
        }
    }
        break;

    case DIAGNOSTIC: {
        try {
            Intent DiagIntent = new Intent(ViewZenossEventsListActivity.this, DiagnosticActivity.class);
            ViewZenossEventsListActivity.this.startActivity(DiagIntent);
        } catch (Exception e) {
            BugSenseHandler.sendExceptionMessage("ViewZenossEventsListActivity",
                    "ProcessDrawerClick DIAGNOSTIC", e);
        }
    }
        break;
    }

    // update selected item and title, then close the drawer
    try {
        mDrawerList.setItemChecked(position, false);
    } catch (Exception e) {
        BugSenseHandler.sendExceptionMessage("ViewZenossEventsListActivity",
                "ProcessDrawerClick setitemchecked false", e);
    }

    try {
        mDrawerLayout.closeDrawer(mDrawerList);
    } catch (Exception e) {
        BugSenseHandler.sendExceptionMessage("ViewZenossEventsListActivity", "ProcessDrawerClick closeDrawer",
                e);
    }
}

From source file:com.tfc.webviewer.ui.WebViewerActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    if (PermissionUtils.REQUEST_PERMISSION_WRITE_EXTERNAL_STORAGE == requestCode) {
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            mLastDownloadId = FileUtils.downloadFile(this, mDownloadUrl, mDownloadMimetype);
        } else {/*  w  ww.  j  a  v a 2  s  .  c  o  m*/
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if (!shouldShowRequestPermissionRationale(permissions[0])) {
                    new AlertDialog.Builder(WebViewerActivity.this)
                            .setTitle(R.string.write_permission_denied_title)
                            .setMessage(R.string.write_permission_denied_message)
                            .setNegativeButton(R.string.dialog_dismiss, null)
                            .setPositiveButton(R.string.dialog_settings, 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", getPackageName(), null);
                                    intent.setData(uri);
                                    startActivityForResult(intent, REQUEST_PERMISSION_SETTING);
                                }
                            }).show();
                }
            }
        }
    }
}

From source file:com.base.utils.permission.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/>// ww w  . ja v  a  2 s.co  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).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;
}

From source file:com.scrachx.foodfacts.checker.ui.main.MainActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[],
        @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    switch (requestCode) {
    case PermissionUtils.MY_PERMISSIONS_REQUEST_CAMERA: {
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            startActivity(ScannerActivity.getStartIntent(this));
        } else {/*  w ww.j  a  va 2 s  .c  o m*/
            new MaterialDialog.Builder(this).title(R.string.permission_title)
                    .content(R.string.permission_denied).negativeText(R.string.txt_no)
                    .positiveText(R.string.txt_yes).onPositive((dialog, which) -> {
                        Intent intent = new Intent();
                        intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                        Uri uri = Uri.fromParts("package", getPackageName(), null);
                        intent.setData(uri);
                        startActivity(intent);
                    }).show();
        }
        break;
    }
    }
}

From source file:com.tml.sharethem.sender.SHAREthemActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    switch (requestCode) {
    case PERMISSIONS_REQUEST_CODE_ACCESS_COARSE_LOCATION:
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            enableAp();//  w ww . j  av  a  2  s .  co m
        } else {
            if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                    Manifest.permission.ACCESS_COARSE_LOCATION)) {
                showMessageDialogWithListner(getString(R.string.p2p_receiver_gps_permission_warning),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                checkLocationPermission();
                            }
                        }, true, true);
            } else {
                showMessageDialogWithListner(getString(R.string.p2p_receiver_gps_no_permission_prompt),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                try {
                                    Intent intent = new Intent();
                                    intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                                    Uri uri = Uri.fromParts("package", getPackageName(), null);
                                    intent.setData(uri);
                                    startActivity(intent);
                                } catch (ActivityNotFoundException anf) {
                                    Toast.makeText(getApplicationContext(), "Settings activity not found",
                                            Toast.LENGTH_SHORT).show();
                                }
                            }
                        }, true, true);
            }
        }
    }
}

From source file:com.silentcircle.silenttext.util.DeviceUtils.java

public static Intent getShareDebugInformationIntent(Context context) {

    Intent intent = new Intent(Intent.ACTION_SENDTO,
            Uri.fromParts("mailto", context.getString(R.string.support_email_address), null));

    intent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.support_email_subject));
    intent.putExtra(Intent.EXTRA_TEXT, wrap(LABEL_DEBUG_INFO, getDebugInformation(context)));

    ResolveInfo info = context.getPackageManager().resolveActivity(intent, 0);

    if (info == null) {
        intent.setAction(Intent.ACTION_SEND);
        intent.setDataAndType(null, "text/plain");
    }// ww  w .  j ava  2 s.  co m

    return Intent.createChooser(intent,
            context.getString(R.string.share_with, context.getString(R.string.feedback)));

}

From source file:com.samsung.richnotification.RichNotificationHelper.java

public static List<SrnAction> createActions(Context mContext, CallbackContext callbackContext,
        RichNotificationOptions options) throws JSONException {
    ArrayList<SrnAction> actionsList = new ArrayList<SrnAction>();
    JSONArray actions = options.actions;
    if (actions == null)
        return null;

    SrnAction action = null;//w  ww . ja  v  a 2  s.c  o m
    for (int i = 0; i < actions.length(); i++) {
        JSONObject act = actions.optJSONObject(i);
        if (act == null)
            continue;

        String actionLabel = act.optString("actionLabel", EMPTY_STRING);
        if (actionLabel.isEmpty())
            continue;

        Bitmap actionIcon = getIconBitmap(mContext, "file://" + act.optString("actionIcon"));
        SrnImageAsset actionImg = new SrnImageAsset(mContext, actionLabel, actionIcon);

        int actionType = act.optInt("type");
        switch (actionType) {

        case ACTION_TYPE_CALL:
            SrnRemoteBuiltInAction call = new SrnRemoteBuiltInAction(actionLabel, OperationType.CALL);
            call.setData(Uri.parse(act.optString("dest")));
            action = call;
            break;
        case ACTION_TYPE_SMS:
            SrnRemoteBuiltInAction sms = new SrnRemoteBuiltInAction(actionLabel, OperationType.SMS);
            sms.setData(Uri.fromParts("sms", act.optString("dest"), null));
            action = sms;
            break;
        case ACTION_TYPE_EMAIL:
            Log.d(TAG, "Email to: '" + act.optString("dest") + "'");
            Log.d(TAG, "Subject: '" + act.optString("subject") + "'");
            Log.d(TAG, "Body: '" + act.optString("body") + "'");

            SrnHostAction email = new SrnHostAction(actionLabel);
            Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
            String uriText = "mailto:" + act.optString("dest") + "?subject="
                    + Uri.encode(act.optString("subject")) + "&body=" + Uri.encode(act.optString("body"));
            Uri uri = Uri.parse(uriText);
            emailIntent.setData(uri);
            email.setCallbackIntent(CallbackIntent.getActivityCallback(emailIntent));
            email.setToast(act.optString("toast"));
            email.setIcon(actionImg);
            action = email;
            break;
        case ACTION_TYPE_VIEW:
            SrnHostAction view = new SrnHostAction(actionLabel);
            Intent viewIntent = new Intent(Intent.ACTION_VIEW);
            String urlText = act.optString("dest");
            Uri url = Uri.parse(urlText);
            viewIntent.setData(url);
            view.setCallbackIntent(CallbackIntent.getActivityCallback(viewIntent));
            view.setToast(act.optString("toast"));
            view.setIcon(actionImg);
            action = view;
            break;
        case ACTION_TYPE_INPUT_KEYBOARD:
        case ACTION_TYPE_INPUT_SINGLE_SELECT:
        case ACTION_TYPE_INPUT_MULTI_SELECT:
            SrnRemoteInputAction input = getRemoteInputAction(mContext, act);
            if (input == null) {
                continue;
            }

            Intent inputIntent = new Intent("com.samsung.cordova.richnotification.remote_input_receiver");
            inputIntent.putExtra("callbackID", callbackContext.getCallbackId());
            String actionID = act.optString("actionID", EMPTY_STRING);
            if (actionID.isEmpty()) {
                continue;
            } else {
                inputIntent.putExtra("actionID", actionID);
            }
            input.setCallbackIntent(CallbackIntent.getBroadcastCallback(inputIntent));
            input.setIcon(actionImg);
            action = input;
            break;
        default:
            Log.e(TAG, "Invalid action type: " + actionType);
            continue;
        }

        Log.d(TAG, "Action type created: " + actionType);
        actionsList.add(action);
    }

    return actionsList;
}

From source file:de.appplant.cordova.emailcomposer.EmailComposerImpl.java

/**
 * If email apps are available.//from w ww  .j  ava2 s .c  om
 *
 * @param ctx
 * The application context.
 * @return
 * true if available, otherwise false
 */
private boolean isEmailAccountConfigured(Context ctx) {
    Uri uri = Uri.fromParts("mailto", "max@mustermann.com", null);
    Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
    PackageManager pm = ctx.getPackageManager();
    int apps = pm.queryIntentActivities(intent, 0).size();

    if (apps == 0) {
        return false;
    }

    AccountManager am = AccountManager.get(ctx);
    int accounts;

    try {
        accounts = am.getAccounts().length;
    } catch (Exception e) {
        Log.e("EmailComposer", "Missing GET_ACCOUNTS permission.");
        return true;
    }

    return accounts > 0;
}