Skip to content

Commit d2c6231

Browse files
committed
openurl in jpush & mipush
1 parent 50a34e6 commit d2c6231

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

android/src/main/java/me/youchai/rnpush/jpush/JPushReceiver.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
import me.youchai.rnpush.RNPushModule;
1414
import me.youchai.rnpush.utils.Logger;
1515

16+
import org.json.JSONObject;
17+
import android.net.Uri;
18+
1619

1720
/**
1821
* 接收自定义消息,通知,通知点击事件等事件的广播
@@ -53,12 +56,20 @@ public void onReceive(Context context, Intent data) {
5356
String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
5457
Logger.d("notification click " + title);
5558

56-
// start MainActivity
5759
Intent intent = new Intent();
58-
intent.setClassName(context.getPackageName(), context.getPackageName() + ".MainActivity");
59-
intent.putExtras(bundle);
60-
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
61-
context.startActivity(intent);
60+
JSONObject jExtra = new JSONObject(extras);
61+
if (jExtra.has("openUrl") && !jExtra.isNull("openUrl")) {
62+
String url = jExtra.getString("openUrl");
63+
Logger.i("openning url: " + url);
64+
intent.setAction(Intent.ACTION_VIEW);
65+
intent.setData(Uri.parse(url));
66+
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
67+
context.startActivity(intent);
68+
} else {
69+
intent.setClassName(context.getPackageName(), context.getPackageName() + ".MainActivity");
70+
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
71+
context.startActivity(intent);
72+
}
6273

6374
RNPushModule.onNotificationClick(new Notification(
6475
id, title, content, extras

android/src/main/java/me/youchai/rnpush/mipush/MiPushReceiver.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.facebook.react.bridge.WritableMap;
1919

2020
import org.json.JSONObject;
21+
import android.net.Uri;
2122

2223
import me.youchai.rnpush.Notification;
2324
import me.youchai.rnpush.RNPushModule;
@@ -44,13 +45,26 @@ public void onNotificationMessageClicked(Context context, MiPushMessage message)
4445
String content = message.getDescription();
4546
Map<String, String> extrasMap = message.getExtra();
4647
String extras = new JSONObject(extrasMap).toString();
47-
Logger.i(message.toString());
4848

49-
// start MainActivity
5049
Intent intent = new Intent();
51-
intent.setClassName(context.getPackageName(), context.getPackageName() + ".MainActivity");
52-
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
53-
context.startActivity(intent);
50+
try {
51+
JSONObject jExtra = new JSONObject(extras);
52+
if (jExtra.has("openUrl") && !jExtra.isNull("openUrl")) {
53+
String url = jExtra.getString("openUrl");
54+
Logger.i("openning url: " + url);
55+
intent.setAction(Intent.ACTION_VIEW);
56+
intent.setData(Uri.parse(url));
57+
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
58+
context.startActivity(intent);
59+
} else {
60+
intent.setClassName(context.getPackageName(), context.getPackageName() + ".MainActivity");
61+
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
62+
context.startActivity(intent);
63+
}
64+
} catch (Exception e) {
65+
e.printStackTrace();
66+
Logger.i("error when click on notification");
67+
}
5468

5569
RNPushModule.onNotificationClick(new Notification(
5670
id, title, content, extras

0 commit comments

Comments
 (0)