Java Code Examples for android.content.Intent.resolveActivityInfo()

The following are Jave code examples for showing how to use resolveActivityInfo() of the android.content.Intent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: darryncampbell-cordova-plugin-intent   File: IntentShim.java   View Source Code Vote up 6 votes
private void startActivity(String action, Uri uri, String type, Map<String, String> extras, boolean bExpectResult, int requestCode, CallbackContext callbackContext) {
    //  Credit: https://github.com/chrisekelley/cordova-webintent
    Intent i = (uri != null ? new Intent(action, uri) : new Intent(action));

    if (type != null && uri != null) {
        i.setDataAndType(uri, type); //Fix the crash problem with android 2.3.6
    } else {
        if (type != null) {
            i.setType(type);
        }
        if (uri != null)
        {
            i.setData(uri);
        }
    }

    for (String key : extras.keySet()) {
        String value = extras.get(key);
        // If type is text html, the extra text must sent as HTML
        if (key.equals(Intent.EXTRA_TEXT) && type.equals("text/html")) {
            i.putExtra(key, Html.fromHtml(value));
        } else if (key.equals(Intent.EXTRA_STREAM)) {
            // allowes sharing of images as attachments.
            // value in this case should be a URI of a file
            final CordovaResourceApi resourceApi = webView.getResourceApi();
            i.putExtra(key, resourceApi.remapUri(Uri.parse(value)));
        } else if (key.equals(Intent.EXTRA_EMAIL)) {
            // allows to add the email address of the receiver
            i.putExtra(Intent.EXTRA_EMAIL, new String[] { value });
        } else {
            i.putExtra(key, value);
        }
    }

    i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    if (i.resolveActivityInfo(this.cordova.getActivity().getPackageManager(), 0) != null)
    {
    if (bExpectResult)
    {
        cordova.setActivityResultCallback(this);
        ((CordovaActivity) this.cordova.getActivity()).startActivityForResult(i, requestCode);
    }
    else
        {
        ((CordovaActivity)this.cordova.getActivity()).startActivity(i);
            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
        }
    }
    else
    {
        //  Return an error as there is no app to handle this intent
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR));
    }
}
 
Example 2
Project: atlas   File: RemoteActivityManager.java   View Source Code Vote up 6 votes
public EmbeddedActivityRecord startEmbeddedActivity(String bundleName) throws Exception{
    EmbeddedActivityRecord activityRecord = new EmbeddedActivityRecord();
    activityRecord.id = "embedded_"+mParent.getClass().getSimpleName();
    Field mThemeResourceF = AndroidHack.findField(mParent,"mThemeResource");
    int mThemeResource = (Integer)mThemeResourceF.get(mParent);
    Intent intent = new Intent();
    intent.setClassName(mParent,EmbeddedActivity.class.getName());
    intent.putExtra("themeId",mThemeResource);
    intent.putExtra("bundleName",bundleName);
    ActivityInfo info = intent.resolveActivityInfo(mParent.getPackageManager(), PackageManager.GET_ACTIVITIES);
    activityRecord.activity = (EmbeddedActivity) ActivityThread_startActivityNow.invoke(AndroidHack.getActivityThread(),
            mParent, activityRecord.id, intent, info, activityRecord.activity, null, null);
    activityRecord.activityInfo = info;
    return activityRecord;
}
 
Example 3
Project: phonk   File: PhonkAppHelper.java   View Source Code Vote up 6 votes
public static void launchWifiSettings(Context context) {
    // context.startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
    Intent intent = new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    if (intent.resolveActivityInfo(context.getPackageManager(), 0) != null) {
        context.startActivity(intent);
    }
}
 
Example 4
Project: phonk   File: PhonkAppHelper.java   View Source Code Vote up 6 votes
public static void launchHotspotSettings(Context context) {
    // context.startActivity(new Intent(WifiManager.AC));

    final Intent intent = new Intent(Intent.ACTION_MAIN, null);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    final ComponentName cn = new ComponentName("com.android.settings", "com.android.settings.TetherSettings");
    intent.setComponent(cn);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    if (intent.resolveActivityInfo(context.getPackageManager(), 0) != null) {
        context.startActivity(intent);
    }
}
 
Example 5
Project: cordova-logcat-filelogger   File: LogCatPlugin.java   View Source Code Vote up 6 votes
private void openDirectory(final Uri dirUri, final CallbackContext callbackContext) {
    final Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(dirUri, "resource/folder");

    final PackageManager packageManager = cordovaInstance.getActivity().getPackageManager();
    if (intent.resolveActivityInfo(packageManager, 0) != null) {
        cordovaInstance.getActivity().startActivity(intent);
        callbackContext.success();
    } else {
        callbackContext.error(RETURN_CODE.NO_FILE_MANAGER_FOUND.name());
    }
}