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:saschpe.birthdays.fragment.SocialFragment.java

/**
 * Called immediately after {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}
 * has returned, but before any saved state has been restored in to the view.
 * This gives subclasses a chance to initialize themselves once
 * they know their view hierarchy has been completely created.  The fragment's
 * view hierarchy is not however attached to its parent at this point.
 *
 * @param view               The View returned by {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}.
 * @param savedInstanceState If non-null, this fragment is being re-constructed
 *//*from w w w.  j a  v a 2  s .co  m*/
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    provideFeedback.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String subject = getString(R.string.feedback_mail_subject_template, getString(R.string.app_name));

            Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
                    Uri.fromParts("mailto", SUPPORT_EMAIL_ADDRESS[0], null))
                            .putExtra(Intent.EXTRA_SUBJECT, subject).putExtra(Intent.EXTRA_TEXT, "")
                            .putExtra(Intent.EXTRA_EMAIL, SUPPORT_EMAIL_ADDRESS);
            startActivity(Intent.createChooser(emailIntent, view.getContext().getString(R.string.send_email)));
        }
    });
    followTwitter.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            try {
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("twitter://user?screen_name=" + TWITTER_NAME)));
            } catch (ActivityNotFoundException e) {
                startActivity(
                        new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/#!/" + TWITTER_NAME)));
            }
        }
    });
    rateOnPlayStore.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // To count with Play market back stack, After pressing back button,
            // to taken back to our application, we need to add following flags to intent.
            int flags = Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
            if (Build.VERSION.SDK_INT >= 21) {
                flags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
            } else {
                //noinspection deprecation
                flags |= Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET;
            }
            Intent goToMarket = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageName))
                    .addFlags(flags);
            try {
                startActivity(goToMarket);
            } catch (ActivityNotFoundException e) {
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("http://play.google.com/store/apps/details?id=" + packageName)));
            }
        }
    });
    recommendToFriend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String subject = getString(R.string.get_app_template, getString(R.string.app_name));
            String body = Uri.parse("http://play.google.com/store/apps/details?id=" + packageName).toString();

            Intent sharingIntent = new Intent(Intent.ACTION_SEND).setType("text/plain")
                    .putExtra(Intent.EXTRA_SUBJECT, subject).putExtra(Intent.EXTRA_TEXT, body);
            startActivity(Intent.createChooser(sharingIntent, view.getContext().getString(R.string.share_via)));
        }
    });
    forkOnGithub.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(Intent.ACTION_VIEW)
                    .setData(Uri.parse("https://github.com/saschpe/BirthdayCalendar")));
        }
    });
}

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

/**
 *///from   w w  w . j a va  2  s .  c o  m
@NonNull
@Override
protected Intent onBuild() {
    final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromParts(URI_SCHEME, mPhoneNumber, null));
    if (!TextUtils.isEmpty(mBody)) {
        intent.putExtra("sms_body", mBody);
    }
    return intent;
}

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

private void loadIntentChooser() {
    mLoadIntentChooser = new AsyncTask<Void, Void, Boolean>() {

        List<IntentChooser> apps;

        @Override//from  w w  w .  j a v a 2  s  .c  o  m
        protected void onPreExecute() {
            super.onPreExecute();
            apps = new ArrayList<>();
        }

        @Override
        protected Boolean doInBackground(Void... voids) {
            while (!isCancelled()) {
                try {
                    Thread.sleep(1);
                    Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto",
                            getActivity().getResources().getString(R.string.dev_email), null));
                    List<ResolveInfo> resolveInfos = getActivity().getPackageManager()
                            .queryIntentActivities(intent, 0);
                    try {
                        Collections.sort(resolveInfos,
                                new ResolveInfo.DisplayNameComparator(getActivity().getPackageManager()));
                    } catch (Exception ignored) {
                    }

                    for (ResolveInfo resolveInfo : resolveInfos) {
                        switch (resolveInfo.activityInfo.packageName) {
                        case "com.google.android.gm":
                            apps.add(new IntentChooser(resolveInfo, IntentChooser.TYPE_RECOMMENDED));
                            break;
                        case "com.google.android.apps.inbox":
                            apps.add(new IntentChooser(resolveInfo, IntentChooser.TYPE_NOT_SUPPORTED));
                            break;
                        case "com.android.fallback":
                        case "com.paypal.android.p2pmobile":
                        case "com.lonelycatgames.Xplore":
                            break;
                        default:
                            apps.add(new IntentChooser(resolveInfo, IntentChooser.TYPE_SUPPORTED));
                            break;
                        }
                    }
                    return true;
                } catch (Exception e) {
                    LogUtil.e(Log.getStackTraceString(e));
                    return false;
                }
            }
            return false;
        }

        @Override
        protected void onPostExecute(Boolean aBoolean) {
            super.onPostExecute(aBoolean);
            if (aBoolean && apps != null) {
                IntentAdapter adapter = new IntentAdapter(getActivity(), apps, mRequest);
                mIntentList.setAdapter(adapter);

                if (apps.size() == 0) {
                    mNoApp.setVisibility(View.VISIBLE);
                    setCancelable(true);
                }

                if (apps.size() == 1) {
                    if (apps.get(0).getApp().activityInfo.packageName.equals("com.google.android.apps.inbox"))
                        setCancelable(true);
                }
            } else {
                dismiss();
                Toast.makeText(getActivity(), R.string.intent_email_failed, Toast.LENGTH_LONG).show();
            }
            mLoadIntentChooser = null;
        }
    }.execute();
}

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

