Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Commit

Permalink
Android端支持 setApplicationIconBadgeNumber 和 `getApplicationIconBadge…
Browse files Browse the repository at this point in the history
…Number `
  • Loading branch information
Jeepeng committed Jun 13, 2017
1 parent c6f8624 commit 74d1b99
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 16 deletions.
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile "com.facebook.react:react-native:+"
compile "me.leolin:ShortcutBadger:1.1.17@aar"
}
15 changes: 15 additions & 0 deletions android/src/main/java/com/jeepeng/react/xgpush/PushModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import com.facebook.react.bridge.ActivityEventListener;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
Expand All @@ -23,6 +24,8 @@
import com.tencent.android.tpush.XGPushManager;
import com.tencent.android.tpush.encrypt.Rijndael;

import me.leolin.shortcutbadger.ShortcutBadger;

/**
* 信鸽推送
* Created by Jeepeng on 16/8/3.
Expand All @@ -32,6 +35,7 @@ public class PushModule extends ReactContextBaseJavaModule implements ActivityEv
public static final String MODULE_NAME = "XGPushManager";

private Context reactContext;
private int badge = 0;

public PushModule(ReactApplicationContext reactContext) {
super(reactContext);
Expand Down Expand Up @@ -274,6 +278,17 @@ public void getInitialNotification(Promise promise) {
promise.resolve(params);
}

@ReactMethod
public void getApplicationIconBadgeNumber(Callback callback) {
callback.invoke(this.badge);
}

@ReactMethod
public void setApplicationIconBadgeNumber(int number) {
this.badge = number;
ShortcutBadger.applyCount(this.reactContext, number);
}

@Override
public void onHostResume() {
XGPushManager.onActivityStarted(getCurrentActivity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
import com.tencent.android.tpush.XGPushShowedResult;
import com.tencent.android.tpush.XGPushTextMessage;

import org.json.JSONException;
import org.json.JSONObject;

import me.leolin.shortcutbadger.ShortcutBadger;

/**
* 消息接收器
* Created by Jeepeng on 16/8/4.
Expand All @@ -25,13 +30,11 @@ public class MessageReceiver extends XGPushBaseReceiver {
*/
@Override
public void onRegisterResult(Context context, int errorCode, XGPushRegisterResult xgPushRegisterResult) {

if(errorCode == 0) {
Intent intent = new Intent(Constants.ACTION_ON_REGISTERED);
intent.putExtra("token", xgPushRegisterResult.getToken());
context.sendBroadcast(intent);
}

}

/**
Expand Down Expand Up @@ -77,7 +80,7 @@ public void onTextMessage(Context context, XGPushTextMessage xgPushTextMessage)
Intent intent = new Intent(Constants.ACTION_ON_TEXT_MESSAGE);
intent.putExtra("title", xgPushTextMessage.getTitle());
intent.putExtra("content", xgPushTextMessage.getContent());
intent.putExtra("customContent", xgPushTextMessage.getCustomContent());
intent.putExtra("custom_content", xgPushTextMessage.getCustomContent());
context.sendBroadcast(intent);
}

Expand Down Expand Up @@ -120,6 +123,16 @@ public void onNotifactionClickedResult(Context context, XGPushClickedResult noti
*/
@Override
public void onNotifactionShowedResult(Context context, XGPushShowedResult xgPushShowedResult) {
// set app icon badge
try {
JSONObject obj = new JSONObject(xgPushShowedResult.getCustomContent());
int badge = obj.optInt("badge", -1);
if (badge >= 0) {
ShortcutBadger.applyCount(context, badge);
}
} catch (JSONException e) {
e.printStackTrace();
}
Intent intent = new Intent(Constants.ACTION_ON_NOTIFICATION_SHOWED);
Bundle bundle = new Bundle();
bundle.putString("content", xgPushShowedResult.getContent());
Expand Down
8 changes: 4 additions & 4 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
compileSdkVersion 25
buildToolsVersion '25.0.2'

defaultConfig {
applicationId "com.jeepeng.push"
minSdkVersion 16
targetSdkVersion 22
targetSdkVersion 25
versionCode 1
versionName "1.0"
ndk {
Expand Down Expand Up @@ -128,7 +128,7 @@ android {
dependencies {
compile project(':react-native-xinge-push')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.android.support:appcompat-v7:25.3.1"
compile "com.facebook.react:react-native:+" // From node_modules
}

Expand Down
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.android.tools.build:gradle:2.3.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
3 changes: 2 additions & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Tue Jun 13 10:05:14 CST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
1 change: 0 additions & 1 deletion example/ios/example/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
// 统计从推送打开的设备
NSLog(@"%@",launchOptions);
[XGPushManager handleLaunching:launchOptions successCallback:^{
NSLog(@"[XGPush] Handle launching success");
} errorCallback:^{
Expand Down
8 changes: 2 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,11 @@ class XGPush {
}

static setApplicationIconBadgeNumber(number) {
if (Platform.OS === 'ios') {
XGPushManager.setApplicationIconBadgeNumber(number);
}
XGPushManager.setApplicationIconBadgeNumber(number);
}

static getApplicationIconBadgeNumber(callback) {
if (Platform.OS === 'ios') {
XGPushManager.getApplicationIconBadgeNumber(callback);
}
XGPushManager.getApplicationIconBadgeNumber(callback);
}

static checkPermissions(callback) {
Expand Down

0 comments on commit 74d1b99

Please sign in to comment.