判断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

判断Android中应用是否为默认启动的方法,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。