Repository: leolin310148/ShortcutBadger Branch: master Commit: 6d4ce808b0a1 Files: 48 Total size: 91.1 KB Directory structure: gitextract_akhmgbpy/ ├── .gitignore ├── LICENSE ├── README.md ├── SampleApp/ │ ├── .gitignore │ ├── build.gradle │ └── src/ │ ├── androidTest/ │ │ └── java/ │ │ └── me/ │ │ └── leolin/ │ │ └── shortcutbadger/ │ │ └── example/ │ │ └── ApplicationTest.java │ └── main/ │ ├── AndroidManifest.xml │ ├── java/ │ │ └── me/ │ │ └── leolin/ │ │ └── shortcutbadger/ │ │ └── example/ │ │ ├── BadgeIntentService.java │ │ └── MainActivity.java │ └── res/ │ ├── layout/ │ │ └── activity_main.xml │ ├── values/ │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── values-w820dp/ │ └── dimens.xml ├── ShortcutBadger/ │ ├── .gitignore │ ├── build.gradle │ ├── mvn-push.gradle │ ├── proguard-rules.pro │ └── src/ │ └── main/ │ ├── AndroidManifest.xml │ └── java/ │ └── me/ │ └── leolin/ │ └── shortcutbadger/ │ ├── Badger.java │ ├── ShortcutBadgeException.java │ ├── ShortcutBadger.java │ ├── impl/ │ │ ├── AdwHomeBadger.java │ │ ├── ApexHomeBadger.java │ │ ├── AsusHomeBadger.java │ │ ├── DefaultBadger.java │ │ ├── EverythingMeHomeBadger.java │ │ ├── HuaweiHomeBadger.java │ │ ├── IntentConstants.java │ │ ├── LGHomeBadger.java │ │ ├── NewHtcHomeBadger.java │ │ ├── NovaHomeBadger.java │ │ ├── OPPOHomeBader.java │ │ ├── SamsungHomeBadger.java │ │ ├── SonyHomeBadger.java │ │ ├── VivoHomeBadger.java │ │ ├── XiaomiHomeBadger.java │ │ ├── YandexLauncherBadger.java │ │ ├── ZTEHomeBadger.java │ │ └── ZukHomeBadger.java │ └── util/ │ ├── BroadcastHelper.java │ └── CloseHelper.java ├── build.gradle ├── gradle/ │ └── wrapper/ │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ .idea/* *.iml build .gradle local.properties **/gradle.properties ================================================ FILE: LICENSE ================================================ Copyright 2014 Leo Lin Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================ FILE: README.md ================================================ ShortcutBadger: [![Maven Central](https://maven-badges.herokuapp.com/maven-central/me.leolin/ShortcutBadger/badge.svg)](https://maven-badges.herokuapp.com/maven-central/me.leolin/ShortcutBadger) =================================== The ShortcutBadger makes your Android App show the count of unread messages as a badge on your App shortcut! # Supported launchers:

Sony


Samsung


LG


HTC


Xiaomi



ASUS


ADW


APEX


NOVA


Huawei


(Not Fully Support)

(1.1.7+)

ZUK



(1.1.10+)

OPPO


(Not Fully Support)

(1.1.10+)

EverythingMe


ZTE



(1.1.17+)

KISS



(1.1.18+)

LaunchTime


Yandex Launcher



(1.1.23+)
* Nova launcher with TeslaUnread, Apex launcher, ADW Launcher provided by [notz](https://github.com/notz) * Solid launcher provided by [MajeurAndroid](https://github.com/MajeurAndroid) * KISS Launcher provided by [alexander255](https://github.com/alexander255) ## About Xiaomi devices Xiaomi devices require extra setup with notifications, please read [wiki](https://github.com/leolin310148/ShortcutBadger/wiki/Xiaomi-Device-Support). ## IsBadgeWorking? A tool for displaying your device, launcher & android version and testing whether ShortcutBadger works or not may be downloaded from * Google Play [https://play.google.com/store/apps/details?id=me.leolin.isbadgeworking](https://play.google.com/store/apps/details?id=me.leolin.isbadgeworking) * The GitHub repository [https://github.com/leolin310148/IsBadgeWorking.Android/releases](https://github.com/leolin310148/IsBadgeWorking.Android/releases) USAGE ===================================
1. Add mavenCentral to your build script. repositories { mavenCentral() }
2. Add dependencies for ShortcutBadger, it's available from maven now. dependencies { implementation "me.leolin:ShortcutBadger:1.1.22@aar" }
3. Add the codes below: int badgeCount = 1; ShortcutBadger.applyCount(context, badgeCount); //for 1.1.4+ ShortcutBadger.with(getApplicationContext()).count(badgeCount); //for 1.1.3
4. If you want to remove the badge ShortcutBadger.removeCount(context); //for 1.1.4+ ShortcutBadger.with(getApplicationContext()).remove(); //for 1.1.3 or ShortcutBadger.applyCount(context, 0); //for 1.1.4+ ShortcutBadger.with(getApplicationContext()).count(0); //for 1.1.3



DEVELOP BY =================================== [Leo Lin](https://github.com/leolin310148) - leolin310148@gmail.com ABOUT Google Play Developer Term Violations =================================== If you receive a message from Google containing something like this:
REASON FOR WARNING: Violation of section 4.4 of the Developer Distribution Agreement. please use version 1.1.0+! CHANGE LOG ========== 1.1.23: * Added Yandex Launcher support. Fixed issue with incorrect default launcher resolve 1.1.22: * Improve Oreo support (Thanks to [AlexStarc](https://github.com/AlexStarc)) 1.1.20: * Renamed default broadcast action; added Android Oreo support. 1.1.19: * Fix multiple home package resolve issue. 1.1.18: * Add Kill Launcher Support 1.1.17: * Add ZTE Support 1.1.16: * Improve Sony Launcher support. 1.1.15: * Add EverythingLauncher Support. 1.1.14: * Fix for specific class of Samsung devices: with android 5, but without support of DefaultBadger * Remove Xiaomi from Badger and add Notification Support for Xiaomi devices. 1.1.13: * Fix XiaomiBadger (tested with RedMi Note4) 1.1.12: * Handling Samsung badger for old devices and new devices. * Try to support newer Xiaomi (Not tested.) * Try to support Vivo (Not tested.) 1.1.11: * Add OPPO Launcher Support 1.1.10: * Add ZUK Launcher Support 1.1.9: * Add SamsungBadger back for more Samsung devices support. 1.1.8: * Remove SolidBadger, now solid launcher will use default badger. 1.1.7: * Add Huawei launcher support. 1.1.6: * Add support for new Sony Launchers. 1.1.5: * `applyCount` will return if the Broadcast has been sent successfully. 1.1.4: * Changed `ShortcutBadger.setBadge(context, badgeCount)` to `ShortcutBadger.applyCount(context, badgeCount);` 1.1.3: * Deprecate SamsungBadger and LGBadger, those devices can use DefaultBadger. 1.1.2: * Add support for `com.miui.mihome2` 1.1.1: * Add DefaultBadger because some launchers use android.intent.action.BADGE_COUNT_UPDATE to update count. * Since the ShortcutBadgerException is helpless. So change api to set badge and never have to handle the exception again. 1.1.0: * Remove Android Launcher support due to Google Play Developer Term Violation since 4.4. 1.0.10: * Add Asus launcher support. 1.0.9: * Add Xiaomi launcher support. LICENSE ===================================
Copyright 2014 Leo Lin Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
================================================ FILE: SampleApp/.gitignore ================================================ /build ================================================ FILE: SampleApp/build.gradle ================================================ apply plugin: 'com.android.application' android { compileSdkVersion 27 buildToolsVersion '27.0.3' defaultConfig { applicationId "me.leolin.shortcutbadger.example" minSdkVersion 16 targetSdkVersion 27 versionCode 1 versionName "1.0" } lintOptions { abortOnError false } } dependencies { // implementation 'me.leolin:ShortcutBadger:1.0.+@aar' implementation project(':ShortcutBadger') } ================================================ FILE: SampleApp/src/androidTest/java/me/leolin/shortcutbadger/example/ApplicationTest.java ================================================ package me.leolin.shortcutbadger.example; import android.app.Application; import android.test.ApplicationTestCase; /** * Testing Fundamentals */ public class ApplicationTest extends ApplicationTestCase { public ApplicationTest() { super(Application.class); } } ================================================ FILE: SampleApp/src/main/AndroidManifest.xml ================================================ ================================================ FILE: SampleApp/src/main/java/me/leolin/shortcutbadger/example/BadgeIntentService.java ================================================ package me.leolin.shortcutbadger.example; import android.annotation.TargetApi; import android.app.IntentService; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; import android.content.Intent; import android.os.Build; import me.leolin.shortcutbadger.ShortcutBadger; public class BadgeIntentService extends IntentService { private static final String NOTIFICATION_CHANNEL = "me.leolin.shortcutbadger.example"; private int notificationId = 0; public BadgeIntentService() { super("BadgeIntentService"); } private NotificationManager mNotificationManager; @Override public void onCreate() { super.onCreate(); mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); } @Override public void onStart(Intent intent, int startId) { super.onStart(intent, startId); } @Override protected void onHandleIntent(Intent intent) { if (intent != null) { int badgeCount = intent.getIntExtra("badgeCount", 0); mNotificationManager.cancel(notificationId); notificationId++; Notification.Builder builder = new Notification.Builder(getApplicationContext()) .setContentTitle("") .setContentText("") .setSmallIcon(R.drawable.ic_launcher); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { setupNotificationChannel(); builder.setChannelId(NOTIFICATION_CHANNEL); } Notification notification = builder.build(); ShortcutBadger.applyNotification(getApplicationContext(), notification, badgeCount); mNotificationManager.notify(notificationId, notification); } } @TargetApi(Build.VERSION_CODES.O) private void setupNotificationChannel() { NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL, "ShortcutBadger Sample", NotificationManager.IMPORTANCE_DEFAULT); mNotificationManager.createNotificationChannel(channel); } } ================================================ FILE: SampleApp/src/main/java/me/leolin/shortcutbadger/example/MainActivity.java ================================================ package me.leolin.shortcutbadger.example; import android.app.Activity; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import me.leolin.shortcutbadger.ShortcutBadger; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final EditText numInput = findViewById(R.id.numInput); Button button = findViewById(R.id.btnSetBadge); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int badgeCount = 0; try { badgeCount = Integer.parseInt(numInput.getText().toString()); } catch (NumberFormatException e) { Toast.makeText(getApplicationContext(), "Error input", Toast.LENGTH_SHORT).show(); } boolean success = ShortcutBadger.applyCount(MainActivity.this, badgeCount); Toast.makeText(getApplicationContext(), "Set count=" + badgeCount + ", success=" + success, Toast.LENGTH_SHORT).show(); } }); Button launchNotification = findViewById(R.id.btnSetBadgeByNotification); launchNotification.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int badgeCount = 0; try { badgeCount = Integer.parseInt(numInput.getText().toString()); } catch (NumberFormatException e) { Toast.makeText(getApplicationContext(), "Error input", Toast.LENGTH_SHORT).show(); } finish(); startService( new Intent(MainActivity.this, BadgeIntentService.class).putExtra("badgeCount", badgeCount) ); } }); Button removeBadgeBtn = findViewById(R.id.btnRemoveBadge); removeBadgeBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { boolean success = ShortcutBadger.removeCount(MainActivity.this); Toast.makeText(getApplicationContext(), "success=" + success, Toast.LENGTH_SHORT).show(); } }); //find the home launcher Package Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); String currentHomePackage = "none"; ResolveInfo resolveInfo = getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); // in case of duplicate apps (Xiaomi), calling resolveActivity from one will return null if (resolveInfo != null) { currentHomePackage = resolveInfo.activityInfo.packageName; } TextView textViewHomePackage = findViewById(R.id.textViewHomePackage); textViewHomePackage.setText("launcher:" + currentHomePackage); } } ================================================ FILE: SampleApp/src/main/res/layout/activity_main.xml ================================================