Example usage for android.content.pm ResolveInfo toString

List of usage examples for android.content.pm ResolveInfo toString

Introduction

In this page you can find the example usage for android.content.pm ResolveInfo toString.

Prototype

public String toString() 

Source Link

Usage

From source file:com.vuze.android.remote.fragment.FilesFragment.java

@SuppressWarnings("unused")
protected boolean reallyStreamFile(Map<?, ?> selectedFile) {
    final String contentURL = getContentURL(selectedFile);
    if (contentURL != null && contentURL.length() > 0) {
        Uri uri = Uri.parse(contentURL);

        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        String name = MapUtils.getMapString(selectedFile, "name", "video");
        intent.putExtra("title", name);

        String extension = MimeTypeMap.getFileExtensionFromUrl(contentURL).toLowerCase(Locale.US);
        String mimetype = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
        if (mimetype != null && tryLaunchWithMimeFirst) {
            intent.setType(mimetype);//from ww  w  .  j  a va  2s  .com
        }
        Class<?> fallBackIntentClass = VideoViewer.class;
        if (mimetype != null && mimetype.startsWith("image")) {
            fallBackIntentClass = ImageViewer.class;
        }

        final PackageManager packageManager = getActivity().getPackageManager();
        List<ResolveInfo> list = packageManager.queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY);
        if (AndroidUtils.DEBUG) {
            Log.d(TAG, "num intents " + list.size());
            for (ResolveInfo info : list) {
                ComponentInfo componentInfo = AndroidUtils.getComponentInfo(info);
                Log.d(TAG, info.toString() + "/"
                        + (componentInfo == null ? "null" : (componentInfo.name + "/" + componentInfo)));
            }
        }
        if (list.size() == 0) {
            // Intent will launch, but show message to the user:
            // "Opening web browser links is not supported"
            intent.setClass(getActivity(), fallBackIntentClass);
        }
        if (list.size() == 1) {
            ResolveInfo info = list.get(0);
            ComponentInfo componentInfo = AndroidUtils.getComponentInfo(info);
            if (componentInfo != null && componentInfo.name != null) {
                if ("com.amazon.unifiedshare.actionchooser.BuellerShareActivity".equals(componentInfo.name)
                        || componentInfo.name.startsWith("com.google.android.tv.frameworkpackagestubs.Stubs")) {
                    intent.setClass(getActivity(), fallBackIntentClass);
                }
            }
        }

        try {
            startActivity(intent);
            if (AndroidUtils.DEBUG) {
                Log.d(TAG, "Started " + uri + " MIME: " + intent.getType());
            }
        } catch (java.lang.SecurityException es) {
            if (AndroidUtils.DEBUG) {
                Log.d(TAG, "ERROR launching. " + es.toString());
            }

            if (mimetype != null) {
                try {
                    Intent intent2 = new Intent(Intent.ACTION_VIEW, uri);
                    intent2.putExtra("title", name);
                    if (!tryLaunchWithMimeFirst) {
                        intent2.setType(mimetype);
                    }

                    list = packageManager.queryIntentActivities(intent2, PackageManager.MATCH_DEFAULT_ONLY);
                    if (AndroidUtils.DEBUG) {
                        Log.d(TAG, "num intents " + list.size());
                        for (ResolveInfo info : list) {
                            ComponentInfo componentInfo = AndroidUtils.getComponentInfo(info);
                            Log.d(TAG, info.toString() + "/" + (componentInfo == null ? "null"
                                    : (componentInfo.name + "/" + componentInfo)));
                        }
                    }

                    startActivity(intent2);
                    if (AndroidUtils.DEBUG) {
                        Log.d(TAG,
                                "Started with" + (intent2.getType() == null ? " no" : " ") + " mime: " + uri);
                    }
                    return true;
                } catch (Throwable ex2) {
                    if (AndroidUtils.DEBUG) {
                        Log.d(TAG, "no intent for view. " + ex2.toString());
                    }
                }
            }

            Toast.makeText(getActivity().getApplicationContext(),
                    getActivity().getResources().getString(R.string.intent_security_fail), Toast.LENGTH_LONG)
                    .show();
        } catch (android.content.ActivityNotFoundException ex) {
            if (AndroidUtils.DEBUG) {
                Log.d(TAG, "no intent for view. " + ex.toString());
            }

            if (mimetype != null) {
                try {
                    Intent intent2 = new Intent(Intent.ACTION_VIEW, uri);
                    intent2.putExtra("title", name);
                    if (!tryLaunchWithMimeFirst) {
                        intent2.setType(mimetype);
                    }
                    startActivity(intent2);
                    if (AndroidUtils.DEBUG) {
                        Log.d(TAG, "Started (no mime set) " + uri);
                    }
                    return true;
                } catch (android.content.ActivityNotFoundException ex2) {
                    if (AndroidUtils.DEBUG) {
                        Log.d(TAG, "no intent for view. " + ex2.toString());
                    }
                }
            }

            Toast.makeText(getActivity().getApplicationContext(),
                    getActivity().getResources().getString(R.string.no_intent), Toast.LENGTH_SHORT).show();
        }
        return true;
    }

    return true;
}