-
华为手机launcher主题
-
-
Huawei mobile phone launcher theme
*/
private static final String HUWEI_LAUNCHERNAME = “com.huawei.android.launcher”;
/**
-
小米手机launcher主题
-
-
MIUI phone launcher theme
*/
private static final String MIUI_LAUNCHERNAME = “com.miui.home”;
/**
-
摩托罗拉和宏达手机launcher主题
-
-
Motorola and HTC mobile phone launcher theme
*/
private static final String MOTOANDHTC_LAUNCHERNAME = " com.android.launcher";
/**
-
三星手机launcher主题
-
-
Samsung mobile phone launcher theme
*/
private static final String SAMSUNG_LAUNCHERNAME = “com.sec.android.app.launcher”;
/**
-
google 手机launcher主题
-
-
Google phone launcher theme
*/
private static final String GOOGLE_LAUNCHERNAME = “com.google.android.apps.nexuslauncher”;
private volatile static DesktopCornerUtil desktopCornerUtil;
/**
-
vivo手机厂商名字
-
Vivo mobile phone manufacturer name
*/
private static final String VIVO_MANUFACTURER_NAME = “vivo”;
/**
-
OPPO 手机厂商名字
-
OPPO mobile phone manufacturer name
*/
private static final String OPPO_MANUFACTURER_NANE = “OPPO”;
/**
-
应用包名
-
Application package name
*/
private static String packageName = null;
/**
-
context 对象 这里建议传递Application的context 避免内存泄漏
-
It is recommended to pass the Application context to avoid memory leaks.
*/
static Context context = null;
/**
-
主Activity的名字 为全路径 比如 com.***…**Activity
-
The name of the main Activity is the full path. For example, com.***…**Activity
*/
private static String mainActivityName = null;
/**
-
notification 对象 小米系统会默认设置 如果修改默认逻辑 必须获取notification对象
-
The millet system will default settings. If you modify the default logic,
-
you must get the notification object.
*/
private static Notification notification = null;
private DesktopCornerUtil() {
}
public static DesktopCornerUtil getInstance() {
if (desktopCornerUtil == null) {
synchronized (DesktopCornerUtil.class) {
if (desktopCornerUtil == null) {
desktopCornerUtil = new DesktopCornerUtil();
}
}
}
return desktopCornerUtil;
}
/**
-
初始化 init 建议放在Application中执行
-
t is recommended to execute in Application
-
@param packageNameParameter @desc 应用包名
-
@param mainActivityNameParameter @desc MainActivity
-
@param contextParameter @desc BaseApplication context
*/
public static void init(String packageNameParameter, String mainActivityNameParameter, Context contextParameter) {
packageName = packageNameParameter;
context = contextParameter;
mainActivityName = mainActivityNameParameter;
}
/**
-
@param packageNameParameter @desc 应用包名
-
@param mainActivityNameParameter @desc MainActivity
-
@param notication 通知
-
@param contextParameter @desc BaseApplication context
*/
public static void init(String packageNameParameter, String mainActivityNameParameter, Notification notication, Context contextParameter) {
packageName = packageNameParameter;
context = contextParameter;
mainActivityName = mainActivityNameParameter;
}
/**
-
获取launcher相关信息 根据launcher
-
分别开发
-
-
miui: com.miui.home
-
-
huawei: com.huawei.android.launcher
-
-
moto and htc: com.android.launcher
-
-
samsung: com.sec.android.app.launcher
-
-
goole:com.google.android.apps.nexuslauncher
-
-
BaseApplication.getContext() is Application context
-
@return
*/
private static String getLauncherMessage() {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
if (context == null) {
return “”;
} else {
final ResolveInfo res = context
.getPackageManager().resolveActivity(intent, 0);
if (res.activityInfo == null) {
return “”;
}
if (context.getString(R.string.android).
equals(res.activityInfo.packageName)) {
return “”;
}
return res.activityInfo.packageName;
}
}
/**
-
设置角标数字
-
Set the angle number
-
@param badgeNumber @desc 数量
*/
public static void setBadgeNumber(int badgeNumber) {
if (badgeNumber >= 0) {
switch (getLauncherMessage()) {
case HUWEI_LAUNCHERNAME:
setBadgeNumberHuawei(badgeNumber);
break;
case MIUI_LAUNCHERNAME:
setBadgeNumberMiui(badgeNumber);
break;
case MOTOANDHTC_LAUNCHERNAME:
setBadgeNumberhtc(badgeNumber);
break;
case SAMSUNG_LAUNCHERNAME:
setBadgeNumberSamsung(badgeNumber);
break;
case GOOGLE_LAUNCHERNAME:
setBadgeNumberGoogle(badgeNumber);
break;
default:
//再根据制造商去判断
String manufacturer = Build.MANUFACTURER;
switch (manufacturer) {
case VIVO_MANUFACTURER_NAME:
setBadgeNumberVivo(badgeNumber);
break;
case OPPO_MANUFACTURER_NANE:
setBadgeNumberOppo(badgeNumber);
break;
default:
break;
}
break;
}
} else {
// TODO: 2019/6/27 donothing
}
}
/**
-
Google手机设置角标 只支持8.0以上
-
Google phone settings corner Only supports 8.0 or above
-
@param badgeNumber @desc 数量
*/
private static void setBadgeNumberGoogle(int badgeNumber) {
if (TextUtils.isEmpty(packageName)) {
return;
}
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O) {
return;
}
Intent intent = new Intent(“android.intent.action.BADGE_COUNT_UPDATE”);
intent.putExtra(“badge_count”, badgeNumber);
intent.putExtra(“badge_count_package_name”, packageName);
intent.putExtra(“badge_count_class_name”, mainActivityName);
context.sendBroadcast(intent);
}
/**
-
htc和摩托罗拉设置角标
-
Htc and Motorola set the corners
-
@param badgeNumber @desc 数量
*/
private static void setBadgeNumberhtc(int badgeNumber) {
if (TextUtils.isEmpty(packageName)) {
return;
}
Intent intentNotification = new Intent(“com.htc.launcher.action.SET_NOTIFICATION”);
intentNotification.putExtra(“com.htc.launcher.extra.COMPONENT”, packageName);
intentNotification.putExtra(“com.htc.launcher.extra.COUNT”, badgeNumber);
context.sendBroadcast(intentNotification);
Intent intentShortcut = new Intent(“com.htc.launcher.action.UPDATE_SHORTCUT”);
intentShortcut.putExtra(“packagename”, packageName);
intentShortcut.putExtra(“count”, badgeNumber);
context.sendBroadcast(intentShortcut);
}
/**
-
小米手机设置角标
-
MIUI mobile phone settings corner
-
当APP处于前台时,数字会自动清空
-
When the app is in the foreground, the number will be automatically cleared.
-
@param badgeNumber @desc 数量
*/
private static void setBadgeNumberMiui(int badgeNumber) {
try {
if (notification == null) {
return;
} else {
Field field = notification.getClass().getDeclaredField(“extraNotification”);
Object extraNotification = field.get(notification);
Method method = extraNotification.getClass().getDeclaredMethod(“setMessageCoun”, int.class);
method.invoke(extraNotification, badgeNumber);
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
-
华为手机设置角标
-
Huawei mobile phone settings corner
-
@param badgeNumber @desc 数量
*/
private static void setBadgeNumberHuawei(int badgeNumber) {
if (TextUtils.isEmpty(packageName)) {
return;
}
Bundle extra = new Bundle();
extra.putString(“package”, packageName);
extra.putString(“class”, mainActivityName);
extra.putInt(“badgenumber”, badgeNumber);
context.getContentResolver().call(Uri.parse(“content://com.huawei.android.launcher.settings/badge/”),
“change_badge”, null, extra);
}
/**
-
三星手机 设置角标
-
Samsung mobile phone set corner
-
@param badgeNumber @desc 数量
*/
private static void setBadgeNumberSamsung(int badgeNumber) {
if (TextUtils.isEmpty(packageName)) {
最后
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!
级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!**
因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
[外链图片转存中…(img-U3jceEVT-1714943215506)]
[外链图片转存中…(img-CuiKL57x-1714943215507)]
[外链图片转存中…(img-hNaMCWxY-1714943215507)]
[外链图片转存中…(img-WV36pOE4-1714943215507)]
[外链图片转存中…(img-eK7tLCIE-1714943215507)]
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!