您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
这篇文章主要讲解了“Android7.0中如何使用MTK设置默认桌面”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Android7.0中如何使用MTK设置默认桌面”吧!
1.找到安装应用的文件
frameworks\base\services\core\java\com\android\server\pm\PackageManagerService.java try { PackageParser.Package newPackage = scanPackageTracedLI(pkg, policyFlags, scanFlags, System.currentTimeMillis(), user); updateSettingsLI(newPackage, installerPackageName, null, res, user); if (res.returnCode == PackageManager.INSTALL_SUCCEEDED) { prepareAppDataAfterInstallLIF(newPackage); Log.d("yh", "pkgName " +pkgName); // 由于客户的应用保密 这里使用点心桌面的包名---com.dianxinos.dxhome if (pkgName.equals("com.dianxinos.dxhome")){ //发送广播 Intent intent = new Intent("android.intent.action.UPDATE_LANUCHER_APPS"); mContext.sendBroadcast(intent); } //------------------------ } else { // Remove package from internal structures, but keep around any // data that might have already existed deletePackageLIF(pkgName, UserHandle.ALL, false, null, PackageManager.DELETE_KEEP_DATA, res.removedInfo, true, null); } } catch (PackageManagerException e) { res.setError("Package couldn't be installed in " + pkg.codePath, e); } Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); }
2.由于设置默认桌面时,是在Settings中设置的所以广播接收者在settings中添加并设置默认桌面(添加文件–packages\apps\Settings\src\com\android\settings下—UpdateLanucherReceiver.java)
package com.android.settings; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.ComponentName; import android.content.IntentFilter; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import java.util.ArrayList; import android.util.Log; import android.content.pm.ActivityInfo; import java.util.List; public class UpdateLanucherReceiver extends BroadcastReceiver { public UpdateLanucherReceiver() { } @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals("android.intent.action.UPDATE_LANUCHER_APPS")) { Log.e("yhyh" ," onReceive"); final PackageManager mPm = context.getPackageManager(); // 点心桌面的包名类名 com.dianxinos.dxhome / com.nd.hilauncherdev.launcher.Launcher设置默认桌面 ComponentName DefaultLauncher=new ComponentName(" com.dianxinos.dxhome", "com.nd.hilauncherdev.launcher.Launcher"); ArrayList<ResolveInfo> homeActivities = new ArrayList<ResolveInfo>(); ComponentName currentDefaultHome = mPm.getHomeActivities(homeActivities); ComponentName[]mHomeComponentSet = new ComponentName[homeActivities.size()]; for (int i = 0; i < homeActivities.size(); i++) { final ResolveInfo candidate = homeActivities.get(i); Log.e("yhyh","homeActivitie: candidate = "+candidate); final ActivityInfo activityInfo= candidate.activityInfo; ComponentName activityName = new ComponentName(activityInfo.packageName, activityInfo.name); mHomeComponentSet[i] = activityName; } IntentFilter mHomeFilter = new IntentFilter(Intent.ACTION_MAIN); mHomeFilter.addCategory(Intent.CATEGORY_HOME); mHomeFilter.addCategory(Intent.CATEGORY_DEFAULT); List<ComponentName>Activities=new ArrayList(); mPm.replacePreferredActivity(mHomeFilter, IntentFilter.MATCH_CATEGORY_EMPTY,mHomeComponentSet, DefaultLauncher); //刷新桌面 Intent intent2 = new Intent(Intent.ACTION_MAIN); intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent2.addCategory(Intent.CATEGORY_HOME); context.startActivity(intent2); } } }
3.packages\apps\Settings\AndroidManifest.xml
<!-- yh --> <receiver android:name=".UpdateLanucherReceiver" > <intent-filter> <action android:name="android.intent.action.UPDATE_LANUCHER_APPS" /> </intent-filter> </receiver>
感谢各位的阅读,以上就是“Android7.0中如何使用MTK设置默认桌面”的内容了,经过本文的学习后,相信大家对Android7.0中如何使用MTK设置默认桌面这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。