List of usage examples for android.content.pm PackageManager getInstalledApplications
public abstract List<ApplicationInfo> getInstalledApplications(@ApplicationInfoFlags int flags);
From source file:org.adaway.util.ScanAdwareLoader.java
/** * Finds all installed packages that look like they include a known ad framework *//*from ww w.ja va2s .c o m*/ private List<PackageInfo> getAdPackages() { Set<PackageInfo> adPackages = new HashSet<PackageInfo>(); PackageManager pm = context.getPackageManager(); // It'd be simpler to just use pm.getInstalledPackages here, but apparently it's broken List<ApplicationInfo> appInfos = pm.getInstalledApplications(0); for (ApplicationInfo appInfo : appInfos) { if (canceled) { adPackages.clear(); break; } try { PackageInfo pkgInfo = pm.getPackageInfo(appInfo.packageName, PackageManager.GET_ACTIVITIES | PackageManager.GET_RECEIVERS | PackageManager.GET_SERVICES); Log.v(Constants.TAG, "Scanning package " + pkgInfo.packageName); if (pkgInfo.activities != null) { for (ActivityInfo activity : pkgInfo.activities) { Log.v(Constants.TAG, "[ACTIVITY] " + activity.name); for (String adPackagePrefix : AD_PACKAGE_PREFIXES) { if (activity.name.startsWith(adPackagePrefix)) { Log.i(Constants.TAG, "Detected ad framework prefix " + adPackagePrefix + " in package " + pkgInfo.packageName + " as activity " + activity.name); adPackages.add(pkgInfo); } } } } if (pkgInfo.receivers != null) { for (ActivityInfo receiver : pkgInfo.receivers) { Log.v(Constants.TAG, "[RECEIVER] " + receiver.name); for (String adPackagePrefix : AD_PACKAGE_PREFIXES) { if (receiver.name.startsWith(adPackagePrefix)) { Log.i(Constants.TAG, "Detected ad framework prefix " + adPackagePrefix + " in package " + pkgInfo.packageName + " as receiver " + receiver.name); adPackages.add(pkgInfo); break; } } } } if (pkgInfo.services != null) { for (ServiceInfo service : pkgInfo.services) { Log.v(Constants.TAG, "[SERVICE] " + service.name); for (String adPackagePrefix : AD_PACKAGE_PREFIXES) { if (service.name.startsWith(adPackagePrefix)) { Log.i(Constants.TAG, "Detected ad framework prefix " + adPackagePrefix + " in package " + pkgInfo.packageName + " as service " + service.name); adPackages.add(pkgInfo); break; } } } } } catch (Exception e) { Log.e(Constants.TAG, "Scan Adware Exception", e); } } return new ArrayList<PackageInfo>(adPackages); }
From source file:ar.org.fsadosky.iptablesmanager.fragment.ApplicationsListFragment.java
private ArrayList<ApplicationItem> getDeviceApplications() { final PackageManager packageManager = getActivity().getPackageManager(); List<ApplicationInfo> installedApplications = packageManager .getInstalledApplications(PackageManager.GET_META_DATA); Map<Integer, ApplicationItem> applicationItemMap = new HashMap<Integer, ApplicationItem>(); for (ApplicationInfo applicationInfo : installedApplications) { if (PackageManager.PERMISSION_GRANTED == packageManager.checkPermission(Manifest.permission.INTERNET, applicationInfo.packageName)) { String appName = (String) (applicationInfo != null ? packageManager.getApplicationLabel(applicationInfo) : "(unknown)"); Uri appIconUri = null;//w w w . ja v a 2 s . c o m if (applicationInfo.icon != 0) { appIconUri = Uri.parse( "android.resource://" + applicationInfo.packageName + "/" + applicationInfo.icon); } int appUid = applicationInfo.uid; if (applicationItemMap.containsKey(appUid)) { ApplicationItem applicationItem = applicationItemMap.get(appUid); applicationItem.addApplication(appName); applicationItemMap.put(appUid, applicationItem); } else { applicationItemMap.put(appUid, new ApplicationItem(appIconUri, appName, appUid)); } } } return new ArrayList<ApplicationItem>(applicationItemMap.values()); }
From source file:com.thejoshwa.ultrasonic.androidapp.util.Util.java
public static boolean isPackageInstalled(Context context, String packageName) { PackageManager pm = context.getPackageManager(); List<ApplicationInfo> packages = pm.getInstalledApplications(0); for (ApplicationInfo packageInfo : packages) { if (packageInfo.packageName.equals(packageName)) { return true; }/*from w w w .j a va2 s . c o m*/ } return false; }
From source file:com.framgia.android.emulator.EmulatorDetector.java
private boolean checkPackageName() { final PackageManager packageManager = mContext.getPackageManager(); List<ApplicationInfo> packages = packageManager.getInstalledApplications(PackageManager.GET_META_DATA); for (ApplicationInfo packageInfo : packages) { String packageName = packageInfo.packageName; boolean isEmulator = mListPackageName.contains(packageName); if (isEmulator) { log("Detected " + packageName); return true; }//www .ja v a2 s .co m } return false; }
From source file:io.rapidpro.androidchannel.RapidPro.java
public void refreshInstalledPacks() { final PackageManager pm = getPackageManager(); List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA); List<String> packs = new ArrayList<String>(); for (ApplicationInfo packageInfo : packages) { if (packageInfo.packageName.startsWith("io.rapidpro.androidchannel")) { packs.add(packageInfo.packageName); }/*from ww w.j a v a 2s.c o m*/ } LOG.d("Found " + packs.size() + " installed messaging packs"); for (String pack : packs) { LOG.d(" - " + pack); } m_installedPacks = packs; }
From source file:com.tomer.alwayson.SettingsFragment.java
public boolean isPackageInstalled(String targetPackage) { List<ApplicationInfo> packages; PackageManager pm; pm = context.getPackageManager();// w w w . ja v a 2 s.c om packages = pm.getInstalledApplications(0); for (ApplicationInfo packageInfo : packages) { if (packageInfo.packageName.equals(targetPackage)) return true; } return false; }
From source file:org.deviceconnect.android.manager.setting.DevicePluginInfoFragment.java
/** * Tests whether packageName exists in application list. * * @param packageName package name/*from w w w . j a v a 2s .co m*/ * @return true if packageName exists, false otherwise */ private boolean existApplicationFromPackageName(final String packageName) { if (packageName == null) { return false; } final PackageManager pm = getActivity().getPackageManager(); final int flags = PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.MATCH_DISABLED_COMPONENTS; final List<ApplicationInfo> installedAppList = pm.getInstalledApplications(flags); for (ApplicationInfo app : installedAppList) { if (app.packageName.equals(packageName)) { return true; } } return false; }
From source file:qauth.djd.qauthclient.main.ContentFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Bundle args = getArguments();//from w w w. j a v a 2 s .c o m if (args.getCharSequence(KEY_TITLE).toString().equals("Providers")) { View rootView = inflater.inflate(R.layout.providers_view_frag, container, false); mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView); mLayoutManager = new LinearLayoutManager(getActivity()); mCurrentLayoutManagerType = LayoutManagerType.LINEAR_LAYOUT_MANAGER; if (savedInstanceState != null) { // Restore saved layout manager type. mCurrentLayoutManagerType = (LayoutManagerType) savedInstanceState .getSerializable(KEY_LAYOUT_MANAGER); } setRecyclerViewLayoutManager(mCurrentLayoutManagerType); pAdapter = new ProviderAdapter(pDataset); mRecyclerView.setAdapter(pAdapter); final PackageManager pm = getActivity().getPackageManager(); List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA); for (ApplicationInfo packageInfo : packages) { //Log.i(TAG, "Installed package :" + packageInfo.packageName); //Log.i(TAG, "Source dir : " + packageInfo.sourceDir); //Log.i(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName)); if (packageInfo.packageName.equals("qauth.djd.dummyclient")) { Provider provider = new Provider("DummyClient", packageInfo.packageName); pDataset.add(provider); pAdapter.notifyDataSetChanged(); } } //get local package names and cross reference with providers on server ("/provider/available") //display package names in listview //allow user to click on item to activate or deactivate // '-> have check box with progress bar indicating status return rootView; } else { View rootView = inflater.inflate(R.layout.recycler_view_frag, container, false); mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView); mLayoutManager = new LinearLayoutManager(getActivity()); mCurrentLayoutManagerType = LayoutManagerType.LINEAR_LAYOUT_MANAGER; if (savedInstanceState != null) { // Restore saved layout manager type. mCurrentLayoutManagerType = (LayoutManagerType) savedInstanceState .getSerializable(KEY_LAYOUT_MANAGER); } setRecyclerViewLayoutManager(mCurrentLayoutManagerType); wAdapter = new WatchAdapter(wDataset); mRecyclerView.setAdapter(wAdapter); FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.fab); fab.attachToRecyclerView(mRecyclerView); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.i("test", "clicked!"); AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity()); builderSingle.setIcon(R.drawable.ic_launcher); builderSingle.setTitle("Select Bluetooth Device"); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.select_dialog_singlechoice); new Thread(new Runnable() { public void run() { for (String s : getNodes()) { arrayAdapter.add(s); } } }).start(); builderSingle.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String nodeId = arrayAdapter.getItem(which); String privKey = null; String pubKey = null; try { SecureRandom random = new SecureRandom(); RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(1024, RSAKeyGenParameterSpec.F4); KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA", "SC"); generator.initialize(spec, random); KeyPair pair = generator.generateKeyPair(); privKey = Base64.encodeToString(pair.getPrivate().getEncoded(), Base64.DEFAULT); pubKey = Base64.encodeToString(pair.getPublic().getEncoded(), Base64.DEFAULT); } catch (Exception e) { Log.i("generate", "error: " + e); } //Log.i("keys", "priv key : " + privKey); //String privKey = Base64.encodeToString(MainTabsActivity.privKey.getEncoded(), Base64.DEFAULT); //String pubKey = Base64.encodeToString(MainTabsActivity.pubKey.getEncoded(), Base64.DEFAULT); Keys keys = new Keys(privKey, pubKey); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutput out = null; try { out = new ObjectOutputStream(bos); } catch (Exception e) { } try { out.writeObject(keys); } catch (Exception e) { } byte b[] = bos.toByteArray(); try { out.close(); } catch (Exception e) { } try { bos.close(); } catch (Exception e) { } Wearable.MessageApi.sendMessage(mGoogleApiClient, nodeId, "REGISTER", b) .setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() { @Override public void onResult(MessageApi.SendMessageResult sendMessageResult) { if (!sendMessageResult.getStatus().isSuccess()) { Log.i("MessageApi", "Failed to send message with status code: " + sendMessageResult.getStatus().getStatusCode()); } else if (sendMessageResult.getStatus().isSuccess()) { Log.i("MessageApi", "onResult successful!"); } } }); } }); builderSingle.show(); } }); mGoogleApiClient = new GoogleApiClient.Builder(getActivity()).addConnectionCallbacks(this) .addOnConnectionFailedListener( new com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener() { @Override public void onConnectionFailed(ConnectionResult result) { Log.i("mGoogleApiClient", "onConnectionFailed: " + result); } }) // Request access only to the Wearable API .addApi(Wearable.API).build(); mGoogleApiClient.connect(); /*BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices(); for(BluetoothDevice bt : pairedDevices) Log.i("BluetoothDevice", "pairedDevice: " + bt.toString());*/ return rootView; } }
From source file:jackpal.androidterm.TermPreferences.java
private void setAppPickerList() { PackageManager pm = this.getApplicationContext().getPackageManager(); final List<ApplicationInfo> installedAppList = pm.getInstalledApplications(0); final TreeMap<String, String> items = new TreeMap<>(); for (ApplicationInfo app : installedAppList) { Intent intent = pm.getLaunchIntentForPackage(app.packageName); if (intent != null) items.put(app.loadLabel(pm).toString(), app.packageName); }// w w w .ja v a 2 s .com List<String> list = new ArrayList<>(items.keySet()); final String labels[] = list.toArray(new String[list.size()]); list = new ArrayList<>(items.values()); final String packageNames[] = list.toArray(new String[list.size()]); String id = "external_app_package_name"; ListPreference packageName = (ListPreference) getPreferenceScreen().findPreference(id); packageName.setEntries(labels); packageName.setEntryValues(packageNames); }
From source file:com.tweetlanes.android.App.java
@Override public void onCreate() { Log.d("tweetlanes url fetch", "*** New run"); Log.d("AsyncTaskEx", "*** New run"); Log.d("StatusCache", "*** New run"); super.onCreate(); java.util.logging.Logger.getLogger("org.apache.http.wire").setLevel(java.util.logging.Level.FINEST); java.util.logging.Logger.getLogger("org.apache.http.headers").setLevel(java.util.logging.Level.FINEST); System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "debug"); System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "debug"); System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.headers", "debug"); try {//from w w w. jav a 2s . com PackageManager packageManager = getPackageManager(); PackageInfo packageInfo = packageManager.getPackageInfo(getPackageName(), 0); mAppVersionName = packageInfo.versionName; List<ApplicationInfo> apps = packageManager.getInstalledApplications(PackageManager.GET_META_DATA); for (ApplicationInfo app : apps) { if (app.packageName != null && app.packageName.equalsIgnoreCase("com.chrislacy.actionlauncher.pro")) { mActionLauncherInstalled = true; break; } } } catch (NameNotFoundException e) { e.printStackTrace(); } mPreferences = PreferenceManager.getDefaultSharedPreferences(this); mPreferences.edit().putInt(SHARED_PREFERENCES_KEY_VERSION, Constant.SHARED_PREFERENCES_VERSION); mAccounts = new ArrayList<AccountDescriptor>(); updateTwitterAccountCount(); SocialNetConstant.Type socialNetType = SocialNetConstant.Type.Twitter; AccountDescriptor currentAccountDescriptor = getCurrentAccount(); if (currentAccountDescriptor != null) { socialNetType = currentAccountDescriptor.getSocialNetType(); if (socialNetType == null) { socialNetType = SocialNetConstant.Type.Twitter; } TwitterManager.initModule(socialNetType, socialNetType == SocialNetConstant.Type.Twitter ? ConsumerKeyConstants.TWITTER_CONSUMER_KEY : ConsumerKeyConstants.APPDOTNET_CONSUMER_KEY, socialNetType == SocialNetConstant.Type.Twitter ? ConsumerKeyConstants.TWITTER_CONSUMER_SECRET : ConsumerKeyConstants.TWITTER_CONSUMER_SECRET, currentAccountDescriptor.getOAuthToken(), currentAccountDescriptor.getOAuthSecret(), currentAccountDescriptor.getAccountKey(), mConnectionStatusCallbacks); } else { TwitterManager.initModule(SocialNetConstant.Type.Twitter, ConsumerKeyConstants.TWITTER_CONSUMER_KEY, ConsumerKeyConstants.TWITTER_CONSUMER_SECRET, null, null, null, mConnectionStatusCallbacks); } setLaneDefinitions(socialNetType); AppSettings.initModule(this); }