Skip to content

Commit

Permalink
Merge pull request #74 from raoxudong/dev
Browse files Browse the repository at this point in the history
v0.2.0
  • Loading branch information
raoxudong authored Sep 25, 2019
2 parents 507e876 + 49acf24 commit 01b5f7c
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .packages
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by pub on 2019-08-23 15:35:48.440553.
# Generated by pub on 2019-09-25 15:21:45.301321.
analyzer:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/analyzer-0.37.0/lib/
args:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/args-1.5.2/lib/
async:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/async-2.3.0/lib/
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.2.0
+ 适配最新版本 JPush SDK
+ Android 支持设置角标 badge
## 0.1.0
+ 修复:调用 sendLocalNotification 接口 crash 问题;
+ 修复:iOS 启动 APP 角标自动消失问题;
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@

```yaml
dependencies:
jpush_flutter: 0.1.0
jpush_flutter: 0.2.0

//github
dependencies:
jmessage_flutter:
git:
url: git://github.com/jpush/jmessage-flutter-plugin.git
ref: master
```
### 配置
Expand Down
1 change: 1 addition & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@
</intent-filter>
</service>
</application>
<uses-permission android:name="com.huawei.android.launcher.permission.CHANGE_BADGE "/>
</manifest>
64 changes: 63 additions & 1 deletion android/src/main/java/com/jiguang/jpush/JPushPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public static void registerWith(Registrar registrar) {

}

private static String TAG = "| JPUSH | Android | ";
public static JPushPlugin instance;
static List<Map<String, Object>> openNotificationCache = new ArrayList<>();

