Example usage for android.content Intent resolveActivity

List of usage examples for android.content Intent resolveActivity

Introduction

In this page you can find the example usage for android.content Intent resolveActivity.

Prototype

public ComponentName resolveActivity(@NonNull PackageManager pm) 

Source Link

Document

Return the Activity component that should be used to handle this intent.

Usage

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

/**
 * send email//from   w  ww .j av a  2 s .co m
 *
 * @param email email address
 */
public static void sendEmail(Context context, String email) {
    Intent data = new Intent(Intent.ACTION_SENDTO);
    data.setData(Uri.parse("mailto:" + email));
    data.putExtra(Intent.EXTRA_SUBJECT, "[ " + AppTools.getApplicationName(context) + " ] " + "??");
    ComponentName componentName = data.resolveActivity(context.getPackageManager());
    if (componentName != null) {
        context.startActivity(data);
    } else {
        Toast.makeText(context, "", Toast.LENGTH_SHORT).show();
    }
}

From source file:com.artemchep.horario.ui.dialogs.FeedbackDialog.java

/**
 * @return {@code true} if this device can send feedback email,
 * {@code false} otherwise./*from w ww  . j  a v  a 2 s. c  o  m*/
 */
public static boolean isSupported(@NonNull Context context) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SENDTO);
    intent.setData(Uri.parse("mailto:")); // only email apps should handle it
    PackageManager pm = context.getPackageManager();
    return pm != null && intent.resolveActivity(pm) != null;
}

From source file:com.codyy.rx.permissions.RxPermissions.java

/**
 * ???//from  ww  w  . j av a 2  s  . com
 *
 * @param context     context
 * @param packageName ??
 */
public static void openPermissionSettings(@NonNull Context context, @NonNull String packageName) {
    Intent intent = new Intent();
    intent.setAction("miui.intent.action.APP_PERM_EDITOR");//??MIUI???
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.putExtra("extra_pkgname", packageName);
    if (intent.resolveActivity(context.getPackageManager()) != null) {
        context.startActivity(intent);
    } else {
        Uri packageURI = Uri.parse("package:" + packageName);
        intent = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS", packageURI);//???
        if (intent.resolveActivity(context.getPackageManager()) != null) {
            context.startActivity(intent);
        } else {
            Toast.makeText(context, "???", Toast.LENGTH_SHORT).show();
        }
    }
}

From source file:com.forrestguice.suntimeswidget.AlarmDialog.java

/**
 * @param context a context used to start the "show alarm" intent
 *//*from  w  w w  . j a  v  a2 s  .c  o m*/
@TargetApi(Build.VERSION_CODES.KITKAT)
public static void showAlarms(Activity context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        Intent alarmsIntent = new Intent(AlarmClock.ACTION_SHOW_ALARMS);
        alarmsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        if (alarmsIntent.resolveActivity(context.getPackageManager()) != null) {
            context.startActivity(alarmsIntent);
        }
    }
}

From source file:util.mediamanager.PlaylistUtils.java

public static void PlayGMPlaylistUsingSearch(Context context, String playlist) {
    Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
    intent.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, MediaStore.Audio.Playlists.ENTRY_CONTENT_TYPE);
    intent.putExtra(SearchManager.QUERY, playlist);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    if (intent.resolveActivity(context.getPackageManager()) != null) {
        context.startActivity(intent);//from  w  w w  .j a va 2  s.  c o m
    }
}

From source file:org.alfresco.mobile.android.application.managers.ActionUtils.java

public static void actionSendFileToAlfresco(FragmentActivity activity, File contentFile) {
    try {/*from   w ww  . j a  v a2  s.  c  o  m*/
        Intent i = createSendFileToAlfrescoIntent(activity, contentFile);
        if (i.resolveActivity(activity.getPackageManager()) == null) {
            AlfrescoNotificationManager.getInstance(activity).showAlertCrouton(activity,
                    activity.getString(R.string.feature_disable));
        } else {
            activity.startActivity(i);
        }
    } catch (ActivityNotFoundException e) {
        AlfrescoNotificationManager.getInstance(activity).showAlertCrouton(activity,
                R.string.error_unable_share_content);
    }
}

From source file:com.battlelancer.seriesguide.util.Utils.java

/**
 * Calls {@link Context#startActivity(Intent)} with the given <b>implicit</b> {@link Intent}
 * after making sure there is an {@link Activity} to handle it. Can show an error toast, if not.
 * <br> <br> This may happen if e.g. the web browser has been disabled through restricted
 * profiles./*ww  w. j  a  v  a  2s .  c  o  m*/
 *
 * @return Whether there was an {@link Activity} to handle the given {@link Intent}.
 */
public static boolean tryStartActivity(Context context, Intent intent, boolean displayError) {
    if (intent.resolveActivity(context.getPackageManager()) != null) {
        context.startActivity(intent);
        return true;
    } else if (displayError) {
        Toast.makeText(context, R.string.app_not_available, Toast.LENGTH_LONG).show();
    }
    return false;
}

From source file:com.userhook.UserHook.java

private static void startActivityToRate() {
    Uri uri = Uri.parse("market://details?id=" + applicationContext.getPackageName());
    Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
    goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
    if (goToMarket.resolveActivity(applicationContext.getPackageManager()) != null) {
        activityLifecycle.getCurrentActivity().startActivity(goToMarket);
        return;/* ww  w .ja  v  a  2 s .  com*/
    }

    activityLifecycle.getCurrentActivity().startActivity(new Intent(Intent.ACTION_VIEW,
            Uri.parse("http://play.google.com/store/apps/details?id=" + applicationContext.getPackageName())));
}

From source file:util.mediamanager.PlaylistUtils.java

public static void PlaySearchArtist(Context context, String artist) {
    Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
    intent.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, MediaStore.Audio.Artists.ENTRY_CONTENT_TYPE);
    intent.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, artist);
    intent.putExtra(SearchManager.QUERY, artist);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    if (intent.resolveActivity(context.getPackageManager()) != null) {
        context.startActivity(intent);/*from  w  ww.jav  a  2s  .c om*/
    }
}

From source file:io.github.runassudo.ptoffline.utils.TransportrUtils.java

static public void startGeoIntent(Context context, Location loc) {
    String lat = Double.toString(loc.lat / 1E6);
    String lon = Double.toString(loc.lon / 1E6);

    String uri1 = "geo:0,0?q=" + lat + "," + lon;
    String uri2;//from   w  w w . jav  a  2 s .  co  m

    try {
        uri2 = "(" + URLEncoder.encode(TransportrUtils.getLocName(loc), "utf-8") + ")";
    } catch (UnsupportedEncodingException e) {
        uri2 = "(" + TransportrUtils.getLocName(loc) + ")";
    }

    Uri geo = Uri.parse(uri1 + uri2);

    Log.d(context.getClass().getCanonicalName(), "Starting geo intent: " + geo.toString());

    // show station on external map
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(geo);
    if (intent.resolveActivity(context.getPackageManager()) != null) {
        context.startActivity(intent);
    }
}