Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Badge in Android not working React Native #387

Open
solomen5555 opened this issue Mar 20, 2024 · 0 comments
Open

Badge in Android not working React Native #387

solomen5555 opened this issue Mar 20, 2024 · 0 comments

Comments

@solomen5555
Copy link

My code.

package com.linkgroup;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import me.leolin.shortcutbadger.Badger;
import me.leolin.shortcutbadger.ShortcutBadger;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import android.util.Log;

public class BadgeModule extends ReactContextBaseJavaModule {

private final ReactApplicationContext reactContext;
private Boolean applyAutomaticBadger;
private ComponentName componentName;
private static final String LOG_TAG = "BadgeAndroid";

public BadgeModule(ReactApplicationContext reactContext) {
    super(reactContext);
    this.reactContext = reactContext;
}

@Override
public String getName() {
    return "BadgeAndroid";
}

@ReactMethod
public void setBadge(int number) {
     Log.d(LOG_TAG, "setting count: " + number);
     Context context = getReactApplicationContext();
    if (null == componentName) {
        componentName = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()).getComponent();
    }
    ShortcutBadger.applyCount(context, number);
    Log.d(LOG_TAG, "setting count666: " + number);
}

}

Can you give me a solution ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant