Android手机:三星Galaxy S6

Android版本:Android 7.0

Android系统自带的本地通知会从顶部Pop下来,用来提示用户有新的消息,然后在Notification栏中停留。

Android接入远程推送后,并不会默认Pop出Notification,所以有时候用户很难发现自己收到了远程推送的消息,这款三星手机就是这样。

截图如下:

三星手机默认的Notification,显示标题,显示单行文本。但是为啥人家网易新闻的推送就有多行Text,而且别人右侧还显示一个大图标。。。

终于,最终还是在一个论坛中找到了答案。看截图:

重点来了,有没有代码,当然有:

创建多行文本的Notification

  1. //发送通知
  2. NotificationCompat.Builder notifyBuilder =
  3. new NotificationCompat.Builder(RichApplication.getContext())
  4. //设置可以显示多行文本
  5. .setStyle(new NotificationCompat.BigTextStyle().bigText(text))
  6. .setContentTitle(title)
  7. .setContentText(text)
  8. .setSmallIcon(R.drawable.appicon)
  9. //设置大图标
  10. .setLargeIcon(BitmapFactory.decodeResource(RichApplication.getContext().getResources(), R.drawable.appicon))
  11. // 点击消失
  12. .setAutoCancel(true)
  13. // 设置该通知优先级
  14. .setPriority(Notification.PRIORITY_MAX)
  15. .setTicker("悬浮通知")
  16. // 通知首次出现在通知栏,带上升动画效果的
  17. .setWhen(System.currentTimeMillis())
  18. // 通知产生的时间,会在通知信息里显示
  19. // 向通知添加声音、闪灯和振动效果的最简单、最一致的方式是使用当前的用户默认设置,使用defaults属性,可以组合:
  20. .setDefaults( Notification.DEFAULT_VIBRATE | Notification.DEFAULT_ALL | Notification.DEFAULT_SOUND );
  21. NotificationManager mNotifyMgr = (NotificationManager) RichApplication.getContext().getSystemService(Context.NOTIFICATION_SERVICE);
  22. Notification notification = notifyBuilder.build();
  23. mNotifyMgr.notify( notificationID, notification);
  1.  

监听Notification的Click事件和Cancel事件。

step1:分别设置notifyBuilder的 setContentIntent 和 setDeleteIntent。注意创建PendingIntent的时候,需要传递一个requestCode,这个requestCode每个Notification需要各不相同,否则只能监听一个Notification的Click和Cancel事件,后创建的Notification会由于相同的requestCode而覆盖之前的Notification,导致监听的函数永远只执行一次。

  1. //创建点击Notification的通知
  2. Intent intentClick = new Intent(RichApplication.getContext(), MyNotificationReceiver.class);
  3. intentClick.setAction("notification_clicked");
  4. intentClick.putExtra(MyNotificationReceiver.TYPE, notificationID);
  5. PendingIntent pendingIntentClick = PendingIntent.getBroadcast(RichApplication.getContext(), notificationID, intentClick, PendingIntent.FLAG_UPDATE_CURRENT);
  6.  
  7. //创建取消Notification的通知
  8. Intent intentCancel = new Intent(RichApplication.getContext(), MyNotificationReceiver.class);
  9. intentCancel.setAction("notification_cancelled");
  10. intentCancel.putExtra(MyNotificationReceiver.TYPE, notificationID);
  11. PendingIntent pendingIntentCancel = PendingIntent.getBroadcast(RichApplication.getContext(), notificationID, intentCancel, PendingIntent.FLAG_UPDATE_CURRENT);
  12.  
  13. //发送通知
  14. NotificationCompat.Builder notifyBuilder =
  15. new NotificationCompat.Builder(RichApplication.getContext())
  16. //设置可以显示多行文本
  17. .setStyle(new NotificationCompat.BigTextStyle().bigText(text))
  18. .setContentTitle(title)
  19. .setContentText(text)
  20. .setSmallIcon(R.drawable.appicon)
  21. //设置大图标
  22. .setLargeIcon(BitmapFactory.decodeResource(RichApplication.getContext().getResources(), R.drawable.appicon))
  23. // 点击消失
  24. .setAutoCancel(true)
  25. // 设置该通知优先级
  26. .setPriority(Notification.PRIORITY_MAX)
  27. .setTicker("悬浮通知")
  28. // 通知首次出现在通知栏,带上升动画效果的
  29. .setWhen(System.currentTimeMillis())
  30. // 通知产生的时间,会在通知信息里显示
  31. // 向通知添加声音、闪灯和振动效果的最简单、最一致的方式是使用当前的用户默认设置,使用defaults属性,可以组合:
  32. .setDefaults( Notification.DEFAULT_VIBRATE | Notification.DEFAULT_ALL | Notification.DEFAULT_SOUND )
  33. //设置点击Notification的监听事件
  34. .setContentIntent(pendingIntentClick)
  35. //设置CancelNotification的监听事件
  36. .setDeleteIntent(pendingIntentCancel);
  37. NotificationManager mNotifyMgr = (NotificationManager) RichApplication.getContext().getSystemService(Context.NOTIFICATION_SERVICE);
  38. Notification notification = notifyBuilder.build();
  39. mNotifyMgr.notify( notificationID, notification);

step2:新建一个Class继承BroadcastReceiver。

  1. public class MyNotificationReceiver extends BroadcastReceiver {
  2. static String TAG = "MyNotification";
  3.  
  4. public static final String TYPE = "type";
  5.  
  6. @Override
  7. public void onReceive(Context context, Intent intent) {
  8.  
  9. String action = intent.getAction();
  10. int notificationId = intent.getIntExtra(TYPE, -1);
  11. Log.i(TAG, "传递过来的Notification的ID是:"+notificationId);
  12.  
  13. Log.i(TAG, "当前收到的Action:"+action);
  14.  
  15. if (action.equals("notification_clicked")) {
  16. //处理点击事件
  17. MyLocalNotificationManager.removeLocalNotification(notificationId);
  18. Log.i(TAG, "点击了notification");
  19. //跳转到App的主页
  20. Intent mainIntent = new Intent(context, MainActivity.class);
  21. mainIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
  22. context.startActivity(mainIntent);
  23. }
  24.  
  25. if (action.equals("notification_cancelled")) {
  26. //处理滑动清除和点击删除事件
  27. MyLocalNotificationManager.removeLocalNotification(notificationId);
  28. Log.i(TAG, "取消了notification");
  29. }
  30.  
  31. }
  32. }

step3:在AndroidManifest.xml文件中注册receiver

  1. <!-- 监听Notification的点击和消失事件 -->
  2. <receiver android:name="com.richapp.home.MyNotificationReceiver">
  3.   <intent-filter>
  4.     <action android:name="notification_cancelled"/>
  5. <action android:name="notification_clicked"/>
  6. </intent-filter>
  7. </receiver>

设置App右上角的角标

由于Android的手机类型很多,而原本的安卓系统没有提供角标的功能,所以各大厂商自己定制了角标。我测试过三星手机和红米手机,三星手机的角标可以自由设置,即使启动App,角标还是可以继续存在,很类似iOS。但是红米手机开启App之后,角标就会消失,即使你不想它消失。

  1. public class MyLocalNotificationManager {
  2.  
  3. private static String TAG = "MyLocalNTManager";
  4.  
  5. /**
  6. * 添加一个新的Notification
  7. * @param title
  8. * @param text
  9. * @param notificationID
  10. */
  11. public static void addLocalNotification(String title, String text, int notificationID){
  12.  
  13. int badgeNumber = 0;
  14. Log.i(TAG, "添加一个新的通知:"+notificationID);
  15.  
  16. //获取当前Notification的数量
  17. Object notificationCount = SharedPreferenceUtils.get(RichApplication.getContext(), "NotificationCount", 0);
  18. int nCount = 0;
  19. if (notificationCount != null){
  20. nCount = Integer.parseInt(notificationCount.toString());
  21. }
  22. Log.i(TAG, "获取的本地通知的个数:"+nCount);
  23.  
  24. //获取即时通讯数据库的数量
  25. List<Contact> contactList = ContactDbHelper.getInstance(RichApplication.getContext()).getAllShowContact();
  26. int sum = 0;
  27. for (Contact unreadCountact : contactList){
  28. sum += unreadCountact.unReadCount;
  29. }
  30. Log.i(TAG, "获取未读消息的个数:"+sum);
  31.  
  32. //在当前未读消息的总数上+1
  33. badgeNumber = sum + nCount + 1;
  34.  
  35. //创建点击Notification的通知
  36. Intent intentClick = new Intent(RichApplication.getContext(), MyNotificationReceiver.class);
  37. intentClick.setAction("notification_clicked");
  38. intentClick.putExtra(MyNotificationReceiver.TYPE, notificationID);
  39. PendingIntent pendingIntentClick = PendingIntent.getBroadcast(RichApplication.getContext(), notificationID, intentClick, PendingIntent.FLAG_UPDATE_CURRENT);
  40.  
  41. //创建取消Notification的通知
  42. Intent intentCancel = new Intent(RichApplication.getContext(), MyNotificationReceiver.class);
  43. intentCancel.setAction("notification_cancelled");
  44. intentCancel.putExtra(MyNotificationReceiver.TYPE, notificationID);
  45. PendingIntent pendingIntentCancel = PendingIntent.getBroadcast(RichApplication.getContext(), notificationID, intentCancel, PendingIntent.FLAG_UPDATE_CURRENT);
  46.  
  47. //发送通知
  48. NotificationCompat.Builder notifyBuilder =
  49. new NotificationCompat.Builder(RichApplication.getContext())
  50. //设置可以显示多行文本
  51. .setStyle(new NotificationCompat.BigTextStyle().bigText(text))
  52. .setContentTitle(title)
  53. .setContentText(text)
  54. .setSmallIcon(R.drawable.appicon)
  55. //设置大图标
  56. .setLargeIcon(BitmapFactory.decodeResource(RichApplication.getContext().getResources(), R.drawable.appicon))
  57. // 点击消失
  58. .setAutoCancel(true)
  59. // 设置该通知优先级
  60. .setPriority(Notification.PRIORITY_MAX)
  61. .setTicker("悬浮通知")
  62. // 通知首次出现在通知栏,带上升动画效果的
  63. .setWhen(System.currentTimeMillis())
  64. // 通知产生的时间,会在通知信息里显示
  65. // 向通知添加声音、闪灯和振动效果的最简单、最一致的方式是使用当前的用户默认设置,使用defaults属性,可以组合:
  66. .setDefaults( Notification.DEFAULT_VIBRATE | Notification.DEFAULT_ALL | Notification.DEFAULT_SOUND )
  67. //设置点击Notification
  68. .setContentIntent(pendingIntentClick)
  69. .setDeleteIntent(pendingIntentCancel);
  70. NotificationManager mNotifyMgr = (NotificationManager) RichApplication.getContext().getSystemService(Context.NOTIFICATION_SERVICE);
  71. Notification notification = notifyBuilder.build();
  72.  
  73. //设置右上角的角标数量
  74. if (Build.MANUFACTURER.equalsIgnoreCase("Xiaomi")){
  75. //小米手机
  76. boolean isMiUIV6 = true;
  77. Class miuiNotificationClass = null;
  78. try {
  79.  
  80. //递增
  81. badgeNumber = 1;
  82. Field field = notification.getClass().getDeclaredField("extraNotification");
  83. Object extraNotification = field.get(notification);
  84. Method method = extraNotification.getClass().getDeclaredMethod("setMessageCount", int.class);
  85. method.invoke(extraNotification, badgeNumber);
  86.  
  87. } catch (Exception e) {
  88. e.printStackTrace();
  89. //miui 6之前的版本
  90. isMiUIV6 = false;
  91. Intent localIntent = new Intent("android.intent.action.APPLICATION_MESSAGE_UPDATE");
  92. localIntent.putExtra("android.intent.extra.update_application_component_name",
  93. RichApplication.getContext().getPackageName()
  94. + "/"+ "com.richapp.home.MainActivity" );
  95. localIntent.putExtra("android.intent.extra.update_application_message_text",badgeNumber);
  96. RichApplication.getContext().sendBroadcast(localIntent);
  97. }
  98. }
  99. else if (Build.MANUFACTURER.equalsIgnoreCase("ZUK")){
  100. //联想手机
  101. final Uri CONTENT_URI = Uri.parse("content://com.android.badge/badge");
  102. Bundle extra = new Bundle();
  103. extra.putInt("app_badge_count", badgeNumber);
  104. RichApplication.getContext().getContentResolver().call(CONTENT_URI, "setAppBadgeCount", null, extra);
  105. }
  106. else if (Build.MANUFACTURER.equalsIgnoreCase("OPPO")){
  107. //OPPO手机
  108. Intent launchIntent = RichApplication.getContext().getPackageManager()
  109. .getLaunchIntentForPackage(RichApplication.getContext().getPackageName());
  110. ComponentName componentName = launchIntent.getComponent();
  111. Intent badgeIntent = new Intent("com.oppo.unsettledevent");
  112. badgeIntent.putExtra("pakeageName", componentName.getPackageName());
  113. badgeIntent.putExtra("number", badgeNumber);
  114. badgeIntent.putExtra("upgradeNumber", badgeNumber);
  115. RichApplication.getContext().sendBroadcast(badgeIntent);
  116. }
  117. else if (Build.MANUFACTURER.equalsIgnoreCase("VIVO")){
  118. //VIVO手机
  119. Intent launchIntent = RichApplication.getContext().getPackageManager()
  120. .getLaunchIntentForPackage(RichApplication.getContext().getPackageName());
  121. ComponentName componentName = launchIntent.getComponent();
  122. Intent badgeIntent = new Intent("launcher.action.CHANGE_APPLICATION_NOTIFICATION_NUM");
  123. badgeIntent.putExtra("packageName", componentName.getPackageName());
  124. badgeIntent.putExtra("className", componentName.getClassName());
  125. badgeIntent.putExtra("notificationNum", badgeNumber);
  126. RichApplication.getContext().sendBroadcast(badgeIntent);
  127. }
  128. else if (Build.MANUFACTURER.equalsIgnoreCase("ZTE")){
  129. //中兴手机
  130. Intent launchIntent = RichApplication.getContext().getPackageManager()
  131. .getLaunchIntentForPackage(RichApplication.getContext().getPackageName());
  132. ComponentName componentName = launchIntent.getComponent();
  133. Bundle extra = new Bundle();
  134. extra.putInt("app_badge_count", badgeNumber);
  135. extra.putString("app_badge_component_name", componentName.flattenToString());
  136.  
  137. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
  138. RichApplication.getContext().getContentResolver().call(
  139. Uri.parse("content://com.android.launcher3.cornermark.unreadbadge"),
  140. "setAppUnreadCount", null, extra);
  141. }
  142. }
  143. else{
  144. //三星,华为等其他都是广播
  145. Intent launchIntent = RichApplication.getContext().getPackageManager()
  146. .getLaunchIntentForPackage(RichApplication.getContext().getPackageName());
  147. ComponentName componentName = launchIntent.getComponent();
  148.  
  149. Intent badgeIntent = new Intent("android.intent.action.BADGE_COUNT_UPDATE");
  150. badgeIntent.putExtra("badge_count", badgeNumber);
  151. badgeIntent.putExtra("badge_count_package_name", componentName.getPackageName());
  152. badgeIntent.putExtra("badge_count_class_name", componentName.getClassName());
  153. RichApplication.getContext().sendBroadcast(badgeIntent);
  154. }
  155.  
  156. mNotifyMgr.notify( notificationID, notification);
  157.  
  158. //更改SharedPrefrence中存储的数据
  159. SharedPreferenceUtils.put(RichApplication.getContext(), "NotificationCount", new Integer(nCount+1));
  160. Log.i(TAG, "更新本地通知的数量:"+(nCount+1));
  161. }
  162.  
  163. /**
  164. * 移除一个Notification
  165. * @param notificationID
  166. */
  167. public static void removeLocalNotification(int notificationID){
  168. int badgeNumber = 0;
  169. Log.i(TAG, "移除一个新的通知:"+notificationID);
  170.  
  171. //获取当前Notification的数量
  172. Object notificationCount = SharedPreferenceUtils.get(RichApplication.getContext(), "NotificationCount", 0);
  173. int nCount = 0;
  174. if (notificationCount != null){
  175. nCount = Integer.parseInt(notificationCount.toString());
  176. }
  177. Log.i(TAG, "获取的本地通知的个数:"+nCount);
  178.  
  179. //获取即时通讯数据库的数量
  180. List<Contact> contactList = ContactDbHelper.getInstance(RichApplication.getContext()).getAllShowContact();
  181. int sum = 0;
  182. for (Contact unreadCountact : contactList){
  183. sum += unreadCountact.unReadCount;
  184. }
  185. Log.i(TAG, "获取未读消息的个数:"+sum);
  186.  
  187. //在当前未读消息的总数上+1
  188. badgeNumber = sum + nCount - 1;
  189.  
  190. // //创建点击Notification的通知
  191. // Intent intentClick = new Intent(RichApplication.getContext(), MyNotificationReceiver.class);
  192. // intentClick.setAction("notification_clicked");
  193. // intentClick.putExtra(MyNotificationReceiver.TYPE, notificationID);
  194. // PendingIntent pendingIntentClick = PendingIntent.getBroadcast(RichApplication.getContext(), 0, intentClick, PendingIntent.FLAG_ONE_SHOT);
  195. //
  196. // //创建取消Notification的通知
  197. // Intent intentCancel = new Intent(RichApplication.getContext(), MyNotificationReceiver.class);
  198. // intentCancel.setAction("notification_cancelled");
  199. // intentCancel.putExtra(MyNotificationReceiver.TYPE, notificationID);
  200. // PendingIntent pendingIntentCancel = PendingIntent.getBroadcast(RichApplication.getContext(), 0, intentCancel, PendingIntent.FLAG_ONE_SHOT);
  201.  
  202. //发送通知
  203. NotificationCompat.Builder notifyBuilder =
  204. new NotificationCompat.Builder(RichApplication.getContext())
  205. .setStyle(new NotificationCompat.BigTextStyle().bigText(""))
  206. .setContentTitle("")
  207. .setContentText("")
  208. .setSmallIcon(R.drawable.appicon)
  209. .setLargeIcon(BitmapFactory.decodeResource(RichApplication.getContext().getResources(), R.drawable.appicon))
  210. // 点击消失
  211. .setAutoCancel(true)
  212. // 设置该通知优先级
  213. .setPriority(Notification.PRIORITY_MAX)
  214. .setTicker("悬浮通知")
  215. // 通知首次出现在通知栏,带上升动画效果的
  216. .setWhen(System.currentTimeMillis())
  217. // 通知产生的时间,会在通知信息里显示
  218. // 向通知添加声音、闪灯和振动效果的最简单、最一致的方式是使用当前的用户默认设置,使用defaults属性,可以组合:
  219. .setDefaults( Notification.DEFAULT_VIBRATE | Notification.DEFAULT_ALL | Notification.DEFAULT_SOUND );
  220. Intent intent = new Intent(RichApplication.getContext(), MainActivity.class);
  221. NotificationManager mNotifyMgr = (NotificationManager) RichApplication.getContext().getSystemService(Context.NOTIFICATION_SERVICE);
  222. Notification notification = notifyBuilder.build();
  223.  
  224. //移除当前的Notification
  225. mNotifyMgr.cancel(notificationID);
  226. //更改SharedPrefrence中存储的数据
  227. SharedPreferenceUtils.put(RichApplication.getContext(), "NotificationCount", new Integer(nCount-1));
  228. Log.i(TAG, "更新本地通知的数量:"+(nCount-1));
  229.  
  230. //设置右上角的角标数量
  231. if (Build.MANUFACTURER.equalsIgnoreCase("Xiaomi")){
  232. //小米手机
  233. boolean isMiUIV6 = true;
  234. Class miuiNotificationClass = null;
  235. try {
  236.  
  237. badgeNumber = -1;
  238. Field field = notification.getClass().getDeclaredField("extraNotification");
  239. Object extraNotification = field.get(notification);
  240. Method method = extraNotification.getClass().getDeclaredMethod("setMessageCount", int.class);
  241. method.invoke(extraNotification, badgeNumber);
  242.  
  243. } catch (Exception e) {
  244. e.printStackTrace();
  245. //miui 6之前的版本
  246. isMiUIV6 = false;
  247. Intent localIntent = new Intent("android.intent.action.APPLICATION_MESSAGE_UPDATE");
  248. localIntent.putExtra("android.intent.extra.update_application_component_name",
  249. RichApplication.getContext().getPackageName()
  250. + "/"+ "com.richapp.home.MainActivity" );
  251. localIntent.putExtra("android.intent.extra.update_application_message_text",badgeNumber);
  252. RichApplication.getContext().sendBroadcast(localIntent);
  253. }
  254. }
  255. else if (Build.MANUFACTURER.equalsIgnoreCase("ZUK")){
  256. //联想手机
  257. final Uri CONTENT_URI = Uri.parse("content://com.android.badge/badge");
  258. Bundle extra = new Bundle();
  259. extra.putInt("app_badge_count", badgeNumber);
  260. RichApplication.getContext().getContentResolver().call(CONTENT_URI, "setAppBadgeCount", null, extra);
  261. }
  262. else if (Build.MANUFACTURER.equalsIgnoreCase("OPPO")){
  263. //OPPO手机
  264. Intent launchIntent = RichApplication.getContext().getPackageManager()
  265. .getLaunchIntentForPackage(RichApplication.getContext().getPackageName());
  266. ComponentName componentName = launchIntent.getComponent();
  267. Intent badgeIntent = new Intent("com.oppo.unsettledevent");
  268. badgeIntent.putExtra("pakeageName", componentName.getPackageName());
  269. badgeIntent.putExtra("number", badgeNumber);
  270. badgeIntent.putExtra("upgradeNumber", badgeNumber);
  271. RichApplication.getContext().sendBroadcast(badgeIntent);
  272. }
  273. else if (Build.MANUFACTURER.equalsIgnoreCase("VIVO")){
  274. //VIVO手机
  275. Intent launchIntent = RichApplication.getContext().getPackageManager()
  276. .getLaunchIntentForPackage(RichApplication.getContext().getPackageName());
  277. ComponentName componentName = launchIntent.getComponent();
  278. Intent badgeIntent = new Intent("launcher.action.CHANGE_APPLICATION_NOTIFICATION_NUM");
  279. badgeIntent.putExtra("packageName", componentName.getPackageName());
  280. badgeIntent.putExtra("className", componentName.getClassName());
  281. badgeIntent.putExtra("notificationNum", badgeNumber);
  282. RichApplication.getContext().sendBroadcast(badgeIntent);
  283. }
  284. else if (Build.MANUFACTURER.equalsIgnoreCase("ZTE")){
  285. //中兴手机
  286. Intent launchIntent = RichApplication.getContext().getPackageManager()
  287. .getLaunchIntentForPackage(RichApplication.getContext().getPackageName());
  288. ComponentName componentName = launchIntent.getComponent();
  289. Bundle extra = new Bundle();
  290. extra.putInt("app_badge_count", badgeNumber);
  291. extra.putString("app_badge_component_name", componentName.flattenToString());
  292.  
  293. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
  294. RichApplication.getContext().getContentResolver().call(
  295. Uri.parse("content://com.android.launcher3.cornermark.unreadbadge"),
  296. "setAppUnreadCount", null, extra);
  297. }
  298. }
  299. else{
  300. //三星,华为等其他都是广播
  301. Intent launchIntent = RichApplication.getContext().getPackageManager()
  302. .getLaunchIntentForPackage(RichApplication.getContext().getPackageName());
  303. ComponentName componentName = launchIntent.getComponent();
  304.  
  305. Intent badgeIntent = new Intent("android.intent.action.BADGE_COUNT_UPDATE");
  306. badgeIntent.putExtra("badge_count", badgeNumber);
  307. badgeIntent.putExtra("badge_count_package_name", componentName.getPackageName());
  308. badgeIntent.putExtra("badge_count_class_name", componentName.getClassName());
  309. RichApplication.getContext().sendBroadcast(badgeIntent);
  310. }
  311.  
  312. // mNotifyMgr.notify( notificationID, notification);
  313. }
  314.  
  315. /**
  316. * 移除全部Notification
  317. */
  318. public static void removeAllLocalNotification(){
  319. int badgeNumber = 0;
  320. Log.i(TAG, "移除全部的通知");
  321.  
  322. //获取当前Notification的数量
  323. Object notificationCount = SharedPreferenceUtils.get(RichApplication.getContext(), "NotificationCount", 0);
  324. int nCount = 0;
  325. if (notificationCount != null){
  326. nCount = Integer.parseInt(notificationCount.toString());
  327. }
  328. Log.i(TAG, "获取的本地通知的个数:"+nCount);
  329.  
  330. //获取即时通讯数据库的数量
  331. List<Contact> contactList = ContactDbHelper.getInstance(RichApplication.getContext()).getAllShowContact();
  332. int sum = 0;
  333. for (Contact unreadCountact : contactList){
  334. sum += unreadCountact.unReadCount;
  335. }
  336.  
  337. //在当前未读消息的总数上+1
  338. badgeNumber = 0;
  339.  
  340. // //创建点击Notification的通知
  341. // Intent intentClick = new Intent(RichApplication.getContext(), MyNotificationReceiver.class);
  342. // intentClick.setAction("notification_clicked");
  343. // intentClick.putExtra(MyNotificationReceiver.TYPE, notificationID);
  344. // PendingIntent pendingIntentClick = PendingIntent.getBroadcast(RichApplication.getContext(), 0, intentClick, PendingIntent.FLAG_ONE_SHOT);
  345. //
  346. // //创建取消Notification的通知
  347. // Intent intentCancel = new Intent(RichApplication.getContext(), MyNotificationReceiver.class);
  348. // intentCancel.setAction("notification_cancelled");
  349. // intentCancel.putExtra(MyNotificationReceiver.TYPE, notificationID);
  350. // PendingIntent pendingIntentCancel = PendingIntent.getBroadcast(RichApplication.getContext(), 0, intentCancel, PendingIntent.FLAG_ONE_SHOT);
  351.  
  352. //发送通知
  353. NotificationCompat.Builder notifyBuilder =
  354. new NotificationCompat.Builder(RichApplication.getContext())
  355. .setStyle(new NotificationCompat.BigTextStyle().bigText(""))
  356. .setContentTitle("")
  357. .setContentText("")
  358. .setSmallIcon(R.drawable.appicon)
  359. .setLargeIcon(BitmapFactory.decodeResource(RichApplication.getContext().getResources(), R.drawable.appicon))
  360. // 点击消失
  361. .setAutoCancel(true)
  362. // 设置该通知优先级
  363. .setPriority(Notification.PRIORITY_MAX)
  364. .setTicker("悬浮通知")
  365. // 通知首次出现在通知栏,带上升动画效果的
  366. .setWhen(System.currentTimeMillis())
  367. // 通知产生的时间,会在通知信息里显示
  368. // 向通知添加声音、闪灯和振动效果的最简单、最一致的方式是使用当前的用户默认设置,使用defaults属性,可以组合:
  369. .setDefaults( Notification.DEFAULT_VIBRATE | Notification.DEFAULT_ALL | Notification.DEFAULT_SOUND );
  370. //Intent intent = new Intent(RichApplication.getContext(), MainActivity.class);
  371. NotificationManager mNotifyMgr = (NotificationManager) RichApplication.getContext().getSystemService(Context.NOTIFICATION_SERVICE);
  372. Notification notification = notifyBuilder.build();
  373.  
  374. //设置右上角的角标数量
  375. if (Build.MANUFACTURER.equalsIgnoreCase("Xiaomi")){
  376. //小米手机
  377. boolean isMiUIV6 = true;
  378. Class miuiNotificationClass = null;
  379. try {
  380.  
  381. Field field = notification.getClass().getDeclaredField("extraNotification");
  382. Object extraNotification = field.get(notification);
  383. Method method = extraNotification.getClass().getDeclaredMethod("setMessageCount", int.class);
  384. method.invoke(extraNotification, badgeNumber);
  385.  
  386. } catch (Exception e) {
  387. e.printStackTrace();
  388. //miui 6之前的版本
  389. isMiUIV6 = false;
  390. Intent localIntent = new Intent("android.intent.action.APPLICATION_MESSAGE_UPDATE");
  391. localIntent.putExtra("android.intent.extra.update_application_component_name",
  392. RichApplication.getContext().getPackageName()
  393. + "/"+ "com.richapp.home.MainActivity" );
  394. localIntent.putExtra("android.intent.extra.update_application_message_text",badgeNumber);
  395. RichApplication.getContext().sendBroadcast(localIntent);
  396. }
  397. }
  398. else if (Build.MANUFACTURER.equalsIgnoreCase("ZUK")){
  399. //联想手机
  400. final Uri CONTENT_URI = Uri.parse("content://com.android.badge/badge");
  401. Bundle extra = new Bundle();
  402. extra.putInt("app_badge_count", badgeNumber);
  403. RichApplication.getContext().getContentResolver().call(CONTENT_URI, "setAppBadgeCount", null, extra);
  404. }
  405. else if (Build.MANUFACTURER.equalsIgnoreCase("OPPO")){
  406. //OPPO手机
  407. Intent launchIntent = RichApplication.getContext().getPackageManager()
  408. .getLaunchIntentForPackage(RichApplication.getContext().getPackageName());
  409. ComponentName componentName = launchIntent.getComponent();
  410. Intent badgeIntent = new Intent("com.oppo.unsettledevent");
  411. badgeIntent.putExtra("pakeageName", componentName.getPackageName());
  412. badgeIntent.putExtra("number", badgeNumber);
  413. badgeIntent.putExtra("upgradeNumber", badgeNumber);
  414. RichApplication.getContext().sendBroadcast(badgeIntent);
  415. }
  416. else if (Build.MANUFACTURER.equalsIgnoreCase("VIVO")){
  417. //VIVO手机
  418. Intent launchIntent = RichApplication.getContext().getPackageManager()
  419. .getLaunchIntentForPackage(RichApplication.getContext().getPackageName());
  420. ComponentName componentName = launchIntent.getComponent();
  421. Intent badgeIntent = new Intent("launcher.action.CHANGE_APPLICATION_NOTIFICATION_NUM");
  422. badgeIntent.putExtra("packageName", componentName.getPackageName());
  423. badgeIntent.putExtra("className", componentName.getClassName());
  424. badgeIntent.putExtra("notificationNum", badgeNumber);
  425. RichApplication.getContext().sendBroadcast(badgeIntent);
  426. }
  427. else if (Build.MANUFACTURER.equalsIgnoreCase("ZTE")){
  428. //中兴手机
  429. Intent launchIntent = RichApplication.getContext().getPackageManager()
  430. .getLaunchIntentForPackage(RichApplication.getContext().getPackageName());
  431. ComponentName componentName = launchIntent.getComponent();
  432. Bundle extra = new Bundle();
  433. extra.putInt("app_badge_count", badgeNumber);
  434. extra.putString("app_badge_component_name", componentName.flattenToString());
  435.  
  436. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
  437. RichApplication.getContext().getContentResolver().call(
  438. Uri.parse("content://com.android.launcher3.cornermark.unreadbadge"),
  439. "setAppUnreadCount", null, extra);
  440. }
  441. }
  442. else{
  443. //三星,华为等其他都是广播
  444. Intent launchIntent = RichApplication.getContext().getPackageManager()
  445. .getLaunchIntentForPackage(RichApplication.getContext().getPackageName());
  446. ComponentName componentName = launchIntent.getComponent();
  447.  
  448. Intent badgeIntent = new Intent("android.intent.action.BADGE_COUNT_UPDATE");
  449. badgeIntent.putExtra("badge_count", badgeNumber);
  450. badgeIntent.putExtra("badge_count_package_name", componentName.getPackageName());
  451. badgeIntent.putExtra("badge_count_class_name", componentName.getClassName());
  452. RichApplication.getContext().sendBroadcast(badgeIntent);
  453. }
  454.  
  455. //更改SharedPrefrence中存储的数据
  456. SharedPreferenceUtils.put(RichApplication.getContext(), "NotificationCount", 0);
  457. Log.i(TAG, "更新本地通知的数量:"+0);
  458. //mNotifyMgr.notify( notificationID, notification);
  459.  
  460. //清除所有的本地Notification
  461. mNotifyMgr.cancelAll();
  462. }
  463.  
  464. /**
  465. * 读取即时通讯消息,更新角标
  466. */
  467. public static void updateNotificationAndBadgeNumber(){
  468. //清除通知栏信息
  469. NotificationManager mNotifyMgr = (NotificationManager) RichApplication.getContext().getSystemService(Context.NOTIFICATION_SERVICE);
  470. mNotifyMgr.cancel(R.drawable.appicon);
  471.  
  472. //获取当前Notification的数量
  473. Object notificationCount = SharedPreferenceUtils.get(RichApplication.getContext(), "NotificationCount", 0);
  474. int nCount = 0;
  475. if (notificationCount != null){
  476. nCount = Integer.parseInt(notificationCount.toString());
  477. }
  478. Log.i(TAG, "获取的本地通知的个数:"+nCount);
  479.  
  480. //更新角标显示
  481. //获取未读消息条数
  482. //获取当前数据库的值,然后设置未读消息数量
  483. List<Contact> contactList = ContactDbHelper.getInstance(RichApplication.getContext()).getAllShowContact();
  484.  
  485. int sum = 0;
  486. for (Contact unreadCountact : contactList){
  487. sum += unreadCountact.unReadCount;
  488. }
  489.  
  490. //计算全部的未读消息数量
  491. sum += nCount;
  492.  
  493. NotificationCompat.Builder notifyBuilder =
  494. new NotificationCompat.Builder(RichApplication.getContext()).setContentTitle("")
  495. .setContentText("")
  496. .setSmallIcon(R.drawable.appicon)
  497. .setLargeIcon(BitmapFactory.decodeResource(RichApplication.getContext().getResources(), R.drawable.appicon))
  498. // 点击消失
  499. .setAutoCancel(true)
  500. // 设置该通知优先级
  501. .setPriority(Notification.PRIORITY_MAX)
  502. .setTicker("")
  503. // 通知首次出现在通知栏,带上升动画效果的
  504. .setWhen(System.currentTimeMillis())
  505. // 通知产生的时间,会在通知信息里显示
  506. // 向通知添加声音、闪灯和振动效果的最简单、最一致的方式是使用当前的用户默认设置,使用defaults属性,可以组合:
  507. .setDefaults( Notification.DEFAULT_VIBRATE | Notification.DEFAULT_ALL | Notification.DEFAULT_SOUND );
  508. Intent intent = new Intent(RichApplication.getContext(), MainActivity.class);
  509. PendingIntent resultPendingIntent =
  510. PendingIntent.getActivity( RichApplication.getContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT );
  511. notifyBuilder.setContentIntent( resultPendingIntent );
  512. Notification notification = notifyBuilder.build();
  513.  
  514. //设置右上角的角标数量
  515. if (Build.MANUFACTURER.equalsIgnoreCase("Xiaomi")){
  516. //小米手机
  517. boolean isMiUIV6 = true;
  518. Class miuiNotificationClass = null;
  519. try {
  520.  
  521. //Field field = notification.getClass().getDeclaredField("extraNotification");
  522. //Object extraNotification = field.get(notification);
  523. //Method method = extraNotification.getClass().getDeclaredMethod("setMessageCount", int.class);
  524. //method.invoke(extraNotification, sum);
  525.  
  526. //mNotifyMgr.notify( R.drawable.imcover, notification);
  527.  
  528. } catch (Exception e) {
  529. e.printStackTrace();
  530. //miui 6之前的版本
  531. isMiUIV6 = false;
  532. Intent localIntent = new Intent("android.intent.action.APPLICATION_MESSAGE_UPDATE");
  533. localIntent.putExtra("android.intent.extra.update_application_component_name",
  534. RichApplication.getContext().getPackageName()
  535. + "/"+ "com.richapp.home.MainActivity" );
  536. localIntent.putExtra("android.intent.extra.update_application_message_text",sum);
  537. RichApplication.getContext().sendBroadcast(localIntent);
  538. }
  539. }
  540. else if (Build.MANUFACTURER.equalsIgnoreCase("ZUK")){
  541. //联想手机
  542. final Uri CONTENT_URI = Uri.parse("content://com.android.badge/badge");
  543. Bundle extra = new Bundle();
  544. extra.putInt("app_badge_count", sum);
  545. RichApplication.getContext().getContentResolver().call(CONTENT_URI, "setAppBadgeCount", null, extra);
  546. }
  547. else if (Build.MANUFACTURER.equalsIgnoreCase("OPPO")){
  548. //OPPO手机
  549. Intent launchIntent = RichApplication.getContext().getPackageManager()
  550. .getLaunchIntentForPackage(RichApplication.getContext().getPackageName());
  551. ComponentName componentName = launchIntent.getComponent();
  552. Intent badgeIntent = new Intent("com.oppo.unsettledevent");
  553. badgeIntent.putExtra("pakeageName", componentName.getPackageName());
  554. badgeIntent.putExtra("number", sum);
  555. badgeIntent.putExtra("upgradeNumber", sum);
  556. RichApplication.getContext().sendBroadcast(badgeIntent);
  557. }
  558. else if (Build.MANUFACTURER.equalsIgnoreCase("VIVO")){
  559. //VIVO手机
  560. Intent launchIntent = RichApplication.getContext().getPackageManager()
  561. .getLaunchIntentForPackage(RichApplication.getContext().getPackageName());
  562. ComponentName componentName = launchIntent.getComponent();
  563. Intent badgeIntent = new Intent("launcher.action.CHANGE_APPLICATION_NOTIFICATION_NUM");
  564. badgeIntent.putExtra("packageName", componentName.getPackageName());
  565. badgeIntent.putExtra("className", componentName.getClassName());
  566. badgeIntent.putExtra("notificationNum", sum);
  567. RichApplication.getContext().sendBroadcast(badgeIntent);
  568. }
  569. else if (Build.MANUFACTURER.equalsIgnoreCase("ZTE")){
  570. //中兴手机
  571. Intent launchIntent = RichApplication.getContext().getPackageManager()
  572. .getLaunchIntentForPackage(RichApplication.getContext().getPackageName());
  573. ComponentName componentName = launchIntent.getComponent();
  574. Bundle extra = new Bundle();
  575. extra.putInt("app_badge_count", sum);
  576. extra.putString("app_badge_component_name", componentName.flattenToString());
  577.  
  578. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
  579. RichApplication.getContext().getContentResolver().call(
  580. Uri.parse("content://com.android.launcher3.cornermark.unreadbadge"),
  581. "setAppUnreadCount", null, extra);
  582. }
  583. }
  584. else{
  585. //三星,华为等其他都是广播
  586. Intent launchIntent = RichApplication.getContext().getPackageManager().getLaunchIntentForPackage(RichApplication.getContext().getPackageName());
  587. ComponentName componentName = launchIntent.getComponent();
  588.  
  589. Intent badgeIntent = new Intent("android.intent.action.BADGE_COUNT_UPDATE");
  590. badgeIntent.putExtra("badge_count", sum);
  591. badgeIntent.putExtra("badge_count_package_name", componentName.getPackageName());
  592. badgeIntent.putExtra("badge_count_class_name", componentName.getClassName());
  593. RichApplication.getContext().sendBroadcast(badgeIntent);
  594. }
  595. }
  596.  
  597. /**
  598. * 收到即时通讯消息,发出本地通知,并更新角标
  599. * @param subject msg的subject
  600. * @param msgBody msg的msgBody
  601. */
  602. public static void receivedNewMessageAndupdateBadgeNumber(String subject, String msgBody){
  603. //获取未读消息条数
  604. //获取当前数据库的值,然后设置未读消息数量
  605. List<Contact> contactList = ContactDbHelper.getInstance(RichApplication.getContext()).getAllShowContact();
  606.  
  607. int sum = 0;
  608. for (Contact unreadCountact : contactList){
  609. sum += unreadCountact.unReadCount;
  610. }
  611.  
  612. if (sum == 1){
  613. msgBody = "["+sum+" "+RichApplication.getContext().getResources().getString(R.string.IMUnReadMessage)+"]"+msgBody;
  614. }else{
  615. msgBody = "["+sum+" "+RichApplication.getContext().getResources().getString(R.string.IMUnReadMessages)+"]"+msgBody;
  616. }
  617.  
  618. //获取当前Notification的数量
  619. Object notificationCount = SharedPreferenceUtils.get(RichApplication.getContext(), "NotificationCount", 0);
  620. int nCount = 0;
  621. if (notificationCount != null){
  622. nCount = Integer.parseInt(notificationCount.toString());
  623. }
  624. //Log.i(TAG, "获取的本地通知的个数:"+nCount);
  625.  
  626. //计算整体的
  627. sum += nCount;
  628.  
  629. NotificationCompat.Builder notifyBuilder =
  630. new NotificationCompat.Builder(RichApplication.getContext()).setContentTitle(subject)
  631. .setContentText(msgBody)
  632. .setSmallIcon(R.drawable.appicon)
  633. .setLargeIcon(BitmapFactory.decodeResource(RichApplication.getContext().getResources(), R.drawable.appicon))
  634. // 点击消失
  635. .setAutoCancel(true)
  636. // 设置该通知优先级
  637. .setPriority(Notification.PRIORITY_MAX)
  638. .setTicker("悬浮通知")
  639. // 通知首次出现在通知栏,带上升动画效果的
  640. .setWhen(System.currentTimeMillis())
  641. // 通知产生的时间,会在通知信息里显示
  642. // 向通知添加声音、闪灯和振动效果的最简单、最一致的方式是使用当前的用户默认设置,使用defaults属性,可以组合:
  643. .setDefaults( Notification.DEFAULT_VIBRATE | Notification.DEFAULT_ALL | Notification.DEFAULT_SOUND );
  644. Intent intent = new Intent(RichApplication.getContext(), MainActivity.class);
  645. PendingIntent resultPendingIntent =
  646. PendingIntent.getActivity( RichApplication.getContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT );
  647. notifyBuilder.setContentIntent( resultPendingIntent );
  648. NotificationManager mNotifyMgr = (NotificationManager) RichApplication.getContext().getSystemService(Context.NOTIFICATION_SERVICE);
  649. Notification notification = notifyBuilder.build();
  650.  
  651. //设置右上角的角标数量
  652. if (Build.MANUFACTURER.equalsIgnoreCase("Xiaomi")){
  653. //小米手机
  654. boolean isMiUIV6 = true;
  655. Class miuiNotificationClass = null;
  656. try {
  657.  
  658. // Field field = notification.getClass().getDeclaredField("extraNotification");
  659. // Object extraNotification = field.get(notification);
  660. // Method method = extraNotification.getClass().getDeclaredMethod("setMessageCount", int.class);
  661. // method.invoke(extraNotification, sum);
  662.  
  663. } catch (Exception e) {
  664. e.printStackTrace();
  665. //miui 6之前的版本
  666. isMiUIV6 = false;
  667. Intent localIntent = new Intent("android.intent.action.APPLICATION_MESSAGE_UPDATE");
  668. localIntent.putExtra("android.intent.extra.update_application_component_name",
  669. RichApplication.getContext().getPackageName()
  670. + "/"+ "com.richapp.home.MainActivity" );
  671. localIntent.putExtra("android.intent.extra.update_application_message_text",sum);
  672. RichApplication.getContext().sendBroadcast(localIntent);
  673. }
  674. }
  675. else if (Build.MANUFACTURER.equalsIgnoreCase("ZUK")){
  676. //联想手机
  677. final Uri CONTENT_URI = Uri.parse("content://com.android.badge/badge");
  678. Bundle extra = new Bundle();
  679. extra.putInt("app_badge_count", sum);
  680. RichApplication.getContext().getContentResolver().call(CONTENT_URI, "setAppBadgeCount", null, extra);
  681. }
  682. else if (Build.MANUFACTURER.equalsIgnoreCase("OPPO")){
  683. //OPPO手机
  684. Intent launchIntent = RichApplication.getContext().getPackageManager()
  685. .getLaunchIntentForPackage(RichApplication.getContext().getPackageName());
  686. ComponentName componentName = launchIntent.getComponent();
  687. Intent badgeIntent = new Intent("com.oppo.unsettledevent");
  688. badgeIntent.putExtra("pakeageName", componentName.getPackageName());
  689. badgeIntent.putExtra("number", sum);
  690. badgeIntent.putExtra("upgradeNumber", sum);
  691. RichApplication.getContext().sendBroadcast(badgeIntent);
  692. }
  693. else if (Build.MANUFACTURER.equalsIgnoreCase("VIVO")){
  694. //VIVO手机
  695. Intent launchIntent = RichApplication.getContext().getPackageManager()
  696. .getLaunchIntentForPackage(RichApplication.getContext().getPackageName());
  697. ComponentName componentName = launchIntent.getComponent();
  698. Intent badgeIntent = new Intent("launcher.action.CHANGE_APPLICATION_NOTIFICATION_NUM");
  699. badgeIntent.putExtra("packageName", componentName.getPackageName());
  700. badgeIntent.putExtra("className", componentName.getClassName());
  701. badgeIntent.putExtra("notificationNum", sum);
  702. RichApplication.getContext().sendBroadcast(badgeIntent);
  703. }
  704. else if (Build.MANUFACTURER.equalsIgnoreCase("ZTE")){
  705. //中兴手机
  706. Intent launchIntent = RichApplication.getContext().getPackageManager()
  707. .getLaunchIntentForPackage(RichApplication.getContext().getPackageName());
  708. ComponentName componentName = launchIntent.getComponent();
  709. Bundle extra = new Bundle();
  710. extra.putInt("app_badge_count", sum);
  711. extra.putString("app_badge_component_name", componentName.flattenToString());
  712.  
  713. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
  714. RichApplication.getContext().getContentResolver().call(
  715. Uri.parse("content://com.android.launcher3.cornermark.unreadbadge"),
  716. "setAppUnreadCount", null, extra);
  717. }
  718. }
  719. else{
  720. //三星,华为等其他都是广播
  721. Intent launchIntent = RichApplication.getContext().getPackageManager()
  722. .getLaunchIntentForPackage(RichApplication.getContext().getPackageName());
  723. ComponentName componentName = launchIntent.getComponent();
  724.  
  725. Intent badgeIntent = new Intent("android.intent.action.BADGE_COUNT_UPDATE");
  726. badgeIntent.putExtra("badge_count", sum);
  727. badgeIntent.putExtra("badge_count_package_name", componentName.getPackageName());
  728. badgeIntent.putExtra("badge_count_class_name", componentName.getClassName());
  729. RichApplication.getContext().sendBroadcast(badgeIntent);
  730. }
  731.  
  732. mNotifyMgr.notify( R.drawable.appicon, notification);
  733. }
  734.  
  735. }

