├── README.md ├── app ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── example │ │ └── billwangbw │ │ └── appiconnumtest │ │ ├── App.java │ │ ├── ImageUtils.java │ │ ├── Main2Activity.java │ │ ├── MainActivity.java │ │ ├── MyReceiver.java │ │ ├── MyService.java │ │ ├── NotificationBroadcastReceiver.java │ │ └── badges │ │ ├── GoogleModelImpl.java │ │ ├── HuaWeiModelImpl.java │ │ ├── IconBadgeNumManager.java │ │ ├── IconBadgeNumModel.java │ │ ├── LauncherHelper.java │ │ ├── MeizuModelImpl.java │ │ ├── OPPOModelImpl.java │ │ ├── SamsungModelImpl.java │ │ ├── Utils.java │ │ ├── VIVOModelImpl.java │ │ ├── XiaoMiModelImpl.java │ │ └── sendIconNumUtil.java │ ├── libs │ ├── arm64-v8a │ │ └── libjcore127.so │ ├── armeabi-v7a │ │ └── libjcore127.so │ ├── armeabi │ │ └── libjcore127.so │ ├── jcore-android-1.2.7.jar │ ├── jpush-android-3.2.0.jar │ ├── mips │ │ └── libjcore127.so │ ├── mips64 │ │ └── libjcore127.so │ ├── x86 │ │ └── libjcore127.so │ └── x86_64 │ │ └── libjcore127.so │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ ├── ic_launcher_background.xml │ ├── jpush_ic_richpush_actionbar_back.png │ ├── jpush_ic_richpush_actionbar_divider.png │ ├── jpush_richpush_btn_selector.xml │ └── jpush_richpush_progressbar.xml │ ├── layout │ ├── activity_main.xml │ ├── activity_main2.xml │ ├── image_item.xml │ ├── jpush_popwin_layout.xml │ ├── jpush_webview_layout.xml │ └── push_notification.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ ├── ic_launcher_round.png │ └── timg.jpg │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ └── values │ ├── colors.xml │ ├── jpush_style.xml │ ├── strings.xml │ └── styles.xml ├── badges ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── tot │ │ └── badges │ │ ├── IconBadgeNumManager.java │ │ ├── LauncherHelper.java │ │ ├── Utils.java │ │ └── sendIconNumUtil.java │ └── res │ └── values │ └── strings.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── local.properties └── settings.gradle /README.md: -------------------------------------------------------------------------------- 1 | # 华为手机需要添加两个权限 2 | ``` 3 | 4 | 5 | 6 | ``` 7 | 8 | 最好在加上闪光灯以及震动权限: 9 | ``` 10 | 11 | 12 | ``` 13 | # 注意事项: 14 | 1. 源生系统不支持(应该只会显示一个红色圆点不会显示具体数字 具体待测试) 15 | 16 | 2. 魅族不支持该功能 17 | 18 | 3. oppo需要申请(一般的小应用就别考虑的需要日活跃高于一定量) 19 | 20 | 4. vivo需要与厂商合作 21 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | defaultConfig { 6 | applicationId "com.example.billwangbw.appiconnumtest" 7 | minSdkVersion 15 8 | targetSdkVersion 28 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | 13 | //要求JDK 1.8 14 | compileOptions { 15 | sourceCompatibility 1.8 16 | targetCompatibility 1.8 17 | } 18 | 19 | ndk { 20 | //选择要添加的对应cpu类型的.so库。 21 | abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64', 'mips', 'mips64' 22 | } 23 | 24 | manifestPlaceholders = [ 25 | JPUSH_PKGNAME : applicationId, 26 | JPUSH_APPKEY : "c3a768ed1e234b2ffd89cb79", //JPush上注册的包名对应的appkey. 27 | JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可. 28 | ] 29 | 30 | } 31 | buildTypes { 32 | release { 33 | minifyEnabled false 34 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 35 | } 36 | } 37 | } 38 | 39 | dependencies { 40 | api fileTree(include: ['*.jar'], dir: 'libs') 41 | api 'com.android.support:appcompat-v7:28.+' 42 | api 'com.android.support.constraint:constraint-layout:1.1.2' 43 | testImplementation 'junit:junit:4.12' 44 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 45 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 46 | api project(path: ':badges') 47 | implementation 'cn.jiguang.sdk:jpush:3.1.6' 48 | // 此处以JPush 3.1.1 版本为例。 49 | implementation 'cn.jiguang.sdk:jcore:1.2.5' 50 | // 此处以JCore 1.1.9 版本为例。 51 | // implementation files('src/main/libs/jcore-android-1.2.7.jar') 52 | //ARcore依赖库 53 | 54 | implementation "com.google.ar.sceneform:core:1.8.0" 55 | } 56 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 111 | 112 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 130 | > 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 174 | 175 | 176 | 177 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/billwangbw/appiconnumtest/App.java: -------------------------------------------------------------------------------- 1 | package com.example.billwangbw.appiconnumtest; 2 | 3 | import android.app.ActivityManager; 4 | import android.app.Application; 5 | import android.content.Context; 6 | 7 | /** 8 | * 创建时间: 2019/3/11 0011. 9 | * 创建人: yanbin 10 | * 功能: 11 | */ 12 | 13 | 14 | import com.tot.badges.SendIconNumUtil; 15 | 16 | import cn.jpush.android.api.JPushInterface; 17 | 18 | public class App extends Application { 19 | private ActivityManager activityManager; 20 | private String packageName; 21 | private boolean stop = false; 22 | private int mFinalCount = 0; 23 | Exception exception = null; 24 | String msg = null; 25 | 26 | @Override 27 | public void onCreate() { 28 | super.onCreate(); 29 | 30 | activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); 31 | packageName = this.getPackageName(); 32 | JPushInterface.setDebugMode(true); 33 | JPushInterface.init(this); 34 | JPushInterface.clearAllNotifications(this); 35 | //设置每次进入app时清空角标 如果需自定义则在application的onCreate方法调用 36 | // registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() 37 | SendIconNumUtil.init(this); 38 | // 39 | // registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() { 40 | // 41 | // @Override 42 | // public void onActivityCreated(Activity activity, Bundle bundle) { 43 | // Log.d("test==", "我是onActivityCreated"); 44 | // } 45 | // 46 | // @Override 47 | // public void onActivityStarted(Activity activity) { 48 | // 49 | // Log.d("test==", "回到了前台了"); 50 | // SendIconNumUtil.sendIconNumNotification(0, (Application) getApplicationContext(), 222); 51 | // //测试修改 52 | // } 53 | // 54 | // @Override 55 | // public void onActivityResumed(Activity activity) { 56 | // Log.d("test==", "我是onActivityResumed"); 57 | // } 58 | // 59 | // @Override 60 | // public void onActivityPaused(Activity activity) { 61 | // Log.d("test==", "我是onActivityPaused"); 62 | // } 63 | // 64 | // @Override 65 | // public void onActivityStopped(Activity activity) { 66 | // 67 | // Log.d("test==", "滚后台去了"); 68 | // 69 | // } 70 | // 71 | // @Override 72 | // public void onActivitySaveInstanceState(Activity activity, Bundle bundle) { 73 | // Log.d("test==", "我是onActivitySaveInstanceState"); 74 | // } 75 | // 76 | // @Override 77 | // public void onActivityDestroyed(Activity activity) { 78 | // Log.d("test==", "我是onActivityDestroyed"); 79 | // } 80 | // }); 81 | } 82 | 83 | 84 | // private class AppStatus implements Runnable { 85 | // @Override 86 | // public void run() { 87 | // stop = false; 88 | // 89 | // while (!stop) { 90 | // try { 91 | // if (appOnForeground()) { 92 | // System.out.println("当前App处于前台"); 93 | // } else { 94 | // System.out.println("当前App处于后台"); 95 | // } 96 | // } catch (Exception e) { 97 | // e.printStackTrace(); 98 | // } 99 | // 100 | // try { 101 | // TimeUnit.SECONDS.sleep(1); 102 | // } catch (Exception e) { 103 | // e.printStackTrace(); 104 | // } 105 | // } 106 | // } 107 | // } 108 | // 109 | // private boolean appOnForeground() { 110 | // List appProcesses = activityManager.getRunningAppProcesses(); 111 | // 112 | // if (appProcesses == null) 113 | // return false; 114 | // 115 | // for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) { 116 | // if (appProcess.processName.equals(packageName) && appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { 117 | // return true; 118 | // } 119 | // } 120 | // 121 | // return false; 122 | // } 123 | // 124 | // private void processCustomMessage(Context context, Bundle bundle) { 125 | // 126 | // String channelID = "1"; 127 | // String channelName = "channel_name"; 128 | // 129 | // // 跳转的Activity 130 | // Intent intent = new Intent(context, Main2Activity.class); 131 | // intent.putExtras(bundle); 132 | // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); 133 | // 134 | // PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); 135 | // 136 | // // 获得系统推送的自定义消息 137 | // String message = bundle.getString(JPushInterface.EXTRA_MESSAGE); 138 | // 139 | // NotificationManager notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE); 140 | // 141 | // //适配安卓8.0的消息渠道 142 | // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 143 | // NotificationChannel channel = new NotificationChannel(channelID, channelName, NotificationManager.IMPORTANCE_HIGH); 144 | // notificationManager.createNotificationChannel(channel); 145 | // } 146 | // 147 | // NotificationCompat.Builder notification = 148 | // new NotificationCompat.Builder(context, channelID); 149 | // 150 | // notification.setAutoCancel(true) 151 | // .setContentText(message) 152 | // .setContentTitle("我是Title") 153 | // .setSmallIcon(R.mipmap.ic_launcher) 154 | // .setDefaults(Notification.DEFAULT_ALL) 155 | // .setContentIntent(pendingIntent); 156 | // 157 | // notificationManager.notify((int) (System.currentTimeMillis() / 1000), notification.build()); 158 | // } 159 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/billwangbw/appiconnumtest/ImageUtils.java: -------------------------------------------------------------------------------- 1 | package com.example.billwangbw.appiconnumtest; 2 | 3 | /** 4 | * 创建时间: 2019/3/14 0014. 5 | * 创建人: yanbin 6 | * 功能: 7 | */ 8 | 9 | public class ImageUtils { 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/billwangbw/appiconnumtest/Main2Activity.java: -------------------------------------------------------------------------------- 1 | package com.example.billwangbw.appiconnumtest; 2 | 3 | import android.app.NotificationManager; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.os.Bundle; 8 | import android.view.View; 9 | import android.widget.TextView; 10 | 11 | public class Main2Activity extends AppCompatActivity { 12 | 13 | String mTvView; 14 | 15 | TextView textView; 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_main2); 21 | textView = findViewById(R.id.textView); 22 | try { 23 | mTvView = getIntent().getStringExtra("test"); 24 | } catch (Exception e) { 25 | 26 | } 27 | textView.setOnClickListener(new View.OnClickListener() { 28 | @Override 29 | public void onClick(View view) { 30 | textView.setText(mTvView); 31 | NotificationManager managers = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 32 | // managers.cancel(R.mipmap.ic_launcher); 33 | managers.cancel(666); 34 | } 35 | }); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/billwangbw/appiconnumtest/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.billwangbw.appiconnumtest; 2 | 3 | import android.app.Notification; 4 | import android.app.NotificationChannel; 5 | import android.app.NotificationManager; 6 | import android.app.PendingIntent; 7 | import android.content.Context; 8 | import android.content.Intent; 9 | import android.graphics.Color; 10 | import android.os.Build; 11 | import android.support.annotation.RequiresApi; 12 | import android.support.v4.app.NotificationCompat; 13 | import android.support.v7.app.AppCompatActivity; 14 | import android.os.Bundle; 15 | import android.util.Log; 16 | import android.view.View; 17 | import android.widget.RemoteViews; 18 | 19 | import com.tot.badges.IconBadgeNumManager; 20 | import com.tot.badges.LauncherHelper; 21 | import com.tot.badges.SendIconNumUtil; 22 | 23 | import cn.jpush.android.api.JPushInterface; 24 | 25 | 26 | public class MainActivity extends AppCompatActivity { 27 | private static final String TAG = "MainActivity"; 28 | IconBadgeNumManager setIconBadgeNumManager = new IconBadgeNumManager(); 29 | public static int i = 0; 30 | NotificationManager nm; 31 | @Override 32 | protected void onCreate(Bundle savedInstanceState) { 33 | super.onCreate(savedInstanceState); 34 | setContentView(R.layout.activity_main); 35 | Log.e(TAG, Build.MANUFACTURER); 36 | Log.e(TAG, new LauncherHelper().getLauncherPackageName(this)); 37 | findViewById(R.id.button3).setOnClickListener(new View.OnClickListener() { 38 | @Override 39 | public void onClick(View v) { 40 | // JPushInterface.clearAllNotifications(MainActivity.this); 41 | SendIconNumUtil.clearAllIconNumNotifucation(); 42 | } 43 | }); 44 | findViewById(R.id.button1).setOnClickListener(new View.OnClickListener() { 45 | @Override 46 | public void onClick(View view) { 47 | 48 | String notificationChannelId = null; 49 | NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 50 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 51 | //8.0以上需设置消息通道id 52 | NotificationChannel notificationChannel = createNotificationChannel(); 53 | nm.createNotificationChannel(notificationChannel); 54 | notificationChannelId = notificationChannel.getId(); 55 | } 56 | Notification notification = null; 57 | RemoteViews remoteViews = new RemoteViews(getApplicationContext().getPackageName(), R.layout.image_item); 58 | remoteViews.setTextViewText(R.id.mTv, "wohahahahahahah"); 59 | notification = new NotificationCompat.Builder(MainActivity.this, notificationChannelId) 60 | .setSmallIcon(getApplicationInfo().icon) 61 | .setWhen(System.currentTimeMillis()) 62 | .setAutoCancel(true) 63 | .setCustomContentView(remoteViews) 64 | .build(); 65 | SendIconNumUtil.sendIconNumNotification(5, getApplication(), 666, notification, nm); 66 | 67 | //点击导航栏的跳转事件(系统默认导航栏) 68 | // Intent intent = new Intent(MainActivity.this, Main2Activity.class); 69 | // //从导航传递的数据 70 | // intent.putExtra("test", "我是测试从通知栏传过来的数据"); 71 | // i++; 72 | // String chann = "test" + i; 73 | // PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0, intent, 74 | // PendingIntent.FLAG_ONE_SHOT); 75 | // SendIconNumUtil.sendIconNumNotification(1, getApplication(), i, pendingIntent, 76 | // "testTitle", "tests", R.mipmap.ic_launcher, 77 | // "我是ticker", i + "", "测试专用渠道2"); 78 | // sendIconNumNotification(5); 79 | } 80 | }); 81 | findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() { 82 | @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN) 83 | @Override 84 | public void onClick(View view) { 85 | //自定义导航栏 86 | String notificationChannelId = null; 87 | nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 88 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 89 | //8.0以上需设置消息通道id 90 | NotificationChannel notificationChannel = createNotificationChannel(); 91 | nm.createNotificationChannel(notificationChannel); 92 | notificationChannelId = notificationChannel.getId(); 93 | } 94 | Notification notification = null; 95 | RemoteViews remoteViews = new RemoteViews(getApplicationContext().getPackageName(), R.layout.image_item); 96 | remoteViews.setTextViewText(R.id.mTv, "wohahahahahahah"); 97 | notification = new NotificationCompat.Builder(MainActivity.this, notificationChannelId) 98 | .setSmallIcon(getApplicationInfo().icon) 99 | .setWhen(System.currentTimeMillis()) 100 | .setAutoCancel(true) 101 | .setCustomContentView(remoteViews) 102 | .build(); 103 | SendIconNumUtil.sendIconNumNotification(5, getApplication(), 555, notification, nm); 104 | } 105 | }); 106 | 107 | } 108 | 109 | 110 | @RequiresApi(api = Build.VERSION_CODES.O) 111 | private static NotificationChannel createNotificationChannel() { 112 | String channelId = "test"; 113 | NotificationChannel channel = null; 114 | channel = new NotificationChannel(channelId, 115 | "第四个权限", NotificationManager.IMPORTANCE_HIGH); 116 | channel.enableLights(true); //是否在桌面icon右上角展示小红点 117 | channel.setLightColor(Color.BLACK); //小红点颜色 118 | channel.setShowBadge(true); //是否在久按桌面图标时显示此渠道的通知 119 | return channel; 120 | } 121 | 122 | 123 | @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN) 124 | private void addNotificationChannel() { 125 | //点击后进入的界面 126 | Intent intent = new Intent(this, Main2Activity.class); 127 | intent.putExtra("test", "我是测试从通知栏传过来的数据"); 128 | PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); 129 | 130 | 131 | Notification notification = new Notification.Builder(this) 132 | .setTicker("托儿所") 133 | .setContentTitle("喜之郎") 134 | .setContentText("儿童节") 135 | .setSmallIcon(R.mipmap.ic_launcher) 136 | .setContentIntent(pendingIntent) 137 | .build(); 138 | 139 | NotificationManager manager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); 140 | manager.notify(666, notification); 141 | } 142 | 143 | } 144 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/billwangbw/appiconnumtest/MyReceiver.java: -------------------------------------------------------------------------------- 1 | package com.example.billwangbw.appiconnumtest; 2 | 3 | import android.app.Application; 4 | import android.app.PendingIntent; 5 | import android.content.BroadcastReceiver; 6 | import android.content.Context; 7 | import android.content.Intent; 8 | import android.os.Bundle; 9 | import android.text.TextUtils; 10 | import android.util.Log; 11 | 12 | 13 | import com.tot.badges.SendIconNumUtil; 14 | 15 | import cn.jpush.android.api.JPushInterface; 16 | 17 | import static com.example.billwangbw.appiconnumtest.MainActivity.i; 18 | 19 | /** 20 | * 创建时间: 2019/3/14 0014. 21 | * 创建人: yanbin 22 | * 功能: 23 | */ 24 | 25 | public class MyReceiver extends BroadcastReceiver { 26 | private static final String TAG = "JIGUANG"; 27 | public static String regId; 28 | String extra_json; 29 | 30 | @Override 31 | public void onReceive(Context context, Intent intent) { 32 | 33 | try { 34 | Bundle bundle = intent.getExtras(); 35 | 36 | if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) { 37 | regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID); 38 | Log.d(TAG, "[MyReceiver] 接收Registration Id : " + regId); 39 | 40 | //send the Registration Id to your server... 41 | 42 | } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) { 43 | Log.d(TAG, "[MyReceiver] 接收到推送下来的自定义消息(内容为): " + bundle.getString(JPushInterface.EXTRA_MESSAGE)); 44 | // processCustomMessage(context, bundle); 45 | PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 46 | PendingIntent.FLAG_ONE_SHOT); 47 | SendIconNumUtil.sendIconNumNotification(1, (Application) context.getApplicationContext(), i, pendingIntent, 48 | "testTitle", "tests", R.mipmap.ic_launcher, 49 | "我是ticker", bundle.getString(JPushInterface.EXTRA_MESSAGE), "测试专用渠道1"); 50 | i++; 51 | // 自定义消息不是通知,默认不会被SDK展示到通知栏上,极光推送仅负责透传给SDK。其内容和展示形式完全由开发者自己定义。 52 | // 自定义消息主要用于应用的内部业务逻辑和特殊展示需求 53 | } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) { 54 | Log.d(TAG, "[MyReceiver] 接收到推送下来的通知"); 55 | i++; 56 | extra_json = bundle.getString(JPushInterface.EXTRA_EXTRA); 57 | if (!TextUtils.isEmpty(extra_json)) 58 | Log.d(TAG, "[MyReceiver] 接收到推送下来的通知附加字段" + extra_json); 59 | 60 | // 可以利用附加字段来区别Notication,指定不同的动作,extra_json是个json字符串 61 | // 通知(Notification),指在手机的通知栏(状态栏)上会显示的一条通知信息 62 | } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) { 63 | 64 | // 在这里根据 JPushInterface.EXTRA_EXTRA(附加字段) 的内容处理代码, 65 | // 比如打开新的Activity, 打开一个网页等.. 66 | 67 | } else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) { 68 | Log.d(TAG, "[MyReceiver] 用户收到到RICH PUSH CALLBACK: " + bundle.getString(JPushInterface.EXTRA_EXTRA)); 69 | //在这里根据 JPushInterface.EXTRA_EXTRA 的内容处理代码,比如打开新的Activity, 打开一个网页等.. 70 | i++; 71 | } else if (JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) { 72 | boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false); 73 | Log.w(TAG, "[MyReceiver]" + intent.getAction() + " connected state change to " + connected); 74 | } else { 75 | Log.d(TAG, "[MyReceiver] Unhandled intent - " + intent.getAction()); 76 | } 77 | 78 | SendIconNumUtil.sendIconNumNotification(i, (Application) context.getApplicationContext()); 79 | } catch (Exception e) { 80 | 81 | } 82 | 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/billwangbw/appiconnumtest/MyService.java: -------------------------------------------------------------------------------- 1 | package com.example.billwangbw.appiconnumtest; 2 | 3 | import android.app.Notification; 4 | import android.app.NotificationChannel; 5 | import android.app.NotificationManager; 6 | import android.app.Service; 7 | import android.content.Context; 8 | import android.content.Intent; 9 | import android.graphics.Color; 10 | import android.os.Build; 11 | import android.os.IBinder; 12 | import android.support.annotation.RequiresApi; 13 | import android.support.v4.app.NotificationCompat; 14 | 15 | import com.tot.badges.IconBadgeNumManager; 16 | 17 | public class MyService extends Service { 18 | IconBadgeNumManager setIconBadgeNumManager; 19 | private boolean isStop; 20 | private int count; 21 | Thread thread = new Thread(new Runnable() { 22 | @Override 23 | public void run() { 24 | while (!isStop) { 25 | try { 26 | Thread.sleep(1000); 27 | } catch (InterruptedException e) { 28 | e.printStackTrace(); 29 | } 30 | count += 10; 31 | sendIconNumNotification(); 32 | } 33 | } 34 | }); 35 | 36 | public MyService() { 37 | setIconBadgeNumManager = new IconBadgeNumManager(); 38 | 39 | } 40 | 41 | @Override 42 | public int onStartCommand(Intent intent, int flags, int startId) { 43 | isStop = false; 44 | thread.start(); 45 | return super.onStartCommand(intent, flags, startId); 46 | } 47 | 48 | @Override 49 | public void onDestroy() { 50 | super.onDestroy(); 51 | isStop = true; 52 | } 53 | 54 | @Override 55 | public IBinder onBind(Intent intent) { 56 | throw new UnsupportedOperationException("Not yet implemented"); 57 | } 58 | 59 | private void sendIconNumNotification() { 60 | NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 61 | if (nm == null) return; 62 | String notificationChannelId = null; 63 | if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { 64 | NotificationChannel notificationChannel = createNotificationChannel(); 65 | nm.createNotificationChannel(notificationChannel); 66 | notificationChannelId = notificationChannel.getId(); 67 | } 68 | Notification notification = null; 69 | try { 70 | notification = new NotificationCompat.Builder(this, notificationChannelId) 71 | .setSmallIcon(getApplicationInfo().icon) 72 | .setWhen(System.currentTimeMillis()) 73 | .setContentTitle("title") 74 | .setContentText("content num: " + count) 75 | .setTicker("ticker") 76 | .setAutoCancel(true) 77 | .setNumber(count) 78 | .build(); 79 | notification = setIconBadgeNumManager.setIconBadgeNum(getApplication(), notification, count); 80 | 81 | nm.notify(32154, notification); 82 | } catch (Exception e) { 83 | e.printStackTrace(); 84 | } 85 | } 86 | 87 | @RequiresApi(api = Build.VERSION_CODES.O) 88 | private static NotificationChannel createNotificationChannel() { 89 | String channelId = "test"; 90 | NotificationChannel channel = null; 91 | channel = new NotificationChannel(channelId, 92 | "Channel1", NotificationManager.IMPORTANCE_DEFAULT); 93 | channel.enableLights(true); //是否在桌面icon右上角展示小红点 94 | channel.setLightColor(Color.RED); //小红点颜色 95 | channel.setShowBadge(true); //是否在久按桌面图标时显示此渠道的通知 96 | return channel; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/billwangbw/appiconnumtest/NotificationBroadcastReceiver.java: -------------------------------------------------------------------------------- 1 | package com.example.billwangbw.appiconnumtest; 2 | 3 | import android.app.NotificationManager; 4 | import android.content.BroadcastReceiver; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.util.Log; 8 | 9 | /** 10 | * 创建时间: 2019/3/11 0011. 11 | * 创建人: yanbin 12 | * 功能:监听通知栏消失 13 | */ 14 | 15 | public class NotificationBroadcastReceiver extends BroadcastReceiver { 16 | @Override 17 | public void onReceive(Context context, Intent intent) { 18 | String action = intent.getAction(); 19 | int type = intent.getIntExtra("type",1); 20 | if (type == -1){ 21 | NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 22 | notificationManager.cancel(type); 23 | if (action.equals("notification_cancelled")){ 24 | Log.d("LogTestNotification","h删除通知栏所有成功"); 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/billwangbw/appiconnumtest/badges/GoogleModelImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.billwangbw.appiconnumtest.badges; 2 | 3 | import android.app.Application; 4 | import android.app.Notification; 5 | import android.content.Intent; 6 | import android.support.annotation.NonNull; 7 | 8 | /** 9 | * 10 | */ 11 | public class GoogleModelImpl implements IconBadgeNumModel { 12 | private static final String NOTIFICATION_ERROR = "google not support before API O"; 13 | 14 | @Override 15 | public Notification setIconBadgeNum(@NonNull Application context, Notification notification, int count) throws Exception { 16 | if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O) { 17 | throw new Exception(NOTIFICATION_ERROR); 18 | } 19 | Intent intent = new Intent("android.intent.action.BADGE_COUNT_UPDATE"); 20 | intent.putExtra("badge_count", count); 21 | intent.putExtra("badge_count_package_name", context.getPackageName()); 22 | intent.putExtra("badge_count_class_name", Utils.getInstance().getLaunchIntentForPackage(context)); // com.test. badge.MainActivity is your apk main activity 23 | 24 | // if (Utils.getInstance().canResolveBroadcast(context, intent)) { 25 | context.sendBroadcast(intent); 26 | // } else { 27 | // throw new Exception(UNABLE_TO_RESOLVE_INTENT_ERROR_ + intent.toString()); 28 | // } 29 | 30 | return notification; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/billwangbw/appiconnumtest/badges/HuaWeiModelImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.billwangbw.appiconnumtest.badges; 2 | 3 | import android.app.Application; 4 | import android.app.Notification; 5 | import android.net.Uri; 6 | import android.os.Bundle; 7 | import android.support.annotation.NonNull; 8 | 9 | /** 10 | * https://developer.huawei.com/consumer/cn/devservice/doc/30802 11 | *

12 | * max:99 13 | */ 14 | public class HuaWeiModelImpl implements IconBadgeNumModel { 15 | @Override 16 | public Notification setIconBadgeNum(@NonNull Application context, Notification notification, int count) throws Exception { 17 | Bundle bunlde = new Bundle(); 18 | bunlde.putString("package", context.getPackageName()); // com.test.badge is your package name 19 | bunlde.putString("class", Utils.getInstance().getLaunchIntentForPackage(context)); // com.test. badge.MainActivity is your apk main activity 20 | bunlde.putInt("badgenumber", count); 21 | context.getContentResolver().call(Uri.parse("content://com.huawei.android.launcher.settings/badge/"), "change_badge", null, bunlde); 22 | return notification; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/billwangbw/appiconnumtest/badges/IconBadgeNumManager.java: -------------------------------------------------------------------------------- 1 | package com.example.billwangbw.appiconnumtest.badges; 2 | 3 | import android.app.Application; 4 | import android.app.Notification; 5 | import android.support.annotation.NonNull; 6 | import android.text.TextUtils; 7 | 8 | import java.util.HashMap; 9 | import java.util.Map; 10 | 11 | public class IconBadgeNumManager implements IconBadgeNumModel { 12 | private static final String NOT_SUPPORT_PHONE = "not support your phone [ Build.MANUFACTURER is null ]"; 13 | private static final String NOT_SUPPORT_MANUFACTURER_ = "not support "; 14 | private static final String NOT_SUPPORT_LAUNCHER = "not support your launcher [ default launcher is null ]"; 15 | private static final String NOT_SUPPORT_LAUNCHER_ = "not support "; 16 | private Map iconBadgeNumModelMap; 17 | private LauncherHelper launcherHelper; 18 | 19 | public IconBadgeNumManager() { 20 | this.launcherHelper = new LauncherHelper(); 21 | iconBadgeNumModelMap = new HashMap<>(); 22 | } 23 | 24 | @Override 25 | public Notification setIconBadgeNum(@NonNull Application context, Notification notification, int count) throws Exception { 26 | IconBadgeNumModel iconBadgeNumModel = getSetIconBadgeNumModel(context); 27 | return iconBadgeNumModel.setIconBadgeNum(context, notification, count); 28 | } 29 | 30 | /** 31 | * 根据手机当前launcher获取相应Model 32 | */ 33 | @NonNull 34 | private IconBadgeNumModel getIconBadgeNumModelByLauncher(@NonNull String launcherType) throws Exception { 35 | switch (launcherType) { 36 | case LauncherHelper.HUAWEI: 37 | return new HuaWeiModelImpl(); 38 | case LauncherHelper.XIAOMI: 39 | return new XiaoMiModelImpl(); 40 | case LauncherHelper.VIVO: 41 | return new VIVOModelImpl(); 42 | case LauncherHelper.OPPO: 43 | return new OPPOModelImpl(); 44 | case LauncherHelper.SAMSUNG: 45 | return new SamsungModelImpl(); 46 | case LauncherHelper.MEIZU: 47 | return new MeizuModelImpl(); 48 | case LauncherHelper.GOOGLE: 49 | return new GoogleModelImpl(); 50 | default: 51 | throw new Exception(NOT_SUPPORT_LAUNCHER_ + launcherType); 52 | } 53 | } 54 | 55 | @NonNull 56 | private IconBadgeNumModel getSetIconBadgeNumModel(@NonNull Application context) throws Exception { 57 | String launcherName = launcherHelper.getLauncherPackageName(context); 58 | if (TextUtils.isEmpty(launcherName)) { 59 | throw new Exception(NOT_SUPPORT_LAUNCHER); 60 | } 61 | String launcherType = launcherHelper.getLauncherTypeByName(launcherName); 62 | if (TextUtils.isEmpty(launcherType)) { 63 | throw new Exception(NOT_SUPPORT_LAUNCHER_ + launcherName); 64 | } 65 | if (iconBadgeNumModelMap.containsKey(launcherType)) { 66 | return iconBadgeNumModelMap.get(launcherType); 67 | } 68 | IconBadgeNumModel iconBadgeNumModel = getIconBadgeNumModelByLauncher(launcherType); 69 | iconBadgeNumModelMap.put(launcherType, iconBadgeNumModel); 70 | return iconBadgeNumModel; 71 | } 72 | 73 | 74 | } 75 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/billwangbw/appiconnumtest/badges/IconBadgeNumModel.java: -------------------------------------------------------------------------------- 1 | package com.example.billwangbw.appiconnumtest.badges; 2 | 3 | import android.app.Application; 4 | import android.app.Notification; 5 | import android.support.annotation.NonNull; 6 | 7 | public interface IconBadgeNumModel { 8 | Notification setIconBadgeNum(@NonNull Application context, Notification notification, int count) throws Exception; 9 | } 10 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/billwangbw/appiconnumtest/badges/LauncherHelper.java: -------------------------------------------------------------------------------- 1 | package com.example.billwangbw.appiconnumtest.badges; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.content.pm.ResolveInfo; 6 | import android.support.annotation.NonNull; 7 | import android.support.annotation.Nullable; 8 | 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | public class LauncherHelper { 13 | public final static String GOOGLE = "google"; 14 | public final static String HUAWEI = "huawei"; 15 | public final static String MEIZU = "meizu"; 16 | public final static String XIAOMI = "xiaomi"; 17 | public final static String OPPO = "oppo"; 18 | public final static String VIVO = "vivo"; 19 | public final static String SAMSUNG = "samsung"; 20 | 21 | private static Map launcherMap; 22 | 23 | static { 24 | launcherMap = new HashMap<>(); 25 | launcherMap.put("com.huawei.android.launcher", HUAWEI); 26 | launcherMap.put("com.miui.home", XIAOMI); 27 | launcherMap.put("com.sec.android.app.launcher", SAMSUNG); 28 | launcherMap.put("com.google.android.apps.nexuslauncher", GOOGLE); 29 | } 30 | 31 | @Nullable 32 | public String getLauncherTypeByName(@NonNull String launcherName) { 33 | return launcherMap.get(launcherName); 34 | } 35 | 36 | @Nullable 37 | public String getLauncherPackageName(@NonNull Context context) { 38 | final Intent intent = new Intent(Intent.ACTION_MAIN); 39 | intent.addCategory(Intent.CATEGORY_HOME); 40 | final ResolveInfo res = context.getPackageManager().resolveActivity(intent, 0); 41 | if (res.activityInfo == null) { 42 | // should not happen. A home is always installed, isn't it? 43 | return null; 44 | } 45 | if (res.activityInfo.packageName.equals("android")) { 46 | return null; 47 | } else { 48 | return res.activityInfo.packageName; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/billwangbw/appiconnumtest/badges/MeizuModelImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.billwangbw.appiconnumtest.badges; 2 | 3 | import android.app.Application; 4 | import android.app.Notification; 5 | import android.support.annotation.NonNull; 6 | 7 | public class MeizuModelImpl implements IconBadgeNumModel { 8 | private static final String NOTIFICATION_ERROR = "not support : meizu"; 9 | 10 | @Override 11 | public Notification setIconBadgeNum(@NonNull Application context, Notification notification, int count) throws Exception { 12 | if (true) { 13 | throw new Exception(NOTIFICATION_ERROR); 14 | } 15 | return null; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/billwangbw/appiconnumtest/badges/OPPOModelImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.billwangbw.appiconnumtest.badges; 2 | 3 | import android.app.Application; 4 | import android.app.Notification; 5 | import android.support.annotation.NonNull; 6 | 7 | /** 8 | * 以下是oppo客服原文(其中没有说明3.3中日活量和总下载量的标准) 9 | *

10 | * 亲,您可以通过邮件的形式提交申请,邮件形式如下: 11 | *

12 | * 1.主题:“申请开放OPPO手机应用角标权限——(应用名称)” 13 | *

14 | * 2.收件人:devtec@oppo.com 15 | *

16 | * 3.正文:应用角标申请所需材料 17 | * 以下为应用角标申请所需材料: 18 | * 1.应用方申请人基本信息(姓名、邮箱、手机、微信); 19 | * 2.应用方厂商介绍(不少于200字); 20 | * 3.申请应用近一个月内IOS与安卓系统的平均日活量及总下载量介绍; 21 | * 4.申请应用产品主要功能介绍(不少于100字); 22 | * 5.申请应用期望角标出现的全部场景。(即哪些类的消息需要出现角标,需全部列出) 23 | *

24 | * 您这边以邮件的形式申请接入角标后,OPPO方审核人员将在接收日期10个工作日内给出审核结果。感谢您对OPPO开放平台的关注与信任,还 25 | * 请您耐心等待的哦~ 26 | */ 27 | public class OPPOModelImpl implements IconBadgeNumModel { 28 | private static final String NOTIFICATION_ERROR = "not support : oppo"; 29 | 30 | @Override 31 | public Notification setIconBadgeNum(@NonNull Application context, Notification notification, int count) throws Exception { 32 | if (true) { 33 | throw new Exception(NOTIFICATION_ERROR); 34 | } 35 | return null; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/billwangbw/appiconnumtest/badges/SamsungModelImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.billwangbw.appiconnumtest.badges; 2 | 3 | import android.app.Application; 4 | import android.app.Notification; 5 | import android.content.Intent; 6 | import android.support.annotation.NonNull; 7 | 8 | import static com.tot.badges.Utils.UNABLE_TO_RESOLVE_INTENT_ERROR_; 9 | 10 | /** 11 | * 没有找到官方文档说明,只有网上的方法 12 | *

13 | * Galaxy S8/SM-G9500/android 8.0 14 | * Galaxy Galaxy Note8/SM-N9500/android 8.0 15 | */ 16 | public class SamsungModelImpl implements IconBadgeNumModel { 17 | private static final String NOTIFICATION_ERROR = "not support : samsung"; 18 | 19 | @Override 20 | public Notification setIconBadgeNum(@NonNull Application context, Notification notification, int count) throws Exception { 21 | Intent intent = new Intent("android.intent.action.BADGE_COUNT_UPDATE"); 22 | intent.putExtra("badge_count", count); 23 | intent.putExtra("badge_count_package_name", context.getPackageName()); 24 | intent.putExtra("badge_count_class_name", Utils.getInstance().getLaunchIntentForPackage(context)); 25 | 26 | if (Utils.getInstance().canResolveBroadcast(context, intent)) { 27 | context.sendBroadcast(intent); 28 | } else { 29 | throw new Exception(UNABLE_TO_RESOLVE_INTENT_ERROR_ + intent.toString()); 30 | } 31 | return notification; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/billwangbw/appiconnumtest/badges/Utils.java: -------------------------------------------------------------------------------- 1 | package com.example.billwangbw.appiconnumtest.badges; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.content.pm.PackageManager; 6 | import android.content.pm.ResolveInfo; 7 | 8 | import java.util.List; 9 | 10 | public class Utils { 11 | public static final String UNABLE_TO_RESOLVE_INTENT_ERROR_ = "unable to resolve intent: "; 12 | 13 | private static Utils instance; 14 | 15 | public static Utils getInstance() { 16 | if (instance == null) { 17 | instance = new Utils(); 18 | } 19 | return instance; 20 | } 21 | 22 | public boolean canResolveBroadcast(Context context, Intent intent) { 23 | PackageManager packageManager = context.getPackageManager(); 24 | List receivers = packageManager.queryBroadcastReceivers(intent, 0); 25 | return receivers != null && receivers.size() > 0; 26 | } 27 | 28 | public String getLaunchIntentForPackage(Context context) { 29 | return context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()).getComponent().getClassName(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/billwangbw/appiconnumtest/badges/VIVOModelImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.billwangbw.appiconnumtest.badges; 2 | 3 | import android.app.Application; 4 | import android.app.Notification; 5 | import android.support.annotation.NonNull; 6 | 7 | /** 8 | * 网上查到了此段代码,但在vivo X21A[android-8.1.0/Funtouch OS_4.0]真机上并未测试成功。 9 | * 在vivo开发者平台上与人工客服联系后,对方回复暂时没有公开的方法可以设置,也没有渠道可以申请,只有vivo特别指定的应用可以实现(微信、微博等) 10 | */ 11 | public class VIVOModelImpl implements IconBadgeNumModel { 12 | private static final String NOTIFICATION_ERROR = "not support : vivo"; 13 | 14 | @Override 15 | public Notification setIconBadgeNum(@NonNull Application context, Notification notification, int count) throws Exception { 16 | if (true) { 17 | throw new Exception(NOTIFICATION_ERROR); 18 | } 19 | return null; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/billwangbw/appiconnumtest/badges/XiaoMiModelImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.billwangbw.appiconnumtest.badges; 2 | 3 | import android.app.Application; 4 | import android.app.Notification; 5 | import android.support.annotation.NonNull; 6 | 7 | import java.lang.reflect.Field; 8 | import java.lang.reflect.Method; 9 | 10 | /** 11 | * https://dev.mi.com/console/doc/detail?pId=939 12 | *

13 | * 必须发送通知 14 | */ 15 | public class XiaoMiModelImpl implements IconBadgeNumModel { 16 | private static final String NOTIFICATION_ERROR = "Xiaomi phones must send notification"; 17 | 18 | @Override 19 | public Notification setIconBadgeNum(@NonNull Application context, Notification notification, int count) throws Exception { 20 | if (notification == null) { 21 | throw new Exception(NOTIFICATION_ERROR); 22 | } 23 | Field field = notification.getClass().getDeclaredField("extraNotification"); 24 | Object extraNotification = field.get(notification); 25 | Method method = extraNotification.getClass().getDeclaredMethod("setMessageCount", int.class); 26 | method.invoke(extraNotification, count); 27 | return notification; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/billwangbw/appiconnumtest/badges/sendIconNumUtil.java: -------------------------------------------------------------------------------- 1 | package com.example.billwangbw.appiconnumtest.badges; 2 | 3 | import android.app.Application; 4 | import android.app.Notification; 5 | import android.app.NotificationChannel; 6 | import android.app.NotificationManager; 7 | import android.app.PendingIntent; 8 | import android.content.Context; 9 | import android.graphics.Color; 10 | import android.os.Build; 11 | import android.support.annotation.RequiresApi; 12 | import android.support.v4.app.NotificationCompat; 13 | import android.util.Log; 14 | 15 | /** 16 | * 创建时间: 2019/3/12 0012. 17 | * 创建人: yanbin 18 | * 功能: 19 | */ 20 | 21 | public class sendIconNumUtil { 22 | 23 | private static IconBadgeNumManager setIconBadgeNumManager = new IconBadgeNumManager(); 24 | 25 | /** 26 | * 设置角标(不带出现通知栏) 27 | * 28 | * @param i 角标数字(为0时清空角标) 29 | * @param context 上下文 30 | * @param notIfyId 通知id 31 | */ 32 | public static void sendIconNumNotification(int i, Application context, int notIfyId) { 33 | NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 34 | if (nm == null) return; 35 | String notificationChannelId = null; 36 | 37 | Notification notification = null; 38 | try { 39 | notification = new NotificationCompat.Builder(context, notificationChannelId) 40 | .setSmallIcon(context.getApplicationInfo().icon) 41 | .setWhen(System.currentTimeMillis()) 42 | .setAutoCancel(true) 43 | .build(); 44 | notification = setIconBadgeNumManager.setIconBadgeNum(context, notification, i); 45 | nm.notify(notIfyId, notification); 46 | } catch (Exception e) { 47 | e.printStackTrace(); 48 | } 49 | } 50 | 51 | /** 52 | * 设置角标并且带通知栏 53 | * 54 | * @param i 角标数字(为0时清空角标) 55 | * @param context 上下文 56 | * @param notifyID 通知id 57 | * @param pendingIntent 跳转事件 58 | * @param title 标题 59 | * @param channelId 通知栏 id 60 | * @param SmallIcon 图标 61 | * @param Ticker 62 | * @param ContentText 通知内容 63 | * @param channelName 通知栏渠道划分(用来区分通知类型如果不传默认为其他分类) 64 | */ 65 | public static void sendIconNumNotification(int i, Application context, int notifyID, PendingIntent pendingIntent, String title, String channelId, int SmallIcon 66 | , String Ticker, String ContentText, String channelName) { 67 | 68 | NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 69 | if (nm == null) return; 70 | Notification notification = null; 71 | String notificationChannelId = null; 72 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 73 | NotificationChannel notificationChannel = createNotificationChannel(channelId, channelName); 74 | nm.createNotificationChannel(notificationChannel); 75 | notificationChannelId = notificationChannel.getId(); 76 | 77 | } 78 | notification = new NotificationCompat.Builder(context, notificationChannelId) 79 | .setSmallIcon(context.getApplicationInfo().icon) 80 | .setWhen(System.currentTimeMillis()) 81 | .setTicker(Ticker) 82 | .setContentTitle(title) 83 | .setContentText(ContentText) 84 | .setSmallIcon(SmallIcon) 85 | .setContentIntent(pendingIntent) 86 | .setAutoCancel(true) 87 | .build(); 88 | try { 89 | notification = setIconBadgeNumManager.setIconBadgeNum(context, notification, i); 90 | nm.notify(notifyID, notification); 91 | } catch (Exception e) { 92 | if (e.toString().equals("")) 93 | Log.d("SendIconNumUtil", e.toString()); 94 | } 95 | } 96 | 97 | /** 98 | * 设置角标并且带通知栏(不设置通知栏渠道 默认为渠道为:其他) 99 | * 100 | * @param i 角标数字(为0时清空角标) 101 | * @param context 上下文 102 | * @param notifyID 通知id 103 | * @param pendingIntent 跳转事件 104 | * @param title 标题 105 | * @param channelId 通知栏 id 106 | * @param SmallIcon 图标 107 | * @param Ticker 108 | * @param ContentText 通知内容 109 | */ 110 | public static void sendIconNumNotification(int i, Application context, int notifyID, PendingIntent pendingIntent, String title, String channelId, int SmallIcon 111 | , String Ticker, String ContentText) { 112 | 113 | NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 114 | if (nm == null) return; 115 | Notification notification = null; 116 | String notificationChannelId = null; 117 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 118 | NotificationChannel notificationChannel = createNotificationChannel(channelId, ""); 119 | nm.createNotificationChannel(notificationChannel); 120 | notificationChannelId = notificationChannel.getId(); 121 | 122 | } 123 | notification = new NotificationCompat.Builder(context, notificationChannelId) 124 | .setSmallIcon(context.getApplicationInfo().icon) 125 | .setWhen(System.currentTimeMillis()) 126 | .setTicker(Ticker) 127 | .setContentTitle(title) 128 | .setContentText(ContentText) 129 | .setSmallIcon(SmallIcon) 130 | .setContentIntent(pendingIntent) 131 | .setAutoCancel(true) 132 | .build(); 133 | try { 134 | notification = setIconBadgeNumManager.setIconBadgeNum(context, notification, i); 135 | nm.notify(notifyID, notification); 136 | } catch (Exception e) { 137 | if (e.toString().equals("")) 138 | Log.d("SendIconNumUtil", e.toString()); 139 | } 140 | } 141 | 142 | /** 143 | * 使用自定义通知栏 144 | * 145 | * @param i 角标显示数量 146 | * @param context 上下文 147 | * @param notifyID 通知id 148 | * @param notification 自定义通知栏 149 | * @param nm 通知栏管理器 150 | */ 151 | public static void sendIconNumNotification(int i, Application context, int notifyID, Notification notification, NotificationManager nm) { 152 | 153 | try { 154 | notification = setIconBadgeNumManager.setIconBadgeNum(context, notification, i); 155 | nm.notify(notifyID, notification); 156 | } catch (Exception e) { 157 | Log.d("SendIconNumUtil", e.toString()); 158 | } 159 | } 160 | 161 | 162 | @RequiresApi(api = Build.VERSION_CODES.O) 163 | private static NotificationChannel createNotificationChannel(String channelId, String channelName) { 164 | String channelNames = channelName; 165 | NotificationChannel channel = null; 166 | channel = new NotificationChannel(channelId, 167 | (channelNames.equals("") ? "其他" : channelNames), NotificationManager.IMPORTANCE_DEFAULT); 168 | channel.canBypassDnd();//是否绕过勿扰模式 169 | channel.setBypassDnd(true); 170 | channel.enableLights(true); //是否在桌面icon右上角展示小红点 171 | channel.setLightColor(Color.RED); //小红点颜色 172 | channel.setShowBadge(true); //是否在久按桌面图标时显示此渠道的通知 173 | return channel; 174 | } 175 | 176 | 177 | } 178 | -------------------------------------------------------------------------------- /app/src/main/libs/arm64-v8a/libjcore127.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ybzqh/GSAppBadge/0b1f0c47846183f47a1e2c922b71d8439ed4a624/app/src/main/libs/arm64-v8a/libjcore127.so -------------------------------------------------------------------------------- /app/src/main/libs/armeabi-v7a/libjcore127.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ybzqh/GSAppBadge/0b1f0c47846183f47a1e2c922b71d8439ed4a624/app/src/main/libs/armeabi-v7a/libjcore127.so -------------------------------------------------------------------------------- /app/src/main/libs/armeabi/libjcore127.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ybzqh/GSAppBadge/0b1f0c47846183f47a1e2c922b71d8439ed4a624/app/src/main/libs/armeabi/libjcore127.so -------------------------------------------------------------------------------- /app/src/main/libs/jcore-android-1.2.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ybzqh/GSAppBadge/0b1f0c47846183f47a1e2c922b71d8439ed4a624/app/src/main/libs/jcore-android-1.2.7.jar -------------------------------------------------------------------------------- /app/src/main/libs/jpush-android-3.2.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ybzqh/GSAppBadge/0b1f0c47846183f47a1e2c922b71d8439ed4a624/app/src/main/libs/jpush-android-3.2.0.jar -------------------------------------------------------------------------------- /app/src/main/libs/mips/libjcore127.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ybzqh/GSAppBadge/0b1f0c47846183f47a1e2c922b71d8439ed4a624/app/src/main/libs/mips/libjcore127.so -------------------------------------------------------------------------------- /app/src/main/libs/mips64/libjcore127.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ybzqh/GSAppBadge/0b1f0c47846183f47a1e2c922b71d8439ed4a624/app/src/main/libs/mips64/libjcore127.so -------------------------------------------------------------------------------- /app/src/main/libs/x86/libjcore127.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ybzqh/GSAppBadge/0b1f0c47846183f47a1e2c922b71d8439ed4a624/app/src/main/libs/x86/libjcore127.so -------------------------------------------------------------------------------- /app/src/main/libs/x86_64/libjcore127.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ybzqh/GSAppBadge/0b1f0c47846183f47a1e2c922b71d8439ed4a624/app/src/main/libs/x86_64/libjcore127.so -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/jpush_ic_richpush_actionbar_back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ybzqh/GSAppBadge/0b1f0c47846183f47a1e2c922b71d8439ed4a624/app/src/main/res/drawable/jpush_ic_richpush_actionbar_back.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/jpush_ic_richpush_actionbar_divider.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ybzqh/GSAppBadge/0b1f0c47846183f47a1e2c922b71d8439ed4a624/app/src/main/res/drawable/jpush_ic_richpush_actionbar_divider.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/jpush_richpush_btn_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 14 | 15 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/jpush_richpush_progressbar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 |