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);
}
}
}
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();
}
}
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);
}
}
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;
}
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);
}
Aggregations