参考链接:

http://blog.csdn.net/bdmh/article/details/41804695

http://www.jianshu.com/p/20ad37d1418b

Android的Notification相关设置的更多相关文章

  1. Android studio界面相关设置

    用惯了emacs的操作方式,每当使用一款新的编辑器的时候,第一个想到的就是这个工具有没有emacs的快捷键,Android studio也是一样的. 1. Android studio设置emacs的 ...

  2. 使用VIRTUALBOX安装ANDROID系统 | 图文教程 | 相关设置

    使用VIRTUALBOX安装ANDROID系统 | 图文教程 | 相关设置 http://icaoye.com/virtualbox-run-android/

  3. Android开发——Notification通知的使用及NotificationCopat.Builder常用设置API

    想要看全部设置的请看这一篇 [转]NotificationCopat.Builder全部设置 常用设置: 设置属性 说明 setAutoCancel(boolean autocancel) 设置点击信 ...

  4. Android studio相关设置及实现存在于工程目录中的视频播放

    一:相关设置 1:主题设置 File-->Settings-->Appearance &Behavior-->Appearance-->THeme 2:Java源码的颜 ...

  5. Android 添加源码到eclipse 以及相关设置

    作者:舍得333 主页:http://blog.sina.com.cn/u/1509658847版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版.作者信息和本声明,否则将追究法律 ...

  6. Android之Notification介绍

    Notification就是在桌面的状态通知栏.这主要涉及三个主要类: Notification:设置通知的各个属性. NotificationManager:负责发送通知和取消通知 Notifica ...

  7. Android 通知栏Notification的整合 全面学习 (一个DEMO让你完全了解它)

    在android的应用层中,涉及到很多应用框架,例如:Service框架,Activity管理机制,Broadcast机制,对话框框架,标题栏框架,状态栏框架,通知机制,ActionBar框架等等. ...

  8. Android 通知栏Notification的整合 全面学习 (一个DEMO让你全然了解它)

    在android的应用层中,涉及到非常多应用框架.比如:Service框架,Activity管理机制,Broadcast机制,对话框框架,标题栏框架,状态栏框架.通知机制,ActionBar框架等等. ...

  9. 【转】 [置顶] Android 通知栏Notification的整合 全面学习 (一个DEMO让你完全了解它)

    在Android的应用层中,涉及到很多应用框架,例如:Service框架,Activity管理机制,Broadcast机制,对话框框架,标题栏框架,状态栏框架,通知机制,ActionBar框架等等. ...