private void uninstallPackage(String packageName) {
    // check that the package is installed
    try {//from w  w  w . j  a v  a  2s  . co  m
        getPackageManager().getPackageInfo(packageName, 0);
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "NameNotFoundException", e);
        installer.sendBroadcastUninstall(packageName, Installer.ACTION_UNINSTALL_INTERRUPTED,
                "Package that is scheduled for uninstall is not installed!");
        finish();
        return;
    }

    Uri uri = Uri.fromParts("package", packageName, null);
    Intent intent = new Intent();
    intent.setData(uri);

    if (Build.VERSION.SDK_INT < 14) {
        intent.setAction(Intent.ACTION_DELETE);
    } else {
        intent.setAction(Intent.ACTION_UNINSTALL_PACKAGE);
        intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
    }

    try {
        startActivityForResult(intent, REQUEST_CODE_UNINSTALL);
    } catch (ActivityNotFoundException e) {
        Log.e(TAG, "ActivityNotFoundException", e);
        installer.sendBroadcastUninstall(packageName, Installer.ACTION_UNINSTALL_INTERRUPTED,
                "This Android rom does not support ACTION_UNINSTALL_PACKAGE!");
        finish();
    }
}

From source file:com.king.base.util.SystemUtils.java

/**
 * app?/*from www .j  a  v  a 2s  . co  m*/
 * @param context
 */
public static void startAppDetailSetings(Context context) {
    Uri uri = Uri.fromParts("package", context.getPackageName(), null);
    Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, uri);
    context.startActivity(intent);
}

From source file:com.tlongdev.bktf.ui.activity.AboutActivity.java

/**
 * Shows the simplified settings UI if the device configuration if the
 * device configuration dictates that a simplified, single-pane UI should be
 * shown./*from  w w w  .j  av a2  s.co  m*/
 */
private void setupSimplePreferencesScreen() {

    // Add 'general' preferences.
    addPreferencesFromResource(R.xml.pref_about);

    PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);

    // Bind the summaries of EditText/List/Dialog/Ringtone preferences to
    // their values. When their values change, their summaries are updated
    // to reflect the new value, per the Android Design guidelines.

    findPreference(getString(R.string.pref_title_feedback))
            .setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    //Start an email intent with my email as the target
                    Intent intent = new Intent(Intent.ACTION_SENDTO,
                            Uri.fromParts("mailto", "dev@tlongdev.com", null));
                    if (intent.resolveActivity(getPackageManager()) != null) {
                        startActivity(Intent.createChooser(intent, getString(R.string.message_send_email)));
                    }
                    return true;
                }
            });

    findPreference(getString(R.string.pref_title_rate))
            .setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    //Open the Play Store page of the app
                    final String appPackageName = getPackageName();
                    try {
                        startActivity(new Intent(Intent.ACTION_VIEW,
                                Uri.parse("market://details?id=" + appPackageName)));
                    } catch (android.content.ActivityNotFoundException e) {
                        //Play store is not present on the phone. Open the browser
                        CustomTabActivityHelper.openCustomTab(AboutActivity.this,
                                new CustomTabsIntent.Builder().build(),
                                Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName),
                                new WebViewFallback());
                    }
                    return true;
                }
            });

    //Set the version name to the summary, so I don't have to change it manually every goddamn
    //update
    findPreference(getString(R.string.pref_title_version)).setSummary(BuildConfig.VERSION_NAME);
}

From source file:cn.qqjlbsc.shopseller.utlis.EasyPermissions.java

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;
            }/*from w  w  w  .  ja  va 2  s . co 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;
}

From source file:fr.bmartel.android.iotf.app.BaseActivity.java

/**
 * process menu item selected//from w  ww  .  ja va  2  s  . co m
 *
 * @param menuItem
 * @param mDrawer
 * @param context
 */
