當(dāng)系統(tǒng)存在多個(gè)launcher時(shí),若沒(méi)有設(shè)置默認(rèn)launcher,開(kāi)機(jī)啟動(dòng)后會(huì)彈出提示框,羅列所有l(wèi)auncher,用戶(hù)選擇并設(shè)置了默認(rèn)launcher后,按home鍵以及以后重啟都會(huì)進(jìn)入默認(rèn)的launcher。
“只有客戶(hù)發(fā)展了,才有我們的生存與發(fā)展!”這是創(chuàng)新互聯(lián)公司的服務(wù)宗旨!把網(wǎng)站當(dāng)作互聯(lián)網(wǎng)產(chǎn)品,產(chǎn)品思維更注重全局思維、需求分析和迭代思維,在網(wǎng)站建設(shè)中就是為了建設(shè)一個(gè)不僅審美在線(xiàn),而且實(shí)用性極高的網(wǎng)站。創(chuàng)新互聯(lián)對(duì)網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、網(wǎng)站制作、網(wǎng)站開(kāi)發(fā)、網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站優(yōu)化、網(wǎng)絡(luò)推廣、探索永無(wú)止境。現(xiàn)在,我希望系統(tǒng)能直接就進(jìn)入我設(shè)定的launcher而不是彈出框后選擇然后設(shè)置
網(wǎng)上大部分的做法就是修改
packages/apps/Provision/src/com/android/DefaultActivity.java
和
frameworks/base/services/java/com/android/server/pm/PackageManagerService.java
兩個(gè)文件,給個(gè)相對(duì)比較好看一點(diǎn)的鏈接http://blog.csdn.net/z_guijin/article/details/8964890
我按照這個(gè)做不能達(dá)到預(yù)期的效果,
/////////////////////////////////////////添加內(nèi)容////////////////////////////////////////
后期修改包名,發(fā)現(xiàn)開(kāi)機(jī)自啟動(dòng)出現(xiàn)問(wèn)題,然后弄了兩天,終于差不多弄清楚了。果然,欠下的債遲早得還!
其實(shí)修改DefaultActivity.java就能夠完成開(kāi)機(jī)自啟動(dòng),只是當(dāng)時(shí)我的程序有問(wèn)題,所以沒(méi)有達(dá)到預(yù)期效果
當(dāng)然下面修改ActivityManagerService.java也能完成開(kāi)機(jī)自啟動(dòng)
這兩者的區(qū)別在于
DefaultActivity.java只是在第一次啟動(dòng)時(shí)執(zhí)行,如果修改了默認(rèn)launcher后不可恢復(fù)
ActivityManagerService.java在每次啟動(dòng)時(shí)執(zhí)行,每次都默認(rèn)啟動(dòng)設(shè)定的launcher,當(dāng)然,如果設(shè)定的launcher存在的話(huà),設(shè)置其他的launcher為默認(rèn)會(huì)無(wú)效,因?yàn)橹匦聠?dòng)時(shí)setDefaultLauncher()會(huì)將當(dāng)前默認(rèn)launcher清除。只有在卸載了設(shè)定默認(rèn)啟動(dòng)的launcher后才能設(shè)置其他launcher為默認(rèn)啟動(dòng).
//////////////////////////////////////////////////////////////////////////////////////////////////////////
修改多次搜索關(guān)鍵字,得到另一篇文章,大致看了下,感覺(jué)不會(huì)有效,但是已經(jīng)絕望了就試了試,竟然解決了問(wèn)題http://blog.csdn.net/jia4525036/article/details/18036765
這篇文章有借鑒之處,直接使用時(shí)會(huì)發(fā)現(xiàn)有些字段是上下文中沒(méi)有的,故寫(xiě)下此文記錄一下。
修改文件
frameworks\base\services\java\com\android\server\am\ActivityManagerService.java
添加一個(gè)方法:
private void setDefaultLauncher() { // get default component String packageName = "com.coship.factorytest";//默認(rèn)launcher包名 String className = "com.coship.factorytest.MainActivity";////默認(rèn)launcher入口 IPackageManager pm = ActivityThread.getPackageManager(); //判斷指定的launcher是否存在 if(hasApkInstalled(packageName)) { Slog.i(TAG, "defautl packageName = " + packageName + ", default className = " + className); //清除當(dāng)前默認(rèn)launcher ArrayListintentList = new ArrayList (); ArrayList cnList = new ArrayList (); mContext.getPackageManager().getPreferredActivities(intentList, cnList, null); IntentFilter dhIF = null; for(int i = 0; i < cnList.size(); i++) { dhIF = intentList.get(i); if(dhIF.hasAction(Intent.ACTION_MAIN) && dhIF.hasCategory(Intent.CATEGORY_HOME)) { mContext.getPackageManager().clearPackagePreferredActivities(cnList.get(i).getPackageName()); } } //獲取所有l(wèi)auncher activity Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); List list = new ArrayList (); try { list = pm.queryIntentActivities(intent, intent.resolveTypeIfNeeded(mContext.getContentResolver()), PackageManager.MATCH_DEFAULT_ONLY); }catch (RemoteException e) { throw new RuntimeException("Package manager has died", e); } // get all components and the best match IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_MAIN); filter.addCategory(Intent.CATEGORY_HOME); filter.addCategory(Intent.CATEGORY_DEFAULT); final int N = list.size(); Slog.d(TAG, "N:::::hyhyhyhy:::: = " + N); //設(shè)置默認(rèn)launcher ComponentName launcher = new ComponentName(packageName, className); ComponentName[] set = new ComponentName[N]; int defaultMatch = 0; for (int i = 0; i < N; i++) { ResolveInfo r = list.get(i); set[i] = new ComponentName(r.activityInfo.packageName, r.activityInfo.name); Slog.d(TAG, "r.activityInfo.packageName:::::hyhyhyhy:::: = " + r.activityInfo.packageName); Slog.d(TAG, "r.activityInfo.name:::::hyhyhyhy:::: = " + r.activityInfo.name); if(launcher.getClassName().equals(r.activityInfo.name)) { defaultMatch = r.match; } } try { pm.addPreferredActivity(filter, defaultMatch, set, launcher); } catch (RemoteException e) { throw new RuntimeException("com.coship.factorytest.MainActivity : Package manager has died", e); } }//end if } private static boolean hasApkInstalled(String pkgname) { try { mSelf.mContext.getPackageManager().getPackageInfo(pkgname,0); } catch(Exception e) { Slog.d(TAG, "PackageManager.NameNotFoundException: = " + e.getMessage()); return false; } return true; }
然后在ActivityManagerService類(lèi)中的
boolean startHomeActivityLocked()
方法第一行調(diào)用上面添加的
setDefaultLauncher()
boolean startHomeActivityLocked() { if (mFactoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL && mTopAction == null) { // We are running in factory test mode, but unable to find // the factory test app, so just sit around displaying the // error message and don't try to start anything. return false; } /////////////////////////////////////////// setDefaultLauncher(); /////////////////////////////////////////// Intent intent = new Intent( mTopAction, mTopData != null ? Uri.parse(mTopData) : null); intent.setComponent(mTopComponent); if (mFactoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) { intent.addCategory(Intent.CATEGORY_HOME); } ActivityInfo aInfo = intent.resolveActivityInfo(mContext.getPackageManager(), STOCK_PM_FLAGS); if (aInfo != null) { intent.setComponent(new ComponentName( aInfo.applicationInfo.packageName, aInfo.name)); // Don't do this if the home app is currently being // instrumented. Proce***ecord app = getProce***ecordLocked(aInfo.processName, aInfo.applicationInfo.uid); if (app == null || app.instrumentationClass == null) { intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK); mMainStack.startActivityLocked(null, intent, null, null, 0, aInfo, null, null, 0, 0, 0, false, false, null); } } return true; }
添加后的方法全部?jī)?nèi)容如上,重新編譯android,燒錄,開(kāi)機(jī)就能夠自動(dòng)進(jìn)入自定義的launcher
可以通過(guò)系統(tǒng)設(shè)置取消該launcher的默認(rèn)設(shè)置,取消之后按home鍵會(huì)彈出launcher選擇提示框
frameworks\base\core\java\com\android\internal\app\ResolverActivity.java
ResolverActivity類(lèi)就是選擇打開(kāi)方式的彈出框
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線(xiàn),公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性?xún)r(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專(zhuān)為企業(yè)上云打造定制,能夠滿(mǎn)足用戶(hù)豐富、多元化的應(yīng)用場(chǎng)景需求。