Search in sources :

Example 1 with ResolveInfo

use of android.content.pm.ResolveInfo in project cw-omnibus by commonsguy.

the class DownloadFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRetainInstance(true);
    appContext = (Application) getActivity().getApplicationContext();
    Intent implicit = new Intent(IDownload.class.getName());
    List<ResolveInfo> matches = getActivity().getPackageManager().queryIntentServices(implicit, 0);
    if (matches.size() == 0) {
        Toast.makeText(getActivity(), "Cannot find a matching service!", Toast.LENGTH_LONG).show();
    } else if (matches.size() > 1) {
        Toast.makeText(getActivity(), "Found multiple matching services!", Toast.LENGTH_LONG).show();
    } else {
        ServiceInfo svcInfo = matches.get(0).serviceInfo;
        try {
            String otherHash = SignatureUtils.getSignatureHash(getActivity(), svcInfo.applicationInfo.packageName);
            String expected = getActivity().getString(R.string.expected_sig_hash);
            if (expected.equals(otherHash)) {
                Intent explicit = new Intent(implicit);
                ComponentName cn = new ComponentName(svcInfo.applicationInfo.packageName, svcInfo.name);
                explicit.setComponent(cn);
                appContext.bindService(explicit, this, Context.BIND_AUTO_CREATE);
            } else {
                Toast.makeText(getActivity(), "Unexpected signature found!", Toast.LENGTH_LONG).show();
            }
        } catch (Exception e) {
            Log.e(getClass().getSimpleName(), "Exception trying to get signature hash", e);
        }
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) IDownload(com.commonsware.android.advservice.remotebinding.IDownload) Intent(android.content.Intent) ComponentName(android.content.ComponentName) RemoteException(android.os.RemoteException)

Example 2 with ResolveInfo

use of android.content.pm.ResolveInfo in project cw-omnibus by commonsguy.

the class ActivityChooserModel method loadActivitiesLocked.

/**
     * Loads the activities.
     */
private void loadActivitiesLocked() {
    mActivites.clear();
    if (mIntent != null) {
        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);
            mActivites.add(new ActivityResolveInfo(resolveInfo));
        }
        sortActivities();
    } else {
        notifyChanged();
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo)

Example 3 with ResolveInfo

use of android.content.pm.ResolveInfo in project cw-omnibus by commonsguy.

the class ActivityChooserView method updateAppearance.

/**
     * Updates the buttons state.
     */
