当前位置: 代码迷 >> Android >> 判断Android中应用是否为默许启动的方法
  详细解决方案

判断Android中应用是否为默许启动的方法

热度:23   发布时间:2016-04-28 06:09:11.0
判断Android中应用是否为默认启动的方法

方法一:

boolean isMyLauncherDefault() {    final IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN);    filter.addCategory(Intent.CATEGORY_HOME);    List<IntentFilter> filters = new ArrayList<IntentFilter>();    filters.add(filter);    final String myPackageName = getPackageName();    List<ComponentName> activities = new ArrayList<ComponentName>();    final PackageManager packageManager = (PackageManager) getPackageManager();    // You can use name of your package here as third argument    packageManager.getPreferredActivities(filters, activities, null);    for (ComponentName activity : activities) {        if (myPackageName.equals(activity.getPackageName())) {            return true;        }    }    return false;}

方法二

public boolean isMyAppLauncherDefault() {    IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN);    filter.addCategory(Intent.CATEGORY_HOME);     List<IntentFilter> filters = new ArrayList<IntentFilter>();    filters.add(filter);     // the packageName of your application    String packageName = getPackageName();    List<ComponentName> preferredActivities = new ArrayList<ComponentName>();    final PackageManager packageManager = (PackageManager) getPackageManager();     // You can use name of your package here as third argument    packageManager.getPreferredActivities(filters, preferredActivities, packageName);     if (preferredActivities != null && preferredActivities.size()> 0) {        return true;    }    return false;} 



http://www.android-ios-tutorials.com/225/get-default-launcher-pogrammatically-android/

http://stackoverflow.com/questions/10188954/start-launcher-selection-programmatically-android

  相关解决方案