Android7.0 MTK設置默認桌面
本文實例為大家分享了Android7.0 MTK設置默認桌面的具體代碼,供大家參考,具體內容如下
項目需求:客戶安裝自己公司的桌面apk,安裝完成后自動設置為默認桌面且不彈出始終和僅一次的彈框
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")){
//發(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.由于設置默認桌面時,是在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>
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
當Flutter遇到節(jié)流與防抖的思路和流程優(yōu)化
這篇文章主要給大家介紹了關于當Flutter遇到節(jié)流與防抖的思路和流程優(yōu)化的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-01-01
AndroidStudio利用android-support-multidex解決64k的各種異常
這篇文章主要為大家詳細介紹了AndroidStudio利用android-support-multidex解決64k的各種異常,感興趣的小伙伴們可以參考一下2016-09-09
Android仿支付寶自定義密碼輸入框及安全鍵盤(密碼鍵盤)
這篇文章主要介紹了Android仿支付寶自定義密碼輸入框及安全鍵盤(密碼鍵盤),需要的朋友可以參考下2018-01-01
Android開發(fā)中使用mms模塊收發(fā)單卡和雙卡短信的教程
這篇文章主要介紹了Android開發(fā)中使用mms模塊收發(fā)單卡和雙卡短信的教程,文中舉了MOTO XT800手機(估計已經落伍很久了--)的例子來說明如何解決雙卡雙待時的短信異常問題,需要的朋友可以參考下2016-02-02
Android編程實現(xiàn)仿QQ發(fā)表說說,上傳照片及彈出框效果【附demo源碼下載】
這篇文章主要介紹了Android編程實現(xiàn)仿QQ發(fā)表說說,上傳照片及彈出框效果,涉及Android動畫特效的相關實現(xiàn)技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2017-01-01
android基于dialog實現(xiàn)等待加載框示例
本篇文章主要介紹了android基于dialog實現(xiàn)等待加載框示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-02-02