private void updateAppearance() {
    // Expand overflow button.
    if (mAdapter.getCount() > 0) {
        mExpandActivityOverflowButton.setEnabled(true);
    } else {
        mExpandActivityOverflowButton.setEnabled(false);
    }
    // Default activity button.
    final int activityCount = mAdapter.getActivityCount();
    final int historySize = mAdapter.getHistorySize();
    if (activityCount > 0 && historySize > 0) {
        mDefaultActivityButton.setVisibility(VISIBLE);
        ResolveInfo activity = mAdapter.getDefaultActivity();
        PackageManager packageManager = mContext.getPackageManager();
        mDefaultActivityButtonImage.setImageDrawable(activity.loadIcon(packageManager));
        if (mDefaultActionButtonContentDescription != 0) {
            CharSequence label = activity.loadLabel(packageManager);
            String contentDescription = mContext.getString(mDefaultActionButtonContentDescription, label);
            mDefaultActivityButton.setContentDescription(contentDescription);
        }
        // Work-around for #415.
        mAdapter.setShowDefaultActivity(false, false);
    } else {
        mDefaultActivityButton.setVisibility(View.GONE);
    }
    // Activity chooser content.
    if (mDefaultActivityButton.getVisibility() == VISIBLE) {
        mActivityChooserContent.setBackgroundDrawable(mActivityChooserContentBackground);
    } else {
        mActivityChooserContent.setBackgroundDrawable(null);
        mActivityChooserContent.setPadding(0, 0, 0, 0);
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager)

Example 4 with ResolveInfo

use of android.content.pm.ResolveInfo in project android-betterpickers by code-troopers.

the class ListSamples method getData.

protected List<Map<String, Object>> getData(String prefix) {
    List<Map<String, Object>> myData = new ArrayList<Map<String, Object>>();
    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(INTENT_SAMPLE);
    PackageManager pm = getPackageManager();
    List<ResolveInfo> list = pm.queryIntentActivities(mainIntent, 0);
    if (null == list) {
        return myData;
    }
    String[] prefixPath;
    String prefixWithSlash = prefix;
    if (prefix.equals("")) {
        prefixPath = null;
    } else {
        prefixPath = prefix.split("/");
        prefixWithSlash = prefix + "/";
    }
    int len = list.size();
    Map<String, Boolean> entries = new HashMap<String, Boolean>();
    for (int i = 0; i < len; i++) {
        ResolveInfo info = list.get(i);
        CharSequence labelSeq = info.loadLabel(pm);
        String label = labelSeq != null ? labelSeq.toString() : info.activityInfo.name;
        if (prefixWithSlash.length() == 0 || label.startsWith(prefixWithSlash)) {
            String[] labelPath = label.split("/");
            String nextLabel = prefixPath == null ? labelPath[0] : labelPath[prefixPath.length];
            if ((prefixPath != null ? prefixPath.length : 0) == labelPath.length - 1) {
                addItem(myData, nextLabel, activityIntent(info.activityInfo.applicationInfo.packageName, info.activityInfo.name));
            } else {
                if (entries.get(nextLabel) == null) {
                    addItem(myData, nextLabel, browseIntent(prefix.equals("") ? nextLabel : prefix + "/" + nextLabel));
                    entries.put(nextLabel, true);
                }
            }
        }
    }
    Collections.sort(myData, NAME_COMPARATOR);
    return myData;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Intent(android.content.Intent) ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with ResolveInfo

use of android.content.pm.ResolveInfo in project cw-omnibus by commonsguy.

the class MainActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    PackageManager pm = getPackageManager();
    Intent main = new Intent(Intent.ACTION_MAIN, null);
    main.addCategory(Intent.CATEGORY_LAUNCHER);
    List<ResolveInfo> launchables = pm.queryIntentActivities(main, 0);
    List<ResolveInfo> filtered = new ArrayList<>();
    for (ResolveInfo launchable : launchables) {
        int launchMode = launchable.activityInfo.launchMode;
        if (launchMode != ActivityInfo.LAUNCH_SINGLE_INSTANCE && launchMode != ActivityInfo.LAUNCH_SINGLE_TASK) {
            filtered.add(launchable);
        }
    }
    Collections.sort(filtered, new ResolveInfo.DisplayNameComparator(pm));
    adapter = new AppAdapter(pm, filtered);
    setListAdapter(adapter);
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) ArrayList(java.util.ArrayList) Intent(android.content.Intent)

Aggregations

ResolveInfo (android.content.pm.ResolveInfo)2316 Intent (android.content.Intent)1476 PackageManager (android.content.pm.PackageManager)875 ComponentName (android.content.ComponentName)637 ArrayList (java.util.ArrayList)515 ActivityInfo (android.content.pm.ActivityInfo)360 Test (org.junit.Test)282 ServiceInfo (android.content.pm.ServiceInfo)203 PendingIntent (android.app.PendingIntent)183 ApplicationInfo (android.content.pm.ApplicationInfo)178 RemoteException (android.os.RemoteException)170 Context (android.content.Context)101 Bundle (android.os.Bundle)97 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)81 IOException (java.io.IOException)78 PackageInfo (android.content.pm.PackageInfo)68 HashSet (java.util.HashSet)65 HashMap (java.util.HashMap)63 ActivityNotFoundException (android.content.ActivityNotFoundException)59 EphemeralResolveInfo (android.content.pm.EphemeralResolveInfo)58