您好,登錄后才能下訂單哦!
這篇文章主要講解了“Android7.0中如何使用MTK設(shè)置默認(rèn)桌面”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“Android7.0中如何使用MTK設(shè)置默認(rèn)桌面”吧!
1.找到安裝應(yīng)用的文件
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); // 由于客戶的應(yīng)用保密 這里使用點(diǎn)心桌面的包名---com.dianxinos.dxhome if (pkgName.equals("com.dianxinos.dxhome")){ //發(fā)送廣播 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.由于設(shè)置默認(rèn)桌面時(shí),是在Settings中設(shè)置的所以廣播接收者在settings中添加并設(shè)置默認(rèn)桌面(添加文件–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(); // 點(diǎn)心桌面的包名類名 com.dianxinos.dxhome / com.nd.hilauncherdev.launcher.Launcher設(shè)置默認(rèn)桌面 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設(shè)置默認(rèn)桌面”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)Android7.0中如何使用MTK設(shè)置默認(rèn)桌面這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。