Android 图标上显示数字
来源:互联网 发布:服装网络营销策划方案 编辑:程序博客网 时间:2024/04/19 23:01
public class MainActivity extends Activity {
//必须使用,Activity启动页
private final static String lancherActivityClassName = Welcome.class.getName();@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.common_listview_layout);
}
@Override
protected void onResume() {
super.onResume();
sendBadgeNumber();
}
private void sendBadgeNumber() {
String number = "35";
if (TextUtils.isEmpty(number)) {
number = "";
} else {
int numInt = Integer.valueOf(number);
number = String.valueOf(Math.max(0, Math.min(numInt, 99)));
}
if (Build.MANUFACTURER.equalsIgnoreCase("Xiaomi")) {
sendToXiaoMi(number);
} else if (Build.MANUFACTURER.equalsIgnoreCase("samsung")) {
sendToSony(number);
} else if (Build.MANUFACTURER.toLowerCase().contains("sony")) {
sendToSamsumg(number);
} else {
Toast.makeText(this, "Not Support", Toast.LENGTH_LONG).show();}
}
private void sendToXiaoMi(String number) {
try {
Class miuiNotificationClass = Class.forName("android.app.MiuiNotification");
Object miuiNotification = miuiNotificationClass.newInstance();
Field field = miuiNotification.getClass().getDeclaredField("messageCount");
field.setAccessible(true);
field.set(miuiNotification, number);// 设置信息数-->这种发送必须是miui 6才行
} catch (Exception e) {
e.printStackTrace();//miui 6之前的版本
Intent localIntent = new Intent("android.intent.action.APPLICATION_MESSAGE_UPDATE");
localIntent.putExtra("android.intent.extra.update_application_component_name",getPackageName() + "/"+ lancherActivityClassName );
localIntent.putExtra("android.intent.extra.update_application_message_text",number);
sendBroadcast(localIntent);
}
}
private void sendToSony(String number) {
boolean isShow = true;
if ("0".equals(number)) {
isShow = false;
}
Intent localIntent = new Intent();
localIntent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE",isShow);//是否显示
localIntent.setAction("com.sonyericsson.home.action.UPDATE_BADGE");localIntent.putExtra("com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME",lancherActivityClassName );//启动页
localIntent.putExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE", number);//数字
localIntent.putExtra("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME",getPackageName());//包名
sendBroadcast(localIntent);
Toast.makeText(this, "Sony," + "isSendOk", Toast.LENGTH_LONG).show();
}
private void sendToSamsumg(String number)
{
Intent localIntent = new Intent("android.intent.action.BADGE_COUNT_UPDATE");
localIntent.putExtra("badge_count", number);//数字
localIntent.putExtra("badge_count_package_name", getPackageName());//包名localIntent.putExtra("badge_count_class_name",lancherActivityClassName ); //启动页
sendBroadcast(localIntent);
Toast.makeText(this, "Samsumg," + "isSendOk", Toast.LENGTH_LONG).show();}
}
注意lancherActivityClassName 必须被配置为 启动页 android.intent.category.LAUNCHER
<activity
android:name="com.sample.activites.Welcome"
android:configChanges="locale|keyboard|screenSize"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT" /> </intent-filter>
</activity>
0 0
- Android图标上显示数字
- Android 图标上显示数字
- 在小米 三星 索尼 手机 :图标上显示数字
- iOS如何在一个图标上加上气泡,显示数字
- css如何实现数字在图标上显示
- [android]在图标上加提醒的数字
- android 添加快捷方式并且图标上添加数字
- android 添加快捷方式并且图标上添加数字
- android 添加快捷方式并且图标上添加数字
- android添加快捷方式并且图标上添加数字
- iOS 图标上的数字
- Android在应用的标题栏上显示请求旋转图标
- Eclipse工具栏上显示android的sdk和adb图标
- android设置系统图标后手机上不显示出来
- Android应用图标在状态栏上显示实现原理
- 仿新浪微博:无法在应用程序图标上显示提醒数字
- 在小米 三星 索尼 手机 :图标上显示数字(未读消息数)
- 不在任务栏上显示图标
- Linux网络和监控命令
- 链表,遍历链表,结构体指针
- 关于新浪微博字数统计。。
- ecure CRT解决乱码问题
- 实例亲授:教你如何创建AR应用
- Android 图标上显示数字
- android wifi (二)
- 更改linux时间
- python科学计算
- 将Vim改造为强大的IDE—Vim集成Ctags/Taglist/Cscope/Winmanager/NERDTree/OmniCppComplete
- java集合学习之Collection(3)
- Android照片墙加强版,使用ViewPager实现画廊效果
- cocos2d-x屏幕适配
- ASP.NET GridView 绑定 MySql数据库