@Override protected void onPostExecute(String notificationsJson) { super.onPostExecute(notificationsJson); String packageName = this.getClass().getPackage().getName(); SharedPreferences prefs = _context.getSharedPreferences(packageName, Context.MODE_PRIVATE); String title = prefs.getString(Constants.SETTING_TITLE, ""); String icon = prefs.getString(Constants.SETTING_ICON, ""); int iconId = _context.getResources().getIdentifier(icon, "drawable", _context.getPackageName()); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(_context) .setAutoCancel(true) .setSmallIcon(iconId) .setContentTitle(title) .setContentText("Get yer ya-yas out!"); // TODO PackageManager packageManager = _context.getPackageManager(); Intent resultIntent = packageManager.getLaunchIntentForPackage(_context.getPackageName()); // TODO change if want to go to a specific page in PAR Mobile when notification is clicked PendingIntent resultPendingIntent = PendingIntent.getActivity(_context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); notificationBuilder.setContentIntent(resultPendingIntent); NotificationManager notificationManager = (NotificationManager) _context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = notificationBuilder.build(); notificationManager.notify(0, notification); }
private void refreshList() { if (iFavoritesService == null) { Log.i(TAG, "refreshList iFavoritesService null"); return; } try { List<String> favoritesPackageList = iFavoritesService.getFavoritesMap(); mAppInfoList.clear(); for (String packageName : favoritesPackageList) { ApplicationInfo applicationInfo; try { applicationInfo = mPackageManager.getApplicationInfo(packageName, 0); FavoritesAppInfo appInfo = new FavoritesAppInfo(); appInfo.packageName = applicationInfo.packageName; appInfo.appName = applicationInfo.loadLabel(mPackageManager).toString(); appInfo.appIntent = mPackageManager.getLaunchIntentForPackage(applicationInfo.packageName); appInfo.appIcon = applicationInfo.loadIcon(mPackageManager); mAppInfoList.add(appInfo); } catch (NameNotFoundException e) { e.printStackTrace(); } } } catch (RemoteException e) { e.printStackTrace(); } Intent intent = new Intent(FavoritesModel.ACTION_LOAD_FAVOTITE_SUCCESS); mContext.sendBroadcast(intent); }
public Intent getIntent() { Intent intent1 = null; if (intent1 == null) { intent1 = intent; } try { intent = pm.getLaunchIntentForPackage(pkginfo.packageName); if (intent != null) { intent = intent.cloneFilter(); intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); intent1 = intent; } if (pkginfo.activities.length == 1) { intent = new Intent("android.intent.action.MAIN"); intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); intent.setClassName(pkginfo.packageName, pkginfo.activities[0].name); intent1 = intent; } intent = IntentList.getIntent(pkginfo.packageName, pm); if (intent != null) { intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT); intent1 = intent; } } catch (Exception exception) { intent1 = null; } return intent1; }
/** 启动APP */ private void startApp() { PackageManager pm = getPackageManager(); Intent intent = pm.getLaunchIntentForPackage(appInfo.getPackageName()); if (intent != null) { startActivity(intent); } else { Toast.makeText(context, "无法启动", Toast.LENGTH_LONG).show(); } }
// common utility - get intent by label, null if not found public Intent getIntentByLabel(String label) { PackageManager pm = getPackageManager(); for (ApplicationInfo packageInfo : pm.getInstalledApplications(PackageManager.GET_META_DATA)) { if (label.equals(pm.getApplicationLabel(packageInfo))) return pm.getLaunchIntentForPackage(packageInfo.packageName); } return null; }
private void showInstallNotification(ScanResult result) { if (result != null) { PackageInfo pi = null; PackageManager pm = getApplicationContext().getPackageManager(); try { pi = pm.getPackageInfo(packageName, 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } String appName = pm.getApplicationLabel(pi.applicationInfo).toString(); if (result.dangerCount.equals(0)) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.small_icon) .setContentTitle(appName + getString(R.string.app_is_safe)) .setContentText(getString(R.string.open_app)) .setAutoCancel(true); Intent resultIntent = pm.getLaunchIntentForPackage(packageName); PendingIntent resultPendingIntent = PendingIntent.getActivity( getApplicationContext(), 1, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(0, mBuilder.build()); } else { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.small_icon) .setContentTitle(appName + getString(R.string.app_unsafe)) .setContentText(getString(R.string.click_show_result)) .setAutoCancel(true); Intent resultIntent = new Intent(getBaseContext(), ResultActivity.class); // resultIntent.putExtra("CALLED_FROM", ScanService.class.getName()); Bundle bundle = new Bundle(); bundle.putParcelable("SCAN_RESULT", result); resultIntent.putExtras(bundle); PendingIntent resultPendingIntent = PendingIntent.getActivity( getApplicationContext(), 1, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(0, mBuilder.build()); } } }
/** * @Title: startAppByPkgName @Description: 由package name启动应用 * * @param context * @param pkgName * @return * @throws */ public static boolean startAppByPkgName(Context context, String pkgName) { PackageManager packageManager = context.getPackageManager(); Intent intent = new Intent(); intent = packageManager.getLaunchIntentForPackage(pkgName); if (intent == null) { System.out.println("APP not found!"); return false; } context.startActivity(intent); return true; }
@Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) { mCursor.moveToPosition(position); String packagename = mCursor.getString(mCursor.getColumnIndex(AppData.App.PKG_NAME)); Intent intent = pm.getLaunchIntentForPackage(packagename); if (null == intent) { mNotice.showToast(R.string.cannot_start_app); return; } startActivity(intent); }
/** 打开指定包名的App */ public static boolean openAppByPackageName(Context context, String packageName) { if (!TextUtils.isEmpty(packageName)) { PackageManager pm = context.getPackageManager(); Intent launchIntentForPackage = pm.getLaunchIntentForPackage(packageName); if (launchIntentForPackage != null) { context.startActivity(launchIntentForPackage); return true; } } return false; }
@NonNull private List<ApplicationInfo> getAllAppInfos() { List<ApplicationInfo> installedApplications = mPackageManager.getInstalledApplications(0); Iterator<ApplicationInfo> infoIterator = installedApplications.iterator(); while (infoIterator.hasNext()) { ApplicationInfo next = infoIterator.next(); if (mPackageManager.getLaunchIntentForPackage(next.packageName) == null) { infoIterator.remove(); } } return installedApplications; }
private void addApp(final String[] packages, int i) { ApplicationInfo applicationInfo; try { applicationInfo = mPackageManager.getApplicationInfo(packages[i], 0); FavoritesAppInfo appInfo = new FavoritesAppInfo(); appInfo.packageName = applicationInfo.packageName; appInfo.appName = applicationInfo.loadLabel(mPackageManager).toString(); appInfo.appIntent = mPackageManager.getLaunchIntentForPackage(applicationInfo.packageName); appInfo.appIcon = applicationInfo.loadIcon(mPackageManager); FavoritesData.mAppsAll.add(appInfo); } catch (NameNotFoundException e) { e.printStackTrace(); } }
private void openMaps() { // check to see if maps is installed try { PackageManager mManager = getPackageManager(); mManager.getApplicationInfo("org.servalproject.maps", PackageManager.GET_META_DATA); Intent mIntent = mManager.getLaunchIntentForPackage("org.servalproject.maps"); mIntent.addCategory(Intent.CATEGORY_LAUNCHER); startActivity(mIntent); } catch (NameNotFoundException e) { startActivity(new Intent(getApplicationContext(), org.servalproject.ui.MapsActivity.class)); } }
private List<ApplicationInfo> checkForLaunchIntent(List<ApplicationInfo> list) { ArrayList<ApplicationInfo> applist = new ArrayList<ApplicationInfo>(); for (ApplicationInfo info : list) { try { if (null != packageManager.getLaunchIntentForPackage(info.packageName)) { applist.add(info); } } catch (Exception e) { e.printStackTrace(); } } return applist; }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ApplicationInfo appInfo = (ApplicationInfo) parent.getItemAtPosition(position); Intent intent = pm.getLaunchIntentForPackage(appInfo.packageName); ResolveInfo ri = pm.resolveActivity(intent, 0); String launchableActivity = ri.activityInfo.name; String intentString = String.format("%1$s%2$s%3$s", appInfo.packageName, separator, launchableActivity); setSummary(intentString == null ? mSummary : appInfo.loadLabel(pm)); persistString(intentString); mValue = intentString; appIcon = appInfo.loadIcon(pm); getDialog().dismiss(); }
/** 打开应用程序 */ public static boolean openApp(Context context, String packageName) { if (!TextUtils.isEmpty(packageName)) { // 默认按getLaunchIntentForPackage方式启动 PackageManager pm = context.getPackageManager(); Intent launchIntentForPackage = pm.getLaunchIntentForPackage(packageName); if (launchIntentForPackage != null) { launchIntentForPackage.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); context.startActivity(launchIntentForPackage); return true; } } return false; }
private void showVPN() { try { PackageManager manager = mContext.getPackageManager(); Intent intent = manager.getLaunchIntentForPackage("app.openconnect"); // intent.putExtra("Fp", "upb ssl"); // zum direkten Öffenen der FP-Einstellungen, sonst // weglassen intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // TODO: wirklich notwendig ? mContext.startActivity(intent); } catch (Exception e) { e.printStackTrace(); Toast.makeText(mContext, "VPN App ist nicht installiert", Toast.LENGTH_SHORT).show(); } }
private void startApp() { Intent i; PackageManager manager = getPackageManager(); try { i = manager.getLaunchIntentForPackage(mAppSettings.getPackageName()); if (i == null) throw new PackageManager.NameNotFoundException(); // start like the Android launcher would do i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); i.addCategory(Intent.CATEGORY_LAUNCHER); startActivity(i); } catch (PackageManager.NameNotFoundException e) { Log.e(Constants.TAG, "startApp", e); } }
/** * 根据包名启动指定的应用 * * @param context * @param packageName * @return */ public static boolean startActivityByPackageName(Context context, String packageName) { try { PackageManager pm = context.getPackageManager(); if (pm != null) { Intent intent = pm.getLaunchIntentForPackage(packageName); if (intent != null) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); return true; } } } catch (Throwable e) { } return false; }
public void launchApp(String pocketName) { PackageManager packageManager = this.getPackageManager(); List<PackageInfo> packages = getAllApps(); PackageInfo pa = null; for (int i = 0; i < packages.size(); i++) { pa = packages.get(i); // 获得应用名 String appLabel = packageManager.getApplicationLabel(pa.applicationInfo).toString(); // 获得包名 String appPackage = pa.packageName; Log.d("" + i, appLabel + " " + appPackage); } newintent = packageManager.getLaunchIntentForPackage(pocketName); startActivity(newintent); }
private static boolean canPreventSystemPackage(PackageManager pm, ApplicationInfo appInfo) { // cannot prevent launcher if (isLauncher(pm, appInfo.packageName)) { return false; } // can prevent system packages with launcher if (pm.getLaunchIntentForPackage(appInfo.packageName) != null) { return true; } if (!isSystemSignaturePackage(pm, BuildConfig.APPLICATION_ID)) { return !isSystemSignaturePackage(pm, appInfo.packageName); } else { return GmsUtils.isGapps(pm, appInfo.packageName); } }
@Override protected void onHandleIntent(Intent intent) { Log.v(ApeicUtil.TAG_HTTP, "UpdateInstalledAppsIntentService onHandleIntent"); PackageManager pm = getPackageManager(); Set<String> currInstalledApps = new HashSet<String>(); for (ApplicationInfo info : pm.getInstalledApplications(PackageManager.GET_META_DATA)) { if (pm.getLaunchIntentForPackage(info.packageName) != null) { currInstalledApps.add(info.packageName); } } ApeicPrefsUtil prefsUtil = ApeicPrefsUtil.getInstance(this); Set<String> registeringApps = prefsUtil.getStringSetPref(ApeicPrefsUtil.KEY_REGISTERING_APPS); if (registeringApps.size() > 0) { Log.v(ApeicUtil.TAG_HTTP, "Re-update newly installed apps."); registerApps(prefsUtil.getStringSetPref(ApeicPrefsUtil.KEY_REGISTERING_APPS)); } Set<String> unregisteringApps = prefsUtil.getStringSetPref(ApeicPrefsUtil.KEY_REGISTERING_APPS); if (unregisteringApps.size() > 0) { Log.v(ApeicUtil.TAG_HTTP, "Re-update uninstalled installed apps."); unregisterApps(prefsUtil.getStringSetPref(ApeicPrefsUtil.KEY_UNREGISTERING_APPS)); } if (prefsUtil.getPrefs().contains(ApeicPrefsUtil.KEY_INSTALLED_APPS)) { Set<String> lastInstalledApps = prefsUtil.getStringSetPref(ApeicPrefsUtil.KEY_INSTALLED_APPS); Set<String> newlyInstalledApps = getNewlyInstalledApps(currInstalledApps, lastInstalledApps); if (newlyInstalledApps.size() > 0) { Log.v(ApeicUtil.TAG_HTTP, "Newly installed Apps: "); registerApps(newlyInstalledApps); } Set<String> removedApps = getUninstalledApps(currInstalledApps, lastInstalledApps); if (removedApps.size() > 0) { Log.v(ApeicUtil.TAG_HTTP, "Uninstalled Apps: "); unregisterApps(removedApps); } } else { Log.v(ApeicUtil.TAG_HTTP, "Current installed Apps: "); registerApps(currInstalledApps); } ApeicPrefsUtil.getInstance(this) .setStringSetPref(ApeicPrefsUtil.KEY_INSTALLED_APPS, currInstalledApps); }
private List<ApplicationInfo> createAppList() { ArrayList<ApplicationInfo> appList = new ArrayList<ApplicationInfo>(); List<ApplicationInfo> list = pm.getInstalledApplications(PackageManager.GET_META_DATA); int l = list.size(); for (int i = 0; i < l; i++) { try { if (pm.getLaunchIntentForPackage(list.get(i).packageName) != null) { appList.add(list.get(i)); } } catch (Exception ex) { ex.printStackTrace(); } } return appList; }
@Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); ApplicationInfo app = applist.get(position); try { Intent intent = packageManager.getLaunchIntentForPackage(app.packageName); if (null != intent) { startActivity(intent); } } catch (ActivityNotFoundException e) { Toast.makeText(AllAppsActivity.this, e.getMessage(), Toast.LENGTH_LONG).show(); } catch (Exception e) { Toast.makeText(AllAppsActivity.this, e.getMessage(), Toast.LENGTH_LONG).show(); } }
public static void resetGoogleNowOnly(Context context) { Intent i; PackageManager manager = context.getPackageManager(); try { i = manager.getLaunchIntentForPackage(GOOGLE_PKG); if (i == null) throw new PackageManager.NameNotFoundException(); i.addCategory(Intent.CATEGORY_LAUNCHER); i.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); context.startActivity(i); } catch (PackageManager.NameNotFoundException e) { } }
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.app, menu); // Launch PackageManager pm = getPackageManager(); if (pm.getLaunchIntentForPackage(mAppInfo.getPackageName()) == null) menu.findItem(R.id.menu_app_launch).setEnabled(false); // Play boolean hasMarketLink = Util.hasMarketLink(this, mAppInfo.getPackageName()); menu.findItem(R.id.menu_app_store).setEnabled(hasMarketLink); return true; }
public static boolean packageIsInstalled(String packageName, Context context) { boolean installed = false; try { PackageManager pm = context.getPackageManager(); Intent pi = pm.getLaunchIntentForPackage(packageName); if (pi != null) { List<ResolveInfo> list = pm.queryIntentActivities(pi, PackageManager.MATCH_DEFAULT_ONLY); if (list.size() > 0) { installed = true; } } } catch (Exception e) { } return installed; }
private void populatePreferences() { final PackageManager packageManager = getActivity().getPackageManager(); List<PackageInfo> allInstalledPackages = packageManager.getInstalledPackages(PackageManager.GET_META_DATA); PreferenceScreen screen = getPreferenceScreen(); Collections.sort( allInstalledPackages, new Comparator<PackageInfo>() { @Override public int compare(PackageInfo p1, PackageInfo p2) { return packageManager .getApplicationLabel(p1.applicationInfo) .toString() .compareTo(packageManager.getApplicationLabel(p2.applicationInfo).toString()); } }); for (PackageInfo p : allInstalledPackages) { if (packageManager.getLaunchIntentForPackage(p.packageName) == null) { continue; } CheckBoxPreference pref = new CheckBoxPreference(screen.getContext()); pref.setKey(getString(R.string.pref_app_notif_base) + "-" + p.packageName); pref.setTitle(packageManager.getApplicationLabel(p.applicationInfo)); pref.setIcon(packageManager.getApplicationIcon(p.applicationInfo)); pref.setChecked( PreferenceManager.getDefaultSharedPreferences(getActivity()) .getBoolean(getString(R.string.pref_app_notif_base) + "-" + p.packageName, true)); pref.setOnPreferenceChangeListener( new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Bundle b = new Bundle(); b.putString( getString(R.string.analytics_param_app_name), preference.getTitle().toString()); String newValueStr = newValue.toString().equals("true") ? "enabled" : "disabled"; b.putString(getString(R.string.analytics_param_new_value), newValueStr); ((PreferencesActivity) getActivity()) .firebaseAnalytics.logEvent(getString(R.string.analytics_tap_app), b); return true; } }); screen.addPreference(pref); } }
public void medicine_inform(View view) { listPackages(); Log.d("mxt", "paglist的大小:" + pagList.size()); for (int i = 0; i < pagList.size(); i++) { Log.d("mxt", pagList.get(i)); } PackageManager pm = getPackageManager(); Intent i = pm.getLaunchIntentForPackage(pagList.get(0)); // 如果该程序不可启动(像系统自带的包,有很多是没有入口的)会返回NULL if (i != null) { startActivity(i); } else { Intent i2 = new Intent(Settings.ACTION_DATE_SETTINGS); startActivity(i); } }
public ArrayList<String> getAppsInstalled() { PackageManager packageManager = context.getPackageManager(); ArrayList<ApplicationInfo> listApp = (ArrayList<ApplicationInfo>) packageManager.getInstalledApplications(PackageManager.GET_ACTIVITIES); Iterator<ApplicationInfo> iterator = listApp.iterator(); ArrayList<String> lstApps = new ArrayList<String>(); while (iterator.hasNext()) { ApplicationInfo appInfo = (ApplicationInfo) iterator.next(); Intent intent = packageManager.getLaunchIntentForPackage(appInfo.packageName); if (intent != null) { lstApps.add(appInfo.packageName); } } return lstApps; }
/** * 启动程序 */ private void startApplication() { // TODO Auto-generated method stub //查询此应用程序的入口activity,然后启动 //包管理器 PackageManager pm = getPackageManager(); // Intent intent = new Intent(); // intent.setAction("android.intent.action.MAIN"); // intent.addCategory("android.intent.category.LAUNCHER"); // //查询手机上的所有具有驱动能力的activity // List<ResolveInfo> infos = pm.queryIntentActivities(intent, PackageManager.GET_INTENT_FILTERS); //启动所点击的应用 Intent intent = pm.getLaunchIntentForPackage(appInfo.getPackname()); if (intent != null) { startActivity(intent); } else { Toast.makeText(this, "无法启动", 0).show(); } }