Android Question Badge counter

bixmatech

Member
Licensed User
Hi....
I'm trying to use Badge counter in my app (show number above the application icon), But I've a problem with Sony Z Ultra ...

In Samsung devices I used this code ( work perfectly):

B4X:
  Try
        Dim cv As ContentValues
        cv.Initialize
        cv.PutString("package", Application.PackageName)
        cv.PutString("class", Application.PackageName & ".main")
        cv.PutInteger("badgecount", count)
        Dim u As Uri
        u.Parse("content://com.sec.badge/apps")
        cr.Insert(u, cv)
    Catch
    End Try


For Sony I tried this code : (actually I tried to convert it to B4A but without success)
https://stackoverflow.com/questions...nt-to-application-icon-on-sony-xperia-devices

Test 1 :
B4X:
Dim intent As Intent
    Try
        Dim u As Uri
        u.Parse("content://com.sec.badge/apps")

        intent.Initialize("com.sonyericsson.home.action.UPDATE_BADGE","")
        'intent.Initialize(intent.ACTION_APPWIDGET_UPDATE,"") (test it too)
       
        intent.Action = "com.sonyericsson.home.action.UPDATE_BADGE"
        intent.putExtra("com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME", Application.PackageName & ".MainActivity")
        intent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE", True)
        intent.putExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE", "11")
        intent.putExtra("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME", Application.PackageName)
       
        StartActivity(intent)
       
        'Dim jo As JavaObject
        'jo.InitializeContext
        'jo.RunMethod("sendBroadcast", Array(intent))  (test it too)
    Catch
       
    End Try


Test 2 :
B4X:
Try
        Dim cv As ContentValues
        cv.Initialize
       
        cv.PutString ("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME" , Application.PackageName)
        cv.PutString ("com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME", Application.PackageName & ".MainActivity")
        cv.PutString("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE" , True)
        cv.PutString("com.sonyericsson.home.intent.extra.badge.MESSAGE", "10")
       
        Dim u As Uri
        u.Parse("content://com.sec.badge/apps")
        cr.Insert(u, cv)
    Catch
    End Try


Permissions :

AddPermission("com.sec.android.provider.badge.permission.READ")
AddPermission("com.sec.android.provider.badge.permission.WRITE")
AddPermission("com.sonyericsson.home.permission.BROADCAST_BADGE")
AddPermission("com.sonyericsson.home.permission.RECEIVE_BADGE")


But did not succeed .

So Where is wrong ?

Thank you .
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

bixmatech

Member
Licensed User
Tried the example , but this error i've got :

LogCat connected to: EP7327KHDW
--------- beginning of crash
--------- beginning of system
--------- beginning of main
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
java.lang.SecurityException: Missing permission to insert badges
at android.os.Parcel.readException(Parcel.java:1547)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
at android.content.ContentProviderProxy.insert(ContentProviderNative.java:475)
at android.content.ContentResolver.insert(ContentResolver.java:1213)
at android.content.AsyncQueryHandler$WorkerHandler.handleMessage(AsyncQueryHandler.java:96)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:211)
at android.os.HandlerThread.run(HandlerThread.java:61)
** Activity (main) Pause, UserClosed = true **
 
Upvote 0

bixmatech

Member
Licensed User
See the thread in the link... You need to add the persmission needed for your device

I tried to add just the Sony Permission :

AddPermission(com.sonyericsson.home.permission.BROADCAST_BADGE)

and tried to add all Permissions:
AddPermission(com.sec.android.provider.badge.permission.READ)
AddPermission(com.sec.android.provider.badge.permission.WRITE)
AddPermission(com.htc.launcher.permission.READ_SETTINGS)
AddPermission(com.htc.launcher.permission.UPDATE_SHORTCUT)
AddPermission(com.sonyericsson.home.permission.BROADCAST_BADGE)
AddPermission(com.anddoes.launcher.permission.UPDATE_COUNT)
AddPermission(com.majeur.launcher.permission.UPDATE_BADGE)