protected void selectDrawerItem(MenuItem menuItem, DrawerLayout mDrawer, Context context) {

    switch (menuItem.getItemId()) {
    case R.id.report_bugs: {
        Intent intent = new Intent(Intent.ACTION_SENDTO,
                Uri.fromParts("mailto", "kiruazoldik92@gmail.com", null));
        intent.putExtra(Intent.EXTRA_SUBJECT, "iotf Issue");
        intent.putExtra(Intent.EXTRA_TEXT, "Your error report here...");
        context.startActivity(Intent.createChooser(intent, "Report a problem"));
        break;
    }
    case R.id.open_source_components: {
        OpenSourceItemsDialog d = new OpenSourceItemsDialog();
        android.support.v4.app.FragmentManager manager = getSupportFragmentManager();
        d.show(manager, "open_source_components");
        break;
    }
    case R.id.about_app: {
        AboutDialog dialog = new AboutDialog(context);
        dialog.show();
        break;
    }
    }
    mDrawer.closeDrawers();
}

From source file:com.hch.beautyenjoy.tools.IntentUtils.java

/**
 * Open App Detail page/*  www. j  a  v a  2s. c  o m*/
 */
public static void openAppDetail(String packageName, Context context) {
    Intent intent = new Intent();
    final int apiLevel = Build.VERSION.SDK_INT;
    if (apiLevel >= 9) {
        intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        Uri uri = Uri.fromParts("package", packageName, null);
        intent.setData(uri);
    } else {
        final String appPkgName = (apiLevel == 8 ? "pkg" : "com.android.settings.ApplicationPkgName");
        intent.setAction(Intent.ACTION_VIEW);
        intent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");
        intent.putExtra(appPkgName, packageName);
    }
    context.startActivity(intent);
}

From source file:com.oasisfeng.nevo.decorators.bundle.BundleDecorator.java

private Notification buildBundleNotification(final String bundle, final int number,
        final List<StatusBarNotificationEvo> sbns) throws RemoteException {
    final Set<String> bundled_pkgs = new HashSet<>(sbns.size());
    final ArrayList<String> bundled_keys = new ArrayList<>(sbns.size());
    long latest_when = 0;
    for (final StatusBarNotificationEvo sbn : sbns) {
        final long when = sbn.notification().getWhen();
        if (when > latest_when)
            latest_when = when;//from ww  w .j a v  a2  s .co  m
        bundled_pkgs.add(sbn.getPackageName());
        bundled_keys.add(sbn.getKey());
    }

    final Intent delete_intent = new Intent(ACTION_BUNDLE_CLEAR)
            .setData(Uri.fromParts(SCHEME_BUNDLE, bundle, null))
            .putStringArrayListExtra(EXTRA_KEYS, bundled_keys);
    final PendingIntent delete_pending_intent = PendingIntent.getBroadcast(this, 0, delete_intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    final Builder builder = new Builder(this).setContentTitle(bundle)
            .setSmallIcon(R.drawable.ic_notification_bundle).setWhen(latest_when).setAutoCancel(false)
            .setPriority(PRIORITY_MIN).setNumber(number).setDeleteIntent(delete_pending_intent);
    if (bundled_pkgs.size() == 1) {
        final IBundle last_extras = sbns.get(0).notification().extras();
        builder.setContentText(last_extras.getCharSequence(NotificationCompat.EXTRA_TITLE))
                .setSubText(last_extras.getCharSequence(NotificationCompat.EXTRA_TEXT));
    } else
        builder.setContentText(getSourceNames(bundled_pkgs));

    builder.getExtras().putBoolean(NevoConstants.EXTRA_PHANTOM, true); // Bundle notification should never be evolved or stored.

    final Notification notification = builder.build();
    // Set on-click pending intent explicitly, to avoid notification drawer collapse when bundle is clicked.
    final Intent click_intent = new Intent(ACTION_BUNDLE_EXPAND)
            .setData(Uri.fromParts(SCHEME_BUNDLE, bundle, null))
            .putStringArrayListExtra(EXTRA_KEYS, bundled_keys);
    final PendingIntent click_pending_intent = PendingIntent.getBroadcast(this, 0, click_intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    final int view_id = Resources.getSystem().getIdentifier("status_bar_latest_event_content", "id", "android");
    if (view_id != 0)
        notification.contentView.setOnClickPendingIntent(view_id, click_pending_intent);
    else
        builder.setContentIntent(click_pending_intent); // Fallback to normal content intent (notification drawer will collapse)

    notification.bigContentView = buildExpandedView(sbns);
    return notification;
}