android如何获取默认的桌面程序
生活随笔
收集整理的這篇文章主要介紹了
android如何获取默认的桌面程序
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
【方法1】
http://stackoverflow.com/questions/12594192/remove-activity-as-default-launcher/12594332#12594332
?
桌面應用的啟動在INTENT中需要包含ACTION_MAIN?和CATEGORY_HOME.
通過PackageManager的resolveActivity方法來獲取一個?ResolveInfo?對象來得知哪個是默認啟動的Activity?
?
private void getDefaultHome() {final Intent intent = new Intent(Intent.ACTION_MAIN);intent.addCategory(Intent.CATEGORY_HOME);final ResolveInfo res = getPackageManager().resolveActivity(intent, 0);if (res.activityInfo == null) {Log.d(TAG, "resolveActivity--->activityInfo null");// should not happen. A home is always installed, isn't it?} else if (res.activityInfo.packageName.equals("android")) {// No default selectedLog.d(TAG, "resolveActivity--->無默認設置");} else {// res.activityInfo.packageName and res.activityInfo.name gives// you the default appLog.d(TAG, "默認桌面為:" + res.activityInfo.packageName + "."+ res.activityInfo.name);}}?
?【方法2】
http://stackoverflow.com/questions/8299427/how-to-check-if-my-application-is-the-default-launcher/8361115#8361115
利用PackageManager里的getPreferredActivities()方法
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 argumentpackageManager.getPreferredActivities(filters, activities, null);for (ComponentName activity : activities) {if (myPackageName.equals(activity.getPackageName())) {return true;}}return false; }?
轉載于:https://www.cnblogs.com/lqstayreal/p/3192712.html
總結
以上是生活随笔為你收集整理的android如何获取默认的桌面程序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于iOS 5 Could not in
- 下一篇: Android组件的使用:RadioBu