List of usage examples for android.content.pm PackageManager GET_PROVIDERS
int GET_PROVIDERS
To view the source code for android.content.pm PackageManager GET_PROVIDERS.
Click Source Link
From source file:com.mycelium.wallet.activity.modern.ModernMain.java
private void shareTransactionHistory() { WalletAccount account = _mbwManager.getSelectedAccount(); MetadataStorage metaData = _mbwManager.getMetadataStorage(); try {// www.j a v a2 s . c o m String fileName = "MyceliumExport_" + System.currentTimeMillis() + ".csv"; File historyData = DataExport.getTxHistoryCsv(account, metaData, getFileStreamPath(fileName)); PackageManager packageManager = Preconditions.checkNotNull(getPackageManager()); PackageInfo packageInfo = packageManager.getPackageInfo(getPackageName(), PackageManager.GET_PROVIDERS); for (ProviderInfo info : packageInfo.providers) { if (info.name.equals("android.support.v4.content.FileProvider")) { String authority = info.authority; Uri uri = FileProvider.getUriForFile(this, authority, historyData); Intent intent = ShareCompat.IntentBuilder.from(this).setStream(uri) // uri from FileProvider .setType("text/plain") .setSubject(getResources().getString(R.string.transaction_history_title)) .setText(getResources().getString(R.string.transaction_history_title)).getIntent() .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); List<ResolveInfo> resInfoList = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resInfoList) { String packageName = resolveInfo.activityInfo.packageName; grantUriPermission(packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION); } startActivity(Intent.createChooser(intent, getResources().getString(R.string.share_transaction_history))); } } } catch (IOException | PackageManager.NameNotFoundException e) { _toaster.toast("Export failed. Check your logs", false); e.printStackTrace(); } }
From source file:com.brq.wallet.activity.modern.ModernMain.java
private void shareTransactionHistory() { WalletAccount account = _mbwManager.getSelectedAccount(); MetadataStorage metaData = _mbwManager.getMetadataStorage(); try {//from www . ja v a 2 s .c om String fileName = "MyceliumExport_" + System.currentTimeMillis() + ".csv"; File historyData = DataExport.getTxHistoryCsv(account, metaData, getFileStreamPath(fileName)); PackageManager packageManager = Preconditions.checkNotNull(getPackageManager()); PackageInfo packageInfo = packageManager.getPackageInfo(getPackageName(), PackageManager.GET_PROVIDERS); for (ProviderInfo info : packageInfo.providers) { if (info.name.equals("android.support.v4.content.FileProvider")) { String authority = info.authority; Uri uri = FileProvider.getUriForFile(this, authority, historyData); Intent intent = ShareCompat.IntentBuilder.from(this).setStream(uri) // uri from FileProvider .setType("text/plain") .setSubject(getResources().getString(R.string.transaction_history_title)) .setText(getResources().getString(R.string.transaction_history_title)).getIntent() .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); List<ResolveInfo> resInfoList = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resInfoList) { String packageName = resolveInfo.activityInfo.packageName; grantUriPermission(packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION); } startActivity(Intent.createChooser(intent, getResources().getString(R.string.share_transaction_history))); } } } catch (IOException e) { _toaster.toast("Export failed. Check your logs", false); e.printStackTrace(); } catch (PackageManager.NameNotFoundException e) { _toaster.toast("Export failed. Check your logs", false); e.printStackTrace(); } }
From source file:android.content.pm.PackageParser.java
public static PackageInfo generatePackageInfo(PackageParser.Package p, int gids[], int flags, long firstInstallTime, long lastUpdateTime, Set<String> grantedPermissions, PackageUserState state, int userId) { if (!checkUseInstalledOrHidden(flags, state)) { return null; }/*from ww w .j a v a 2s . c o m*/ PackageInfo pi = new PackageInfo(); pi.packageName = p.packageName; pi.splitNames = p.splitNames; pi.versionCode = p.mVersionCode; pi.baseRevisionCode = p.baseRevisionCode; pi.splitRevisionCodes = p.splitRevisionCodes; pi.versionName = p.mVersionName; pi.sharedUserId = p.mSharedUserId; pi.sharedUserLabel = p.mSharedUserLabel; pi.applicationInfo = generateApplicationInfo(p, flags, state, userId); pi.installLocation = p.installLocation; pi.coreApp = p.coreApp; if ((pi.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 || (pi.applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) { pi.requiredForAllUsers = p.mRequiredForAllUsers; } pi.restrictedAccountType = p.mRestrictedAccountType; pi.requiredAccountType = p.mRequiredAccountType; pi.overlayTarget = p.mOverlayTarget; pi.firstInstallTime = firstInstallTime; pi.lastUpdateTime = lastUpdateTime; if ((flags & PackageManager.GET_GIDS) != 0) { pi.gids = gids; } if ((flags & PackageManager.GET_CONFIGURATIONS) != 0) { int N = p.configPreferences != null ? p.configPreferences.size() : 0; if (N > 0) { pi.configPreferences = new ConfigurationInfo[N]; p.configPreferences.toArray(pi.configPreferences); } N = p.reqFeatures != null ? p.reqFeatures.size() : 0; if (N > 0) { pi.reqFeatures = new FeatureInfo[N]; p.reqFeatures.toArray(pi.reqFeatures); } N = p.featureGroups != null ? p.featureGroups.size() : 0; if (N > 0) { pi.featureGroups = new FeatureGroupInfo[N]; p.featureGroups.toArray(pi.featureGroups); } } if ((flags & PackageManager.GET_ACTIVITIES) != 0) { int N = p.activities.size(); if (N > 0) { if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) { pi.activities = new ActivityInfo[N]; } else { int num = 0; for (int i = 0; i < N; i++) { if (p.activities.get(i).info.enabled) num++; } pi.activities = new ActivityInfo[num]; } for (int i = 0, j = 0; i < N; i++) { final Activity activity = p.activities.get(i); if (activity.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) { pi.activities[j++] = generateActivityInfo(p.activities.get(i), flags, state, userId); } } } } if ((flags & PackageManager.GET_RECEIVERS) != 0) { int N = p.receivers.size(); if (N > 0) { if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) { pi.receivers = new ActivityInfo[N]; } else { int num = 0; for (int i = 0; i < N; i++) { if (p.receivers.get(i).info.enabled) num++; } pi.receivers = new ActivityInfo[num]; } for (int i = 0, j = 0; i < N; i++) { final Activity activity = p.receivers.get(i); if (activity.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) { pi.receivers[j++] = generateActivityInfo(p.receivers.get(i), flags, state, userId); } } } } if ((flags & PackageManager.GET_SERVICES) != 0) { int N = p.services.size(); if (N > 0) { if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) { pi.services = new ServiceInfo[N]; } else { int num = 0; for (int i = 0; i < N; i++) { if (p.services.get(i).info.enabled) num++; } pi.services = new ServiceInfo[num]; } for (int i = 0, j = 0; i < N; i++) { final Service service = p.services.get(i); if (service.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) { pi.services[j++] = generateServiceInfo(p.services.get(i), flags, state, userId); } } } } if ((flags & PackageManager.GET_PROVIDERS) != 0) { int N = p.providers.size(); if (N > 0) { if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) { pi.providers = new ProviderInfo[N]; } else { int num = 0; for (int i = 0; i < N; i++) { if (p.providers.get(i).info.enabled) num++; } pi.providers = new ProviderInfo[num]; } for (int i = 0, j = 0; i < N; i++) { final Provider provider = p.providers.get(i); if (provider.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) { pi.providers[j++] = generateProviderInfo(p.providers.get(i), flags, state, userId); } } } } if ((flags & PackageManager.GET_INSTRUMENTATION) != 0) { int N = p.instrumentation.size(); if (N > 0) { pi.instrumentation = new InstrumentationInfo[N]; for (int i = 0; i < N; i++) { pi.instrumentation[i] = generateInstrumentationInfo(p.instrumentation.get(i), flags); } } } if ((flags & PackageManager.GET_PERMISSIONS) != 0) { int N = p.permissions.size(); if (N > 0) { pi.permissions = new PermissionInfo[N]; for (int i = 0; i < N; i++) { pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags); } } N = p.requestedPermissions.size(); if (N > 0) { pi.requestedPermissions = new String[N]; pi.requestedPermissionsFlags = new int[N]; for (int i = 0; i < N; i++) { final String perm = p.requestedPermissions.get(i); pi.requestedPermissions[i] = perm; // The notion of required permissions is deprecated but for compatibility. pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_REQUIRED; if (grantedPermissions != null && grantedPermissions.contains(perm)) { pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_GRANTED; } } } } if ((flags & PackageManager.GET_SIGNATURES) != 0) { int N = (p.mSignatures != null) ? p.mSignatures.length : 0; if (N > 0) { pi.signatures = new Signature[N]; System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N); } } return pi; }
From source file:com.github.michalbednarski.intentslab.browser.ComponentFetcher.java
@Override void onPrepareOptionsMenu(Menu menu) { if (appType == APP_TYPE_USER) { menu.findItem(R.id.system_apps).setVisible(true); } else if (appType == APP_TYPE_SYSTEM) { menu.findItem(R.id.user_apps).setVisible(true); }//from ww w .j a va2s.c o m if (type == PackageManager.GET_ACTIVITIES) { menu.findItem(R.id.activities).setChecked(true); } else if (type == PackageManager.GET_RECEIVERS) { menu.findItem(R.id.broadcasts).setChecked(true); } else if (type == PackageManager.GET_SERVICES) { menu.findItem(R.id.services).setChecked(true); } else if (type == PackageManager.GET_PROVIDERS) { menu.findItem(R.id.content_providers).setChecked(true); } menu.findItem(R.id.simple_filter_permission).setVisible(true); for (int i = 0; i < PROTECTION_PRESETS_MENU_IDS.length; i++) { if (protection == PROTECTION_PRESETS[i]) { menu.findItem(PROTECTION_PRESETS_MENU_IDS[i]).setChecked(true); } } }
From source file:com.github.michalbednarski.intentslab.browser.ComponentFetcher.java
@Override boolean onOptionsItemSelected(int id) { switch (id) { case R.id.system_apps: appType = APP_TYPE_SYSTEM;// w w w . ja v a2s. c o m return true; case R.id.user_apps: appType = APP_TYPE_USER; return true; case R.id.activities: type = PackageManager.GET_ACTIVITIES; return true; case R.id.broadcasts: type = PackageManager.GET_RECEIVERS; return true; case R.id.services: type = PackageManager.GET_SERVICES; return true; case R.id.content_providers: type = PackageManager.GET_PROVIDERS; return true; case R.id.permission_filter_all: protection = PROTECTION_ANY; return true; case R.id.permission_filter_exported: protection = PROTECTION_ANY_EXPORTED; return true; case R.id.permission_filter_obtainable: protection = PROTECTION_ANY_OBTAINABLE; return true; case R.id.permission_filter_world_accessible: protection = PROTECTION_WORLD_ACCESSIBLE; return true; } return false; }
From source file:com.github.michalbednarski.intentslab.browser.ComponentFetcher.java
@Override JSONObject serializeToJSON() throws JSONException { JSONObject jsonObject = new JSONObject(); jsonObject.put("componentType", type); jsonObject.put("appType", appType); jsonObject.put("protectionFilter", protection); if ((type & PackageManager.GET_PROVIDERS) != 0) { jsonObject.put("testProviderWrite", testWritePermissionForProviders); }//w w w .j av a 2 s. c om jsonObject.put("metadataSubstring", requireMetaDataSubstring); return jsonObject; }
From source file:com.landenlabs.all_devtool.PackageFragment.java
/** * Load packages which are default (associated) with specific mime types. * * Use "adb shell dumpsys package r" to get full list *//* w w w .j ava 2 s. com*/ void loadDefaultPackages() { m_workList = new ArrayList<PackingItem>(); String[] actions = { Intent.ACTION_SEND, Intent.ACTION_SEND, Intent.ACTION_SEND, Intent.ACTION_SEND, Intent.ACTION_VIEW, Intent.ACTION_VIEW, Intent.ACTION_VIEW, Intent.ACTION_VIEW, Intent.ACTION_VIEW, Intent.ACTION_VIEW, Intent.ACTION_VIEW, Intent.ACTION_VIEW, MediaStore.ACTION_IMAGE_CAPTURE, MediaStore.ACTION_VIDEO_CAPTURE, Intent.ACTION_CREATE_SHORTCUT }; String[] types = { "audio/*", "video/*", "image/*", "text/plain", "application/pdf", "application/zip", "audio/*", "video/*", "image/*", "text/html", "text/plain", "text/csv", "image/png", "video/*", "" }; long orderCnt = 1; for (int idx = 0; idx != actions.length; idx++) { String type = types[idx]; Intent resolveIntent = new Intent(actions[idx]); if (!TextUtils.isEmpty(type)) { if (type.startsWith("audio/*")) { Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1"); resolveIntent.setDataAndType(uri, type); } else if (type.startsWith("video/*")) { Uri uri = Uri.withAppendedPath(MediaStore.Video.Media.INTERNAL_CONTENT_URI, "1"); resolveIntent.setDataAndType(uri, type); } else if (type.startsWith("text/")) { Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath()); resolveIntent.setDataAndType(uri, type); } else { resolveIntent.setType(type); } } PackageManager pm = getActivity().getPackageManager(); // PackageManager.GET_RESOLVED_FILTER); // or PackageManager.MATCH_DEFAULT_ONLY List<ResolveInfo> resolveList = pm.queryIntentActivities(resolveIntent, -1); // PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_INTENT_FILTERS); if (resolveList != null) { String actType = type = Utils.last(actions[idx].split("[.]")) + ":" + type; for (ResolveInfo resolveInfo : resolveList) { ArrayListPairString pkgList = new ArrayListPairString(); String appName = resolveInfo.activityInfo.loadLabel(pm).toString().trim(); addList(pkgList, "Type", actType); String pkgName = resolveInfo.activityInfo.packageName; PackageInfo packInfo = null; try { packInfo = pm.getPackageInfo(pkgName, 0); addList(pkgList, "Version", packInfo.versionName); addList(pkgList, "VerCode", String.valueOf(packInfo.versionCode)); addList(pkgList, "TargetSDK", String.valueOf(packInfo.applicationInfo.targetSdkVersion)); m_date.setTime(packInfo.firstInstallTime); addList(pkgList, "Install First", s_timeFormat.format(m_date)); m_date.setTime(packInfo.lastUpdateTime); addList(pkgList, "Install Last", s_timeFormat.format(m_date)); if (resolveInfo.filter != null) { if (resolveInfo.filter.countDataSchemes() > 0) { addList(pkgList, "Intent Scheme", ""); for (int sIdx = 0; sIdx != resolveInfo.filter.countDataSchemes(); sIdx++) addList(pkgList, " ", resolveInfo.filter.getDataScheme(sIdx)); } if (resolveInfo.filter.countActions() > 0) { addList(pkgList, "Intent Action", ""); for (int aIdx = 0; aIdx != resolveInfo.filter.countActions(); aIdx++) addList(pkgList, " ", resolveInfo.filter.getAction(aIdx)); } if (resolveInfo.filter.countCategories() > 0) { addList(pkgList, "Intent Category", ""); for (int cIdx = 0; cIdx != resolveInfo.filter.countCategories(); cIdx++) addList(pkgList, " ", resolveInfo.filter.getCategory(cIdx)); } if (resolveInfo.filter.countDataTypes() > 0) { addList(pkgList, "Intent DataType", ""); for (int dIdx = 0; dIdx != resolveInfo.filter.countDataTypes(); dIdx++) addList(pkgList, " ", resolveInfo.filter.getDataType(dIdx)); } } m_workList.add( new PackingItem(pkgName.trim(), pkgList, packInfo, orderCnt++, appName, actType)); } catch (Exception ex) { } } } if (false) { // TODO - look into this method, see loadCachedPackages int flags = PackageManager.GET_PROVIDERS; List<PackageInfo> packList = pm.getPreferredPackages(flags); if (packList != null) { for (int pkgIdx = 0; pkgIdx < packList.size(); pkgIdx++) { PackageInfo packInfo = packList.get(pkgIdx); // if (((packInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) == showSys) { addPackageInfo(packInfo); // } } } } } // getPreferredAppInfo(); /* List<ProviderInfo> providerList = getActivity().getPackageManager().queryContentProviders(null, 0, 0); if (providerList != null) { for (ProviderInfo providerInfo : providerList) { String name = providerInfo.name; String pkg = providerInfo.packageName; } } */ }
From source file:com.landenlabs.all_devtool.PackageFragment.java
/** * Load installed (user or system) packages. *//*w w w . j a v a 2 s . c om*/ void loadInstalledPackages() { try { m_workList = new ArrayList<PackingItem>(); int flags1 = PackageManager.GET_PERMISSIONS | PackageManager.GET_PROVIDERS // use hides some app, may require permissions | PackageManager.GET_ACTIVITIES | PackageManager.GET_RECEIVERS // use hides some app, may require permissions | PackageManager.GET_SERVICES; int flags2 = PackageManager.GET_PERMISSIONS | PackageManager.GET_ACTIVITIES | PackageManager.GET_SERVICES; int flags3 = PackageManager.GET_PERMISSIONS; int flags4 = 0; boolean showSys = (m_show == SHOW_SYS); // Some packages will not appear with some flags. loadAndAddPackages(showSys, flags1); loadAndAddPackages(showSys, flags2); loadAndAddPackages(showSys, flags3); loadAndAddPackages(showSys, flags4); // Sort per settings. // TODO *** This does not seem to be working *** Message msgObj = m_handler.obtainMessage(MSG_SORT_LIST); m_handler.sendMessage(msgObj); } catch (Exception ex) { m_log.e(ex.getMessage()); } }