Android 桌面图标消息数提醒
2016-04-19 17:18
603 查看
I. App内的数字提醒:第三方控件BadgeView(https://github.com/stefanjauker/BadgeView / http://blog.csdn.net/crazy1235/article/details/42262369 )。
II. 桌面图标消息数提醒: 数字提醒,俗称:角标/红点
可能的处理方法:
1. 我们自己的程序处理,在service接收到消息之后,程序在画布上重新绘出图标,在右上角画出。
2. 不是我们自己程序处理,由launcher(android的桌面应用程序)处理。这种不同进程/应用程序间通信,显然广播机制非常擅长的场景。launcher通过Binder在Android OS 的AMS注册相应的广播消息处理器,App通过Binder向AMS发送广播。但是到目前版本5.0为止Android SDK原生Lancher没有实现这一机制,仅部分厂商深度定制的ROM支持,目前支持的有Samsung/小米/Sony/LG/HTC等。 华为不支持。
3. 创建/替换快捷方式:每次有消息到达,删除当前的桌面快捷方式,替换成新的待有消息提醒的。快捷方式是Android内部使用的的未文档化的方式(internal use, undocumented),Google不推荐使用,在未来的版本可能会变化。
实现分析:
每一个应用本身不负责对桌面图标的修改,这一修改是通过桌面应用程序Launcher实现的。 App通过Binder向AMS发送广播。Launcher通过Binder在Android OS 的AMS(Activity
Management Service)中注册相应的广播消息处理器,在收到到应用发给系统的广播后,Launcher会根据消息内容(通常是未读消息数)重绘应用桌面图标。而Android(到5.0为止)本身的桌面并没有实现这一功能,目前只有部分厂商如xiaomi/Samsung等通过深度定制,在自己制造的ROM中改写了桌面程序,加入了可跨应用的广播接收机制(负责接受消息并处理),把这一广播暴露出来,开发者可以通过发送广播的方式来实现桌面角标。我们知道Google的Android消息机制是并不是以传递消息对象的方式实现的,而是通过意图(Intent)这种通用设计来完成的。和其他组件如Activity一样,知道了Intent,才可以实现系统广播。
Xiaomi:
Intent localIntent = new Intent("android.intent.action.APPLICATION_MESSAGE_UPDATE");
localIntent.putExtra("android.intent.extra.update_application_component_name",context.getPackageName() + "/" + getLauncherClassName(context));
localIntent.putExtra("android.intent.extra.update_application_message_text", ""+msgcount);
context.sendBroadcast(localIntent);
Samsung:
Intent intent = new Intent("android.intent.action.BADGE_COUNT_UPDATE");
intent.putExtra("badge_count", msgcount);
intent.putExtra("badge_count_package_name", context.getPackageName());
intent.putExtra("badge_count_class_name", launcherClassName);
context.sendBroadcast(intent);
Sony:
Intent localIntent = new Intent();
localIntent.setAction("com.sonyericsson.home.action.UPDATE_BADGE");
localIntent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE",isShow);
localIntent.putExtra("com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME",launcherClassName );
localIntent.putExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE",String.valueOf(count));
localIntent.putExtra("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME", context.getPackageName());
context.sendBroadcast(localIntent);
此前一直人认为是应用本身在对图标进行修改,看了源码之后发现其实主要的工作并不是应用自己完成的,主要的工作在是launcher里面完成的。http://blog.csdn.net/andylao62/article/details/41794695
参照了大量网上文档, 一并列出供参考。
Reference:
/article/1824981.html
http://www.th7.cn/Program/Android/201210/105649.shtml //Shortcut
http://blog.csdn.net/andylao62/article/details/41794695
/article/7710989.html
https://github.com/ekinlyw/android-badge
http://www.tuicool.com/articles/JV7vIr
http://stackoverflow.com/questions/20864785/i-want-create-shortcut/20864800#20864800
http://pulse7.net/android/android-application-shortcut-home-screen/
https://codinggeekorg.wordpress.com/2011/01/31/android-home-screen-shortcuts-part-iii-remove-shortcuts/
/article/4847925.html
II. 桌面图标消息数提醒: 数字提醒,俗称:角标/红点
可能的处理方法:
1. 我们自己的程序处理,在service接收到消息之后,程序在画布上重新绘出图标,在右上角画出。
2. 不是我们自己程序处理,由launcher(android的桌面应用程序)处理。这种不同进程/应用程序间通信,显然广播机制非常擅长的场景。launcher通过Binder在Android OS 的AMS注册相应的广播消息处理器,App通过Binder向AMS发送广播。但是到目前版本5.0为止Android SDK原生Lancher没有实现这一机制,仅部分厂商深度定制的ROM支持,目前支持的有Samsung/小米/Sony/LG/HTC等。 华为不支持。
3. 创建/替换快捷方式:每次有消息到达,删除当前的桌面快捷方式,替换成新的待有消息提醒的。快捷方式是Android内部使用的的未文档化的方式(internal use, undocumented),Google不推荐使用,在未来的版本可能会变化。
实现分析:
每一个应用本身不负责对桌面图标的修改,这一修改是通过桌面应用程序Launcher实现的。 App通过Binder向AMS发送广播。Launcher通过Binder在Android OS 的AMS(Activity
Management Service)中注册相应的广播消息处理器,在收到到应用发给系统的广播后,Launcher会根据消息内容(通常是未读消息数)重绘应用桌面图标。而Android(到5.0为止)本身的桌面并没有实现这一功能,目前只有部分厂商如xiaomi/Samsung等通过深度定制,在自己制造的ROM中改写了桌面程序,加入了可跨应用的广播接收机制(负责接受消息并处理),把这一广播暴露出来,开发者可以通过发送广播的方式来实现桌面角标。我们知道Google的Android消息机制是并不是以传递消息对象的方式实现的,而是通过意图(Intent)这种通用设计来完成的。和其他组件如Activity一样,知道了Intent,才可以实现系统广播。
Xiaomi:
Intent localIntent = new Intent("android.intent.action.APPLICATION_MESSAGE_UPDATE");
localIntent.putExtra("android.intent.extra.update_application_component_name",context.getPackageName() + "/" + getLauncherClassName(context));
localIntent.putExtra("android.intent.extra.update_application_message_text", ""+msgcount);
context.sendBroadcast(localIntent);
Samsung:
Intent intent = new Intent("android.intent.action.BADGE_COUNT_UPDATE");
intent.putExtra("badge_count", msgcount);
intent.putExtra("badge_count_package_name", context.getPackageName());
intent.putExtra("badge_count_class_name", launcherClassName);
context.sendBroadcast(intent);
Sony:
Intent localIntent = new Intent();
localIntent.setAction("com.sonyericsson.home.action.UPDATE_BADGE");
localIntent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE",isShow);
localIntent.putExtra("com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME",launcherClassName );
localIntent.putExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE",String.valueOf(count));
localIntent.putExtra("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME", context.getPackageName());
context.sendBroadcast(localIntent);
此前一直人认为是应用本身在对图标进行修改,看了源码之后发现其实主要的工作并不是应用自己完成的,主要的工作在是launcher里面完成的。http://blog.csdn.net/andylao62/article/details/41794695
参照了大量网上文档, 一并列出供参考。
Reference:
/article/1824981.html
http://www.th7.cn/Program/Android/201210/105649.shtml //Shortcut
http://blog.csdn.net/andylao62/article/details/41794695
/article/7710989.html
https://github.com/ekinlyw/android-badge
http://www.tuicool.com/articles/JV7vIr
http://stackoverflow.com/questions/20864785/i-want-create-shortcut/20864800#20864800
http://pulse7.net/android/android-application-shortcut-home-screen/
https://codinggeekorg.wordpress.com/2011/01/31/android-home-screen-shortcuts-part-iii-remove-shortcuts/
/article/4847925.html
相关文章推荐
- Android知识补漏
- Android解决ViewPager嵌套Fragment,Fragment嵌套ViewPager滑动冲突
- Android官方开发文档Training系列课程中文版:调用相机之简单摄像
- 用户检测手势Gesture implements android.view.GestureDetector.OnGestureListener
- Android activity组件
- android ImageView亮度变化
- Android中的Serialable和Parcelable的区别
- Android 驱动开发系列四
- Android adb 命令
- [Android]嵌套Fragment以及startActivityForResult()
- Android应用中炫酷的横向和环形进度条的实例分享
- Android NavigationBar 显示 Menu 按键
- Android EditText用法及焦点处理总结
- android文件操作
- Android广播BroadcastReceiver
- android中WeekCalendar控件
- Android-Spinner下拉列表显示
- android基础学习之back键的监听和回到主页面
- Android自定义属性时typedArray的使用方法
- android studio插件