随机推荐

  1. jquery获取页面iframe内容

    //取得整个HTML格式 var f = $(window.frames["ReportIFrame"].document).contents().html(); 或者 $(&qu ...

  2. 【python】-- pymsql 操作MySQL

    pymysql 对MySQL数据库进行简单数据操作python模块主要是:MySQLdb.pymsql,MySQLdb模块主要用于python2.X,而python3.X则使用pymsql,pymys ...

  3. 洛谷 P2486 [SDOI2011]染色

    题目描述 输入输出格式 输入格式: 输出格式: 对于每个询问操作,输出一行答案. 输入输出样例 输入样例#1: 6 5 2 2 1 2 1 1 1 2 1 3 2 4 2 5 2 6 Q 3 5 C ...

  4. Nodejs课堂笔记-第三课 构建一个nodejs的Docker镜像

    本文由Vikings(http://www.cnblogs.com/vikings-blog/) 原创,转载请标明.谢谢! 因为一直做Linux有关的开发工作,所以不习惯在Windows平台编译和测试 ...

  5. JVM性能优化, Part 1 ―― JVM简介

    JVM性能优化这些列文章共分为5章,是ImportNew上面翻译自Javaworld: 第1章:JVM技术概览 第2章:编译器 第3章:垃圾回收 第4章:并发垃圾回收 第5章:可伸缩性 众所周知,Ja ...

  6. 每天一个Linux命令(28)df命令

    报告文件系统磁盘空间的使用情况.获取硬盘被占用了多少空间,目前还剩下多少空间等信息.       (1)用法:       用法:  df [选项] [文件]       (2)功能: 功能:  显示 ...

  7. mysql设置有外键的主键自增及其他

    有外键的主键设置自增. ; ALTER TABLE `<table>` MODIFY COLUMN `id` ) NOT NULL AUTO_INCREMENT FIRST; 创建数据库, ...

  8. CKeditor插件开发流程(一)

    1.放在多文件中 第一步:config.js中 config.extraPlugins = '插件名称';//注册插件,extraPlugins只允许出现一次,你如果之前有新增别的插件,那么用逗号分隔 ...

  9. [原创]Scala学习:流程控制,异常处理

    1.流程控制 1)do..while def doWhile(){ var line="" do{ line = readLine() println("readline ...

  10. 【leetcode刷题笔记】Word Search

    Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from l ...