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:Main.java

private static boolean isCameraActivityAvailable(Activity currentActivity, Intent takePictureIntent) {
    return takePictureIntent.resolveActivity(currentActivity.getPackageManager()) != null;
}

From source file:Main.java

public static boolean resolves(PackageManager packageManager, String action, Uri uri, String mimeType) {
    Intent intent = new Intent(action);
    intent.setDataAndType(uri, mimeType);
    return intent.resolveActivity(packageManager) != null;
}

From source file:Main.java

public static boolean testingShowWebView(final Activity activity, final String aid, final String url) {
    if (TextUtils.isEmpty(url)) {
        Intent intent = new Intent(adWebAction);
        intent.putExtra("aid", aid);
        if (intent.resolveActivity(activity.getPackageManager()) != null) {
            activity.startActivity(intent);
        }/*from ww  w. j ava  2s  .c  o  m*/
        return true;
    }

    return false;
}

From source file:Main.java

public static boolean hasActivityForThat(@NonNull Context context, @Nullable Intent intent) {
    PackageManager pm = context.getPackageManager();
    return pm != null && intent != null && intent.resolveActivity(pm) != null;
}

From source file:Main.java

/**
 * Checks whether a browser if available on the device to handle ACTION_VIEW intents.
 * @param ctx The context of the application.
 * @return Whether ACTION_VIEW intents will resolve.
 *//*from ww  w  .  ja  v a 2s . c o  m*/
public static boolean check_browser_available(Context ctx) {
    if (_BROWSER_AVAILABLE != null) {
        return _BROWSER_AVAILABLE;
    }
    Intent browser_intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://apktrack.kwiatkowski.fr/"));
    _BROWSER_AVAILABLE = browser_intent.resolveActivity(ctx.getPackageManager()) != null;
    return _BROWSER_AVAILABLE;
}

From source file:Main.java

public static boolean isActivityExists(Context context, String packageName, String className) {
    Intent intent = new Intent();
    intent.setClassName(packageName, className);
    return !(context.getPackageManager().resolveActivity(intent, 0) == null
            || intent.resolveActivity(context.getPackageManager()) == null
            || context.getPackageManager().queryIntentActivities(intent, 0).size() == 0);
}

From source file:am.project.x.utils.ContextUtils.java

/**
 * ??/*from  w  w  w. j  a v  a 2  s  .  co  m*/
 *
 * @param context Context
 * @param url     ?
 */
public static void openBrowser(Context context, String url) {
    final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    if (intent.resolveActivity(context.getPackageManager()) != null) {
        context.startActivity(intent);
    }
}

From source file:Main.java

public static boolean hasSpeechToText(Context context) {
    try {/*from  w w w .ja  va  2 s . c  o  m*/
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, Locale.getDefault());
        return intent.resolveActivity(context.getPackageManager()) != null;
    } catch (Exception e) {
        return false;
    }
}

From source file:org.xbmc.kore.utils.Utils.java

/**
 * Calls {@link Context#startActivity(Intent)} with the given <b>implicit</b> {@link Intent}
 * after making sure there is an Activity to handle it.
 * <br> <br> This may happen if e.g. the web browser has been disabled through restricted
 * profiles./*from  w w w .jav  a 2 s  .  com*/
 *
 * @return Whether there was an Activity to handle the given {@link Intent}.
 */
public static boolean tryStartActivity(Context context, Intent intent) {
    if (intent.resolveActivity(context.getPackageManager()) != null) {
        context.startActivity(intent);
        return true;
    }
    return false;
}

From source file:com.google.android.apps.forscience.whistlepunk.PictureUtils.java

private static String capturePictureLabel(Context context, IStartable startable) {
    // Starts a picture intent.
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(context.getPackageManager()) != null) {
        File photoFile = null;/*from w w  w  .  j a  v a2  s  . c o m*/
        try {
            photoFile = PictureUtils.createImageFile(
                    AppSingleton.getInstance(context).getSensorEnvironment().getDefaultClock().getNow());
        } catch (IOException ex) {
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, ex.getMessage());
            }
        }
        if (photoFile != null) {
            Uri photoUri = FileProvider.getUriForFile(context, context.getPackageName(), photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                // Needed to avoid security exception on KitKat.
                takePictureIntent.setClipData(ClipData.newRawUri(null, photoUri));
            }
            takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            String pictureLabelPath = "file:" + photoFile.getAbsoluteFile();
            startable.startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
            return pictureLabelPath;
        }
    }
    return null;
}