Expand Down Expand Up @@ -60,6 +61,7 @@ private JPushPlugin(Registrar registrar, MethodChannel channel) {

@Override
public void onMethodCall(MethodCall call, Result result) {
Log.i(TAG,call.method);
if (call.method.equals("getPlatformVersion")) {
result.success("Android " + android.os.Build.VERSION.RELEASE);
} else if (call.method.equals("setup")) {
Expand Down Expand Up @@ -90,12 +92,17 @@ public void onMethodCall(MethodCall call, Result result) {
getRegistrationID(call, result);
} else if (call.method.equals("sendLocalNotification")) {
sendLocalNotification(call, result);
} else {
} else if (call.method.equals("setBadge")) {
setBadge(call, result);
}
else {
result.notImplemented();
}
}

public void setup(MethodCall call, Result result) {
Log.d(TAG,"setup :" + call.arguments);

HashMap<String, Object> map = call.arguments();
boolean debug = (boolean)map.get("debug");
JPushInterface.setDebugMode(debug);
Expand All @@ -112,6 +119,8 @@ public void setup(MethodCall call, Result result) {
}

public void scheduleCache() {
Log.d(TAG,"scheduleCache:");

if (dartIsReady) {
// try to shedule notifcation cache
for (Map<String, Object> notification: JPushPlugin.openNotificationCache) {
Expand All @@ -131,6 +140,8 @@ public void scheduleCache() {
}

public void setTags(MethodCall call, Result result) {
Log.d(TAG,"setTags:");

List<String>tagList = call.arguments();
Set<String> tags = new HashSet<>(tagList);
sequence += 1;
Expand All @@ -139,12 +150,16 @@ public void setTags(MethodCall call, Result result) {
}

public void cleanTags(MethodCall call, Result result) {
Log.d(TAG,"cleanTags:");

sequence += 1;
callbackMap.put(sequence, result);
JPushInterface.cleanTags(registrar.context(), sequence);
}

public void addTags(MethodCall call, Result result) {
Log.d(TAG,"addTags: " + call.arguments);

List<String>tagList = call.arguments();
Set<String> tags = new HashSet<>(tagList);
sequence += 1;
Expand All @@ -153,6 +168,8 @@ public void addTags(MethodCall call, Result result) {
}

public void deleteTags(MethodCall call, Result result) {
Log.d(TAG,"deleteTags: " + call.arguments);

List<String>tagList = call.arguments();
Set<String> tags = new HashSet<>(tagList);
sequence += 1;
Expand All @@ -161,42 +178,57 @@ public void deleteTags(MethodCall call, Result result) {
}

public void getAllTags(MethodCall call, Result result) {
Log.d(TAG,"getAllTags: ");

sequence += 1;
callbackMap.put(sequence, result);
JPushInterface.getAllTags(registrar.context(), sequence);
}

public void setAlias(MethodCall call, Result result) {
Log.d(TAG,"setAlias: " + call.arguments);

String alias= call.arguments();
sequence += 1;
callbackMap.put(sequence, result);
JPushInterface.setAlias(registrar.context(), sequence, alias);
}

public void deleteAlias(MethodCall call, Result result) {
Log.d(TAG,"deleteAlias:");

String alias= call.arguments();
sequence += 1;
callbackMap.put(sequence, result);
JPushInterface.deleteAlias(registrar.context(), sequence);
}

public void stopPush(MethodCall call, Result result) {
Log.d(TAG,"stopPush:");

JPushInterface.stopPush(registrar.context());
}

public void resumePush(MethodCall call, Result result) {
Log.d(TAG,"resumePush:");

JPushInterface.resumePush(registrar.context());
}

public void clearAllNotifications(MethodCall call, Result result) {
Log.d(TAG,"clearAllNotifications: ");

JPushInterface.clearAllNotifications(registrar.context());
}

public void getLaunchAppNotification(MethodCall call, Result result) {
Log.d(TAG,"");


}

public void getRegistrationID(MethodCall call, Result result) {
Log.d(TAG,"getRegistrationID: ");

String rid = JPushInterface.getRegistrationID(registrar.context());
if (rid == null || rid.isEmpty()) {
Expand All @@ -208,6 +240,8 @@ public void getRegistrationID(MethodCall call, Result result) {


public void sendLocalNotification(MethodCall call, Result result) {
Log.d(TAG,"sendLocalNotification: " + call.arguments);

try {
HashMap<String, Object> map = call.arguments();

Expand All @@ -232,6 +266,17 @@ public void sendLocalNotification(MethodCall call, Result result) {
}
}

public void setBadge(MethodCall call, Result result) {
Log.d(TAG,"setBadge: " + call.arguments);

HashMap<String, Object> map = call.arguments();
Object numObject = map.get("badge");
if (numObject != null) {
int num = (int)numObject;
JPushInterface.setBadgeNumber(registrar.context(),num);
result.success(true);
}
}

/**
* 接收自定义消息,通知,通知点击事件等事件的广播
Expand All @@ -248,6 +293,7 @@ public JPushReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();

if (action.equals(JPushInterface.ACTION_REGISTRATION_ID)) {
String rId = intent.getStringExtra(JPushInterface.EXTRA_REGISTRATION_ID);
Log.d("JPushPlugin","on get registration");
Expand All @@ -264,12 +310,16 @@ public void onReceive(Context context, Intent intent) {
}

private void handlingMessageReceive(Intent intent) {
Log.d(TAG,"handlingMessageReceive " + intent.getAction());

String msg = intent.getStringExtra(JPushInterface.EXTRA_MESSAGE);
Map<String, Object> extras = getNotificationExtras(intent);
JPushPlugin.transmitMessageReceive(msg, extras);
}

private void handlingNotificationOpen(Context context, Intent intent) {
Log.d(TAG,"handlingNotificationOpen " + intent.getAction());

String title = intent.getStringExtra(JPushInterface.EXTRA_NOTIFICATION_TITLE);
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
Map<String, Object> extras = getNotificationExtras(intent);
Expand All @@ -284,13 +334,17 @@ private void handlingNotificationOpen(Context context, Intent intent) {
}

private void handlingNotificationReceive(Context context, Intent intent) {
Log.d(TAG,"handlingNotificationReceive " + intent.getAction());

String title = intent.getStringExtra(JPushInterface.EXTRA_NOTIFICATION_TITLE);
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
Map<String, Object> extras = getNotificationExtras(intent);
JPushPlugin.transmitNotificationReceive(title, alert, extras);
}

private Map<String, Object> getNotificationExtras(Intent intent) {
Log.d(TAG,"");

Map<String, Object> extrasMap = new HashMap<String, Object>();
for (String key : intent.getExtras().keySet()) {
if (!IGNORED_EXTRAS_KEYS.contains(key)) {
Expand All @@ -307,6 +361,8 @@ private Map<String, Object> getNotificationExtras(Intent intent) {


static void transmitMessageReceive(String message, Map<String, Object> extras) {
Log.d(TAG,"transmitMessageReceive " + "message=" + message + "extras=" + extras);

if (instance == null) {
return;
}
Expand All @@ -318,6 +374,8 @@ static void transmitMessageReceive(String message, Map<String, Object> extras) {
}

static void transmitNotificationOpen(String title, String alert, Map<String, Object> extras) {
Log.d(TAG,"transmitNotificationOpen " + "title=" + title + "alert=" + alert + "extras=" + extras);

Map<String, Object> notification= new HashMap<>();
notification.put("title", title);
notification.put("alert", alert);
Expand All @@ -338,6 +396,8 @@ static void transmitNotificationOpen(String title, String alert, Map<String, Obj
}

static void transmitNotificationReceive(String title, String alert, Map<String, Object> extras) {
Log.d(TAG,"transmitNotificationReceive " + "title=" + title + "alert=" + alert + "extras=" + extras);

if (instance == null) {
return;
}
Expand All @@ -350,6 +410,8 @@ static void transmitNotificationReceive(String title, String alert, Map<String,
}

static void transmitReceiveRegistrationId(String rId) {
Log.d(TAG,"transmitReceiveRegistrationId: " + rId);

if (instance == null) {
return;
}
Expand Down
Loading

0 comments on commit 01b5f7c

Please sign in to comment.