Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> 判斷Android中應用是否為默認啟動的方法

判斷Android中應用是否為默認啟動的方法

編輯:關於Android編程

方法一:

boolean isMyLauncherDefault() {
    final IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN);
    filter.addCategory(Intent.CATEGORY_HOME);

    List filters = new ArrayList();
    filters.add(filter);

    final String myPackageName = getPackageName();
    List activities = new ArrayList();
    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 filters = new ArrayList();
    filters.add(filter);
 
    // the packageName of your application
    String packageName = getPackageName();
    List preferredActivities = new ArrayList();
    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

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved