https://github.com/zoff99/unreadwidget
Widget for any Android App to show unread count
https://github.com/zoff99/unreadwidget
Last synced: 8 months ago
JSON representation
Widget for any Android App to show unread count
- Host: GitHub
- URL: https://github.com/zoff99/unreadwidget
- Owner: zoff99
- Created: 2016-09-02T09:08:59.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-09-02T12:26:12.000Z (over 9 years ago)
- Last Synced: 2025-06-16T22:41:38.817Z (12 months ago)
- Language: Java
- Size: 118 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# UnreadWidget
Widget for any Android App to show unread count
## Adding to your Project:
Just drop all the files into your Project.
## Example Widget

Normal App Icon on the left // UnreadWidget on the right
## CustomWidgetProvider.java
configure these 3 values to your needs:
```java
public static final int MAX_COUNT = 20;
public static Class ToOpenActivity = org.example.myapp.WantToStartThisActivity.class;
public static String baseClass = "org.example.myapp";
```
if more than MAX_COUNT unread count, then MAX_COUNT"+" will be displayed
ToOpenActivity specifies the Activity that you want to open, when the Widget is clicked
baseClass is the Base Class of your Project
## Resources
you will need to already have these resources in your Project:
*@drawable/icon*
this should be your App's Homescreen Icon
*@string/app_name*
this should be the String that shows under your App's Homescreen Icon
## AndroidManifest.xml
add these lines to your AndroidManifest.xml (inside the application tag):
<!-- unread badge widget -->
<!-- unread badge widget -->
<receiver android:name="com.zoffcc.applications.CustomWidgetProvider"
android:icon="@drawable/icon"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/badge_widget_provider"/>
</receiver>
<receiver
android:name="com.zoffcc.applications.BadgeWidgetIntentReceiver"
android:label="widgetBroadcastReceiver">
<intent-filter>
<action android:name="org.example.myapp.CHANGE_BADGE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/badge_widget_provider" />
</receiver>
<!-- unread badge widget -->
<!-- unread badge widget -->
and replace
*org.example.myapp*
with the Base Class of your Project
## Update the Widget in your App
in your Project add:
```java
import com.zoffcc.applications.CustomWidgetProvider;
.
.
.
.
try
{
// ---- update the widget if present ----
final Intent intent2 = new Intent();
intent2.setAction(CustomWidgetProvider.baseClass + ".CHANGE_BADGE");
intent2.putExtra("UNREAD_COUNT_NEW", enter_your_unread_count_here_as_integer);
context.getApplicationContext().sendBroadcast(intent2);
// ---- update the widget if present ----
}
catch (Exception e)
{
}
catch (Throwable t)
{
}
.
.
.
```
**enter_your_unread_count_here_as_integer** is the number you want displayed over your Widget.
if you want to hide the Count, just give 0 as **enter_your_unread_count_here_as_integer**