Search in sources :

Example 66 with ResolveInfo

use of android.content.pm.ResolveInfo in project HoloEverywhere by Prototik.

the class ResolverActivity method onIntentSelected.

@SuppressWarnings("deprecation")
protected void onIntentSelected(ResolveInfo ri, Intent intent, boolean alwaysCheck) {
    if (alwaysCheck) {
        IntentFilter filter = new IntentFilter();
        if (intent.getAction() != null) {
            filter.addAction(intent.getAction());
        }
        Set<String> categories = intent.getCategories();
        if (categories != null) {
            for (String cat : categories) {
                filter.addCategory(cat);
            }
        }
        filter.addCategory(Intent.CATEGORY_DEFAULT);
        int cat = ri.match & IntentFilter.MATCH_CATEGORY_MASK;
        Uri data = intent.getData();
        if (cat == IntentFilter.MATCH_CATEGORY_TYPE) {
            String mimeType = intent.resolveType(this);
            if (mimeType != null) {
                try {
                    filter.addDataType(mimeType);
                } catch (IntentFilter.MalformedMimeTypeException e) {
                    Log.w("ResolverActivity", e);
                    filter = null;
                }
            }
        }
        if (data != null && data.getScheme() != null) {
            if (cat != IntentFilter.MATCH_CATEGORY_TYPE || !"file".equals(data.getScheme()) && !"content".equals(data.getScheme())) {
                filter.addDataScheme(data.getScheme());
                Iterator<IntentFilter.AuthorityEntry> aIt = ri.filter.authoritiesIterator();
                if (aIt != null) {
                    while (aIt.hasNext()) {
                        IntentFilter.AuthorityEntry a = aIt.next();
                        if (a.match(data) >= 0) {
                            int port = a.getPort();
                            filter.addDataAuthority(a.getHost(), port >= 0 ? Integer.toString(port) : null);
                            break;
                        }
                    }
                }
                Iterator<PatternMatcher> pIt = ri.filter.pathsIterator();
                if (pIt != null) {
                    String path = data.getPath();
                    while (path != null && pIt.hasNext()) {
                        PatternMatcher p = pIt.next();
                        if (p.match(path)) {
                            filter.addDataPath(p.getPath(), p.getType());
                            break;
                        }
                    }
                }
            }
        }
        if (filter != null) {
            final int N = mAdapter.mList.size();
            ComponentName[] set = new ComponentName[N];
            int bestMatch = 0;
            for (int i = 0; i < N; i++) {
                ResolveInfo r = mAdapter.mList.get(i).ri;
                set[i] = new ComponentName(r.activityInfo.packageName, r.activityInfo.name);
                if (r.match > bestMatch) {
                    bestMatch = r.match;
                }
            }
            try {
                getPackageManager().addPreferredActivity(filter, bestMatch, set, intent.getComponent());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    if (intent != null) {
        startActivity(intent);
    }
}
Also used : IntentFilter(android.content.IntentFilter) Uri(android.net.Uri) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ResolveInfo(android.content.pm.ResolveInfo) ComponentName(android.content.ComponentName) PatternMatcher(android.os.PatternMatcher)

Example 67 with ResolveInfo

use of android.content.pm.ResolveInfo in project HoloEverywhere by Prototik.

the class ActivityChooserModel method loadActivitiesIfNeeded.

/**
     * Loads the activities for the current intent if needed which is
     * if they are not already loaded for the current intent.
     *
     * @return Whether loading was performed.
     */
private boolean loadActivitiesIfNeeded() {
    if (mReloadActivities && mIntent != null) {
        mReloadActivities = false;
        mActivities.clear();
        List<ResolveInfo> resolveInfos = mContext.getPackageManager().queryIntentActivities(mIntent, 0);
        final int resolveInfoCount = resolveInfos.size();
        for (int i = 0; i < resolveInfoCount; i++) {
            ResolveInfo resolveInfo = resolveInfos.get(i);
            mActivities.add(new ActivityResolveInfo(resolveInfo));
        }
        return true;
    }
    return false;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo)

Example 68 with ResolveInfo

use of android.content.pm.ResolveInfo in project Anki-Android by Ramblurr.

the class Utils method isIntentAvailable.

public static boolean isIntentAvailable(Context context, String action, ComponentName componentName) {
    final PackageManager packageManager = context.getPackageManager();
    final Intent intent = new Intent(action);
    intent.setComponent(componentName);
    List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) Intent(android.content.Intent)

Example 69 with ResolveInfo

use of android.content.pm.ResolveInfo in project Reader by TheKeeperOfPie.

the class FragmentWeb method showExternalLaunchDialog.

private void showExternalLaunchDialog(final String data, final List<ResolveInfo> listResolveInfo, PackageManager packageManager) {
    CharSequence[] titles = new CharSequence[1 + listResolveInfo.size()];
    titles[0] = getString(R.string.app_name);
    for (int index = 1; index < titles.length; index++) {
        titles[index] = listResolveInfo.get(index - 1).loadLabel(packageManager);
    }
    new AlertDialog.Builder(getActivity()).setItems(titles, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which > 0) {
                ResolveInfo resolveInfo = listResolveInfo.get(which - 1);
                Intent intent = new Intent();
                intent.setData(Uri.parse(data));
                intent.setClassName(resolveInfo.activityInfo.applicationInfo.packageName, resolveInfo.activityInfo.name);
                startActivity(intent);
            }
        }
    }).show();
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent)