but I've got error :
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
java.lang.SecurityException: Missing permission to insert badges
at android.os.Parcel.readException(Parcel.java:1547)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
at android.content.ContentProviderProxy.insert(ContentProviderNative.java:475)
at android.content.ContentResolver.insert(ContentResolver.java:1213)
at android.content.AsyncQueryHandler$WorkerHandler.handleMessage(AsyncQueryHandler.java:96)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:211)
at android.os.HandlerThread.run(HandlerThread.java:61)
** Activity (main) Pause, UserClosed = true **



Missing permission , is there another permission ?


Thank you ....
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Based on stackoverflow you need to add the permission in another way

Remove the AddPermission lines from manifest.

Try to add
AddApplicationText(<!-- START: ShortcutBadger -->
<!-- Samsung -->
<uses-permission android:name="com.sec.android.provider.badge.permission.READ"/>
<uses-permission android:name="com.sec.android.provider.badge.permission.WRITE"/>

<!-- HTC -->
<uses-permission android:name="com.htc.launcher.permission.READ_SETTINGS"/>
<uses-permission android:name="com.htc.launcher.permission.UPDATE_SHORTCUT"/>

<!-- Sony -->
<uses-permission android:name="com.sonyericsson.home.permission.BROADCAST_BADGE"/>
<uses-permission android:name="com.sonymobile.home.permission.PROVIDER_INSERT_BADGE"/>

<!-- Apex -->
<uses-permission android:name="com.anddoes.launcher.permission.UPDATE_COUNT"/>

<!-- Solid -->
<uses-permission android:name="com.majeur.launcher.permission.UPDATE_BADGE"/>

<!-- Huawei -->
<uses-permission android:name="com.huawei.android.launcher.permission.CHANGE_BADGE" />
<uses-permission android:name="com.huawei.android.launcher.permission.READ_SETTINGS" />
<uses-permission android:name="com.huawei.android.launcher.permission.WRITE_SETTINGS" />
<!-- End: ShortcutBadger -->)
to the manifest. Run the project again
 
Upvote 0

bixmatech

Member
Licensed User
Based on stackoverflow you need to add the permission in another way

Remove the AddPermission lines from manifest.

Try to add

to the manifest. Run the project again


Thank you DonManfred And Sorry for delay in reply, But I was working on another project. :)
Anyway.
I tried to remove "AddPermission " and add the new lines ..
but I've got this error ::(
B4X:
java.lang.SecurityException: Missing permission to insert badges
    at android.os.Parcel.readException(Parcel.java:1547)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
    at android.content.ContentProviderProxy.insert(ContentProviderNative.java:475)
    at android.content.ContentResolver.insert(ContentResolver.java:1213)
    at android.content.AsyncQueryHandler$WorkerHandler.handleMessage(AsyncQueryHandler.java:96)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:211)
    at android.os.HandlerThread.run(HandlerThread.java:61)

This the full code in the Manifest:
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="19"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>
    )
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.

'AddPermission(com.sec.android.provider.badge.permission.READ)
'AddPermission(com.sec.android.provider.badge.permission.WRITE)

AddApplicationText(<!-- START: ShortcutBadger -->
<!-- Samsung -->
<uses-permission android:name="com.sec.android.provider.badge.permission.READ"/>
<uses-permission android:name="com.sec.android.provider.badge.permission.WRITE"/>

<!-- HTC -->
<uses-permission android:name="com.htc.launcher.permission.READ_SETTINGS"/>
<uses-permission android:name="com.htc.launcher.permission.UPDATE_SHORTCUT"/>

<!-- Sony -->
<uses-permission android:name="com.sonyericsson.home.permission.BROADCAST_BADGE"/>
<uses-permission android:name="com.sonymobile.home.permission.PROVIDER_INSERT_BADGE"/>

<!-- Apex -->
<uses-permission android:name="com.anddoes.launcher.permission.UPDATE_COUNT"/>

<!-- Solid -->
<uses-permission android:name="com.majeur.launcher.permission.UPDATE_BADGE"/>

<!-- Huawei -->
<uses-permission android:name="com.huawei.android.launcher.permission.CHANGE_BADGE" />
<uses-permission android:name="com.huawei.android.launcher.permission.READ_SETTINGS" />
<uses-permission android:name="com.huawei.android.launcher.permission.WRITE_SETTINGS" />
<!-- End: ShortcutBadger -->)

Thank you again ...:D
 
Upvote 0
Top