Example 70 with ResolveInfo

use of android.content.pm.ResolveInfo in project SeriesGuide by UweTrottmann.

the class IabHelper method startSetup.

/**
     * Starts the setup process. This will start up the setup process asynchronously. You will be
     * notified through the listener when the setup process is complete. This method is safe to call
     * from a UI thread.
     *
     * @param listener The listener to notify when the setup process is complete.
     */
public void startSetup(@NonNull final OnIabSetupFinishedListener listener) {
    if (context == null) {
        // helper should not have been disposed of already
        throwDisposed();
    }
    if (billingService != null || billingServiceConnection != null) {
        throw new IllegalStateException("IAB helper is already set up.");
    }
    // check if Google IAB service is available
    logDebug("Starting in-app billing setup.");
    Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
    serviceIntent.setPackage("com.android.vending");
    List<ResolveInfo> resolveInfos = context.getPackageManager().queryIntentServices(serviceIntent, 0);
    if (resolveInfos == null || resolveInfos.isEmpty()) {
        // billing service not available
        listener.onIabSetupFinished(new IabResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE, "Billing service unavailable on device."));
        return;
    }
    billingServiceConnection = buildServiceConnection(listener);
    context.bindService(serviceIntent, billingServiceConnection, Context.BIND_AUTO_CREATE);
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Aggregations

ResolveInfo (android.content.pm.ResolveInfo)1196 Intent (android.content.Intent)746 PackageManager (android.content.pm.PackageManager)458 ComponentName (android.content.ComponentName)375 ArrayList (java.util.ArrayList)204 ActivityInfo (android.content.pm.ActivityInfo)203 PendingIntent (android.app.PendingIntent)159 RemoteException (android.os.RemoteException)137 ServiceInfo (android.content.pm.ServiceInfo)120 ApplicationInfo (android.content.pm.ApplicationInfo)72 EphemeralResolveInfo (android.content.pm.EphemeralResolveInfo)58 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)53 Bundle (android.os.Bundle)47 HashMap (java.util.HashMap)44 IOException (java.io.IOException)43 HashSet (java.util.HashSet)43 Point (android.graphics.Point)42 PackageInfo (android.content.pm.PackageInfo)37 ActivityNotFoundException (android.content.ActivityNotFoundException)33 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)33