-
Notifications
You must be signed in to change notification settings - Fork 5
Feat/update jpush #9
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
Changes from all commits
3cd3bd8
7d95852
d3e465b
b833fe9
a218bf4
006b0c5
1b3c479
703e4d8
34b8198
8bfe4e6
927f068
d094cf9
99fcc32
00af791
5cc4a9e
5a743dc
3c3235d
bfa70ea
6110895
89ed69d
462a1b4
3498c6a
d44d379
05b0228
5feb793
9738417
c085c9f
399d6a6
165e11e
db35edd
8fa1908
5a49236
ee35cb9
23154c9
16d4ab9
f6fba6e
488cb13
fbb68bc
1a95b32
aea8e8a
cb1aa1e
bf4590f
ac83f6b
84f5f63
f22de5e
cfcdd51
66fd0ce
b12deec
6caa607
b7ecc60
83b3e34
77963bb
387c14b
e819315
7df3067
b394de8
ebb2996
689f6b0
9d43325
fddbb5a
4f64d47
316e442
4c24ab0
9f4be94
133ef7f
482c9f7
54f08c2
ec29ce7
0a3f279
4ccc1c7
c1d9c30
68ae328
9273903
ef98578
9a32604
5d71b6a
355ac46
cd5ff64
36a8f77
7f6318f
cd028ed
cf0bc28
47c8764
7f518ab
89c54ad
c9862a3
e4d4c00
daff0ba
285e490
b1752a2
eba0a7f
a0ddaf2
45c3731
99c2d27
3e94519
11c4b92
e03b9a0
9f5c2fb
ce7a937
62fef2d
ccc8fef
a4fb1fa
756b89a
376651e
8d00e18
3e28355
33eca9e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| example/ | ||
| cursor.md |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,38 +1,47 @@ | ||||||||||||||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||||||||||||||
| package="cn.jiguang.plugins.push"> | ||||||||||||||
| > | ||||||||||||||
|
|
||||||||||||||
| <permission | ||||||||||||||
| android:name="${applicationId}.permission.JPUSH_MESSAGE" | ||||||||||||||
| android:protectionLevel="signature" /> | ||||||||||||||
|
|
||||||||||||||
| <!-- Required --> | ||||||||||||||
| <uses-permission android:name="${applicationId}.permission.JPUSH_MESSAGE" /> | ||||||||||||||
| <uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" /> | ||||||||||||||
| <uses-permission android:name="android.permission.INTERNET" /> | ||||||||||||||
| <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||||||||||||||
| <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/> | ||||||||||||||
| <!--华为角标--> | ||||||||||||||
| <uses-permission android:name="com.huawei.android.launcher.permission.CHANGE_BADGE"/> | ||||||||||||||
| <!--vivo 角标--> | ||||||||||||||
| <uses-permission android:name="com.vivo.notification.permission.BADGE_ICON" /> | ||||||||||||||
| <!--honor 角标--> | ||||||||||||||
| <uses-permission android:name="com.hihonor.android.launcher.permission.CHANGE_BADGE" /> | ||||||||||||||
| <!--小米 推送必须--> | ||||||||||||||
| <uses-permission android:name="android.permission.VIBRATE" /> | ||||||||||||||
| <!-- Optional. Required for location feature --> | ||||||||||||||
| <!-- <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> | ||||||||||||||
| <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> | ||||||||||||||
| <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> | ||||||||||||||
|
Comment on lines
+20
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the comment block; it currently comments out unrelated permissions. Close the comment after the 3 location lines and remove the stray trailing -->. - <!-- Optional. Required for location feature -->
- <!-- <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
- <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
+ <!-- Optional. Required for location feature
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
+ <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
+ -->
- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
- <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> -->Also applies to: 31-32 🤖 Prompt for AI Agents |
||||||||||||||
| <uses-permission android:name="android.permission.READ_PHONE_STATE" /> | ||||||||||||||
| <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/> | ||||||||||||||
| <uses-permission android:name="android.permission.GET_TASKS" /> | ||||||||||||||
| <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | ||||||||||||||
| <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||||||||||||||
| <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | ||||||||||||||
| <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" /> | ||||||||||||||
|
Comment on lines
+25
to
30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove non‑Play‑compliant or obsolete permissions. QUERY_ALL_PACKAGES (API 30+) needs strong Play justification; GET_TASKS and MOUNT_UNMOUNT_FILESYSTEMS are legacy/privileged. - <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
- <uses-permission android:name="android.permission.GET_TASKS" />
...
- <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />🤖 Prompt for AI Agents |
||||||||||||||
| <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||||||||||||||
| <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | ||||||||||||||
|
|
||||||||||||||
| <!-- Optional. Required for location feature --> | ||||||||||||||
| <!-- <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> | ||||||||||||||
| <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> | ||||||||||||||
| <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> | ||||||||||||||
| <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> | ||||||||||||||
| <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> | ||||||||||||||
| <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /> | ||||||||||||||
| <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> | ||||||||||||||
| <uses-permission android:name="android.permission.GET_TASKS" /> | ||||||||||||||
| <uses-permission android:name="android.permission.VIBRATE" /> | ||||||||||||||
| <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/> --> | ||||||||||||||
| <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> --> | ||||||||||||||
|
|
||||||||||||||
| <application> | ||||||||||||||
| <activity | ||||||||||||||
| android:name="cn.jpush.android.ui.PopWinActivity" | ||||||||||||||
| android:exported="false" | ||||||||||||||
| android:theme="@style/MyDialogStyle" /> | ||||||||||||||
| android:exported="true" | ||||||||||||||
| android:theme="@style/MyDialogStyle" > | ||||||||||||||
| <intent-filter> | ||||||||||||||
| <category android:name="android.intent.category.DEFAULT" /> | ||||||||||||||
| <action android:name="cn.jpush.android.ui.PopWinActivity" /> | ||||||||||||||
| <category android:name="${applicationId}" /> | ||||||||||||||
| </intent-filter> | ||||||||||||||
| </activity> | ||||||||||||||
|
Comment on lines
+37
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Reassess exporting PopWinActivity. If external apps shouldn’t launch it, drop the intent-filter or add tighter guards. At minimum, keep only DEFAULT + ${applicationId} category; avoid custom action if not required. 🤖 Prompt for AI Agents |
||||||||||||||
|
|
||||||||||||||
| <activity | ||||||||||||||
| android:name="cn.jpush.android.ui.PushActivity" | ||||||||||||||
|
|
@@ -50,7 +59,7 @@ | |||||||||||||
| <activity | ||||||||||||||
| android:name="cn.jpush.android.service.JNotifyActivity" | ||||||||||||||
| android:exported="true" | ||||||||||||||
| android:taskAffinity="jpush.custom" | ||||||||||||||
| android:taskAffinity="" | ||||||||||||||
| android:theme="@style/JPushTheme"> | ||||||||||||||
| <intent-filter> | ||||||||||||||
| <action android:name="cn.jpush.android.intent.JNotifyActivity" /> | ||||||||||||||
|
|
@@ -63,7 +72,7 @@ | |||||||||||||
| android:enabled="true" | ||||||||||||||
| android:exported="false"> | ||||||||||||||
| <intent-filter> | ||||||||||||||
| <action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" /> | ||||||||||||||
| <action android:name="cn.jpush.android.intent.RECEIVER_MESSAGE" /> | ||||||||||||||
| <category android:name="${applicationId}" /> | ||||||||||||||
| </intent-filter> | ||||||||||||||
|
Comment on lines
+75
to
77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Receiver action name looks wrong; likely breaks message delivery. Use cn.jpush.android.intent.RECEIVE_MESSAGE (not RECEIVER_MESSAGE). Apply this diff: - <action android:name="cn.jpush.android.intent.RECEIVER_MESSAGE" />
+ <action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" />📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| </receiver> | ||||||||||||||
|
|
@@ -83,7 +92,7 @@ | |||||||||||||
| <activity | ||||||||||||||
| android:name="cn.android.service.JTransitActivity" | ||||||||||||||
| android:exported="true" | ||||||||||||||
| android:taskAffinity="jpush.custom" | ||||||||||||||
| android:taskAffinity="" | ||||||||||||||
| android:theme="@style/JPushTheme" > | ||||||||||||||
| <intent-filter> | ||||||||||||||
| <action android:name="cn.android.service.JTransitActivity" /> | ||||||||||||||
|
|
@@ -95,13 +104,18 @@ | |||||||||||||
| android:enabled="true" | ||||||||||||||
| android:exported="true" | ||||||||||||||
| android:theme="@android:style/Theme.Translucent.NoTitleBar" | ||||||||||||||
| android:taskAffinity="jpush.custom"> | ||||||||||||||
| android:taskAffinity=""> | ||||||||||||||
| <intent-filter> | ||||||||||||||
| <action android:name="cn.jpush.android.intent.DActivity"/> | ||||||||||||||
| <category android:name="${applicationId}" /> | ||||||||||||||
| </intent-filter> | ||||||||||||||
| </activity> | ||||||||||||||
|
|
||||||||||||||
| <provider | ||||||||||||||
| android:name="cn.jpush.android.service.InitProvider" | ||||||||||||||
| android:authorities="${applicationId}.jiguang.InitProvider" | ||||||||||||||
| android:exported="false" | ||||||||||||||
| android:readPermission="${applicationId}.permission.JPUSH_MESSAGE" | ||||||||||||||
| android:writePermission="${applicationId}.permission.JPUSH_MESSAGE" /> | ||||||||||||||
| </application> | ||||||||||||||
|
|
||||||||||||||
| </manifest> | ||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,9 @@ | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| package cn.jiguang.plugins.push; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| import android.app.NotificationChannel; | ||||||||||||||||||||||||||||||||||
| import android.app.NotificationManager; | ||||||||||||||||||||||||||||||||||
| import android.net.Uri; | ||||||||||||||||||||||||||||||||||
| import android.os.Build; | ||||||||||||||||||||||||||||||||||
| import android.app.Activity; | ||||||||||||||||||||||||||||||||||
| import android.app.Application; | ||||||||||||||||||||||||||||||||||
| import android.os.Bundle; | ||||||||||||||||||||||||||||||||||
|
|
@@ -14,19 +17,23 @@ | |||||||||||||||||||||||||||||||||
| import com.facebook.react.bridge.ReactMethod; | ||||||||||||||||||||||||||||||||||
| import com.facebook.react.bridge.ReadableArray; | ||||||||||||||||||||||||||||||||||
| import com.facebook.react.bridge.ReadableMap; | ||||||||||||||||||||||||||||||||||
| import com.facebook.react.bridge.ReadableNativeMap; | ||||||||||||||||||||||||||||||||||
| import com.facebook.react.bridge.WritableMap; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| import org.json.JSONObject; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| import java.util.HashMap; | ||||||||||||||||||||||||||||||||||
| import java.util.HashSet; | ||||||||||||||||||||||||||||||||||
| import java.util.Set; | ||||||||||||||||||||||||||||||||||
| import java.lang.*; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| import cn.jiguang.plugins.push.common.JConstants; | ||||||||||||||||||||||||||||||||||
| import cn.jiguang.plugins.push.common.JLogger; | ||||||||||||||||||||||||||||||||||
| import cn.jiguang.plugins.push.helper.JPushHelper; | ||||||||||||||||||||||||||||||||||
| import cn.jiguang.plugins.push.receiver.JPushBroadcastReceiver; | ||||||||||||||||||||||||||||||||||
| import cn.jpush.android.api.BasicPushNotificationBuilder; | ||||||||||||||||||||||||||||||||||
| import cn.jpush.android.api.JPushInterface; | ||||||||||||||||||||||||||||||||||
| import cn.jpush.android.data.JPushCollectControl; | ||||||||||||||||||||||||||||||||||
| import cn.jpush.android.data.JPushLocalNotification; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| public class JPushModule extends ReactContextBaseJavaModule { | ||||||||||||||||||||||||||||||||||
|
|
@@ -59,6 +66,7 @@ public void init() { | |||||||||||||||||||||||||||||||||
| JPushHelper.sendEvent(JConstants.NOTIFICATION_EVENT, writableMap); | ||||||||||||||||||||||||||||||||||
| JPushBroadcastReceiver.NOTIFICATION_BUNDLE = null; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| JPushInterface.setNotificationCallBackEnable(reactContext,true); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| @ReactMethod | ||||||||||||||||||||||||||||||||||
|
|
@@ -95,6 +103,92 @@ public void setChannel(ReadableMap readableMap) { | |||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| @ReactMethod | ||||||||||||||||||||||||||||||||||
| public void setChannelAndSound(ReadableMap readableMap) { | ||||||||||||||||||||||||||||||||||
| if (readableMap == null) { | ||||||||||||||||||||||||||||||||||
| JLogger.w(JConstants.PARAMS_NULL); | ||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| String channel = readableMap.getString(JConstants.CHANNEL); | ||||||||||||||||||||||||||||||||||
| String sound = readableMap.getString(JConstants.SOUND); | ||||||||||||||||||||||||||||||||||
| String channelId = readableMap.getString(JConstants.CHANNELID); | ||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||
| NotificationManager manager= (NotificationManager) reactContext.getSystemService("notification"); | ||||||||||||||||||||||||||||||||||
| if(Build.VERSION.SDK_INT<26){ | ||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| if(TextUtils.isEmpty(channel)||TextUtils.isEmpty(channelId)){ | ||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| NotificationChannel channel1=new NotificationChannel(channelId,channel, NotificationManager.IMPORTANCE_HIGH); | ||||||||||||||||||||||||||||||||||
| if(!TextUtils.isEmpty(sound)){ | ||||||||||||||||||||||||||||||||||
| channel1.setSound(Uri.parse("android.resource://"+reactContext.getPackageName()+"/raw/"+sound),null); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| manager.createNotificationChannel(channel1); | ||||||||||||||||||||||||||||||||||
| JPushInterface.setChannel(reactContext,channel); | ||||||||||||||||||||||||||||||||||
| }catch (Throwable throwable){ | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+106
to
+130
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Harden setChannelAndSound: key checks, proper service constant, audio attributes, and logging. Current code can throw before try, swallows all errors, and sets sound without AudioAttributes. - public void setChannelAndSound(ReadableMap readableMap) {
- if (readableMap == null) {
- JLogger.w(JConstants.PARAMS_NULL);
- return;
- }
- String channel = readableMap.getString(JConstants.CHANNEL);
- String sound = readableMap.getString(JConstants.SOUND);
- String channelId = readableMap.getString(JConstants.CHANNELID);
- try {
- NotificationManager manager= (NotificationManager) reactContext.getSystemService("notification");
- if(Build.VERSION.SDK_INT<26){
- return;
- }
- if(TextUtils.isEmpty(channel)||TextUtils.isEmpty(channelId)){
- return;
- }
- NotificationChannel channel1=new NotificationChannel(channelId,channel, NotificationManager.IMPORTANCE_HIGH);
- if(!TextUtils.isEmpty(sound)){
- channel1.setSound(Uri.parse("android.resource://"+reactContext.getPackageName()+"/raw/"+sound),null);
- }
- manager.createNotificationChannel(channel1);
- JPushInterface.setChannel(reactContext,channel);
- }catch (Throwable throwable){
- }
- }
+ public void setChannelAndSound(ReadableMap readableMap) {
+ if (readableMap == null) {
+ JLogger.w(JConstants.PARAMS_NULL);
+ return;
+ }
+ try {
+ String channel = readableMap.hasKey(JConstants.CHANNEL) ? readableMap.getString(JConstants.CHANNEL) : null;
+ String sound = readableMap.hasKey(JConstants.SOUND) ? readableMap.getString(JConstants.SOUND) : null;
+ String channelId = readableMap.hasKey(JConstants.CHANNELID) ? readableMap.getString(JConstants.CHANNELID) : null;
+ if (TextUtils.isEmpty(channel)) {
+ JLogger.w(JConstants.PARAMS_ILLEGAL);
+ return;
+ }
+ if (Build.VERSION.SDK_INT >= 26) {
+ if (TextUtils.isEmpty(channelId)) {
+ JLogger.w("channelId is required on Android O+");
+ return;
+ }
+ NotificationManager manager = (NotificationManager) reactContext.getSystemService(android.content.Context.NOTIFICATION_SERVICE);
+ if (manager == null) {
+ JLogger.w("NotificationManager is null");
+ return;
+ }
+ NotificationChannel ch = new NotificationChannel(channelId, channel, NotificationManager.IMPORTANCE_HIGH);
+ if (!TextUtils.isEmpty(sound)) {
+ Uri uri = Uri.parse("android.resource://" + reactContext.getPackageName() + "/raw/" + sound);
+ android.media.AudioAttributes attrs = new android.media.AudioAttributes.Builder()
+ .setUsage(android.media.AudioAttributes.USAGE_NOTIFICATION)
+ .setContentType(android.media.AudioAttributes.CONTENT_TYPE_SONIFICATION)
+ .build();
+ ch.setSound(uri, attrs);
+ }
+ manager.createNotificationChannel(ch);
+ }
+ // Still set logical channel for JPush
+ JPushInterface.setChannel(reactContext, channel);
+ } catch (Exception e) {
+ JLogger.w("setChannelAndSound failed: " + e.getMessage());
+ }
+ }🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
| @ReactMethod | ||||||||||||||||||||||||||||||||||
| public void setLinkMergeEnable(boolean enable) { | ||||||||||||||||||||||||||||||||||
| JPushInterface.setLinkMergeEnable(reactContext, enable); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| @ReactMethod | ||||||||||||||||||||||||||||||||||
| public void setSmartPushEnable(boolean enable) { | ||||||||||||||||||||||||||||||||||
| JPushInterface.setSmartPushEnable(reactContext, enable); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| @ReactMethod | ||||||||||||||||||||||||||||||||||
| public void setDataInsightsEnable(boolean enable) { | ||||||||||||||||||||||||||||||||||
| JPushInterface.setDataInsightsEnable(reactContext, enable); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| @ReactMethod | ||||||||||||||||||||||||||||||||||
| public void setGeofenceEnable(boolean enable) { | ||||||||||||||||||||||||||||||||||
| JPushInterface.setGeofenceEnable(reactContext, enable); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| @ReactMethod | ||||||||||||||||||||||||||||||||||
| public void setCollectControl(ReadableMap readableMap) { | ||||||||||||||||||||||||||||||||||
| if (readableMap == null) { | ||||||||||||||||||||||||||||||||||
| JLogger.w(JConstants.PARAMS_NULL); | ||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| boolean hadValue = false; | ||||||||||||||||||||||||||||||||||
| JPushCollectControl.Builder builder = new JPushCollectControl.Builder(); | ||||||||||||||||||||||||||||||||||
| if (readableMap.hasKey(JConstants.IMEI)) { | ||||||||||||||||||||||||||||||||||
| hadValue = true; | ||||||||||||||||||||||||||||||||||
| builder.imei(readableMap.getBoolean(JConstants.IMEI)); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| if (readableMap.hasKey(JConstants.IMSI)) { | ||||||||||||||||||||||||||||||||||
| hadValue = true; | ||||||||||||||||||||||||||||||||||
| builder.imsi(readableMap.getBoolean(JConstants.IMSI)); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| if (readableMap.hasKey(JConstants.MAC)) { | ||||||||||||||||||||||||||||||||||
| hadValue = true; | ||||||||||||||||||||||||||||||||||
| builder.mac(readableMap.getBoolean(JConstants.MAC)); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| if (readableMap.hasKey(JConstants.WIFI)) { | ||||||||||||||||||||||||||||||||||
| hadValue = true; | ||||||||||||||||||||||||||||||||||
| builder.wifi(readableMap.getBoolean(JConstants.WIFI)); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| if (readableMap.hasKey(JConstants.BSSID)) { | ||||||||||||||||||||||||||||||||||
| hadValue = true; | ||||||||||||||||||||||||||||||||||
| builder.bssid(readableMap.getBoolean(JConstants.BSSID)); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| if (readableMap.hasKey(JConstants.SSID)) { | ||||||||||||||||||||||||||||||||||
| hadValue = true; | ||||||||||||||||||||||||||||||||||
| builder.ssid(readableMap.getBoolean(JConstants.SSID)); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| if (readableMap.hasKey(JConstants.CELL)) { | ||||||||||||||||||||||||||||||||||
| hadValue = true; | ||||||||||||||||||||||||||||||||||
| builder.cell(readableMap.getBoolean(JConstants.CELL)); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| if (hadValue) { | ||||||||||||||||||||||||||||||||||
| JPushInterface.setCollectControl(reactContext, builder.build()); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| @ReactMethod | ||||||||||||||||||||||||||||||||||
| public void setBadgeNumber(ReadableMap readableMap) { | ||||||||||||||||||||||||||||||||||
| if (readableMap == null) { | ||||||||||||||||||||||||||||||||||
| JLogger.w(JConstants.PARAMS_NULL); | ||||||||||||||||||||||||||||||||||
|
|
@@ -213,7 +307,48 @@ public void filterValidTags(ReadableMap readableMap, Callback callback) { | |||||||||||||||||||||||||||||||||
| JLogger.w("there are no " + JConstants.TAGS); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| @ReactMethod | ||||||||||||||||||||||||||||||||||
| public void setProperties(ReadableMap readableMap) { | ||||||||||||||||||||||||||||||||||
| if (readableMap == null) { | ||||||||||||||||||||||||||||||||||
| JLogger.w(JConstants.PARAMS_NULL); | ||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| if (readableMap.hasKey(JConstants.PROPERTIES)) { | ||||||||||||||||||||||||||||||||||
| int sequence = readableMap.getInt(JConstants.SEQUENCE); | ||||||||||||||||||||||||||||||||||
| ReadableMap readMap = readableMap.getMap(JConstants.PROPERTIES); | ||||||||||||||||||||||||||||||||||
| ReadableNativeMap map= (ReadableNativeMap) readMap; | ||||||||||||||||||||||||||||||||||
| HashMap properties=map.toHashMap(); | ||||||||||||||||||||||||||||||||||
| JPushInterface.setProperties(reactContext,sequence,properties); | ||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||
| JLogger.w("there are no " + JConstants.PROPERTIES); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| @ReactMethod | ||||||||||||||||||||||||||||||||||
| public void deleteProperties(ReadableMap readableMap) { | ||||||||||||||||||||||||||||||||||
| if (readableMap == null) { | ||||||||||||||||||||||||||||||||||
| JLogger.w(JConstants.PARAMS_NULL); | ||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| if (readableMap.hasKey(JConstants.PROPERTIES)) { | ||||||||||||||||||||||||||||||||||
| int sequence = readableMap.getInt(JConstants.SEQUENCE); | ||||||||||||||||||||||||||||||||||
| ReadableMap readMap = readableMap.getMap(JConstants.PROPERTIES); | ||||||||||||||||||||||||||||||||||
| ReadableNativeMap map= (ReadableNativeMap) readMap; | ||||||||||||||||||||||||||||||||||
| HashMap properties=map.toHashMap(); | ||||||||||||||||||||||||||||||||||
| JPushInterface.deleteProperties(reactContext,sequence,properties); | ||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||
| JLogger.w("there are no " + JConstants.PROPERTIES); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| @ReactMethod | ||||||||||||||||||||||||||||||||||
| public void cleanProperties(ReadableMap readableMap) { | ||||||||||||||||||||||||||||||||||
| if (readableMap == null) { | ||||||||||||||||||||||||||||||||||
| JLogger.w(JConstants.PARAMS_NULL); | ||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| int sequence = readableMap.getInt(JConstants.SEQUENCE); | ||||||||||||||||||||||||||||||||||
| JPushInterface.cleanProperties(reactContext,sequence); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+344
to
+351
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard SEQUENCE in cleanProperties. getInt throws if missing. - int sequence = readableMap.getInt(JConstants.SEQUENCE);
+ int sequence = readableMap.hasKey(JConstants.SEQUENCE) ? readableMap.getInt(JConstants.SEQUENCE) : -1;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
| @ReactMethod | ||||||||||||||||||||||||||||||||||
| public void setTags(ReadableMap readableMap) { | ||||||||||||||||||||||||||||||||||
| if (readableMap == null) { | ||||||||||||||||||||||||||||||||||
|
|
@@ -390,15 +525,61 @@ public void addLocalNotification(ReadableMap readableMap) { | |||||||||||||||||||||||||||||||||
| int id = Integer.valueOf(notificationID); | ||||||||||||||||||||||||||||||||||
| String notificationTitle = readableMap.hasKey(JConstants.TITLE) ? readableMap.getString(JConstants.TITLE) : reactContext.getPackageName(); | ||||||||||||||||||||||||||||||||||
| String notificationContent = readableMap.hasKey(JConstants.CONTENT) ? readableMap.getString(JConstants.CONTENT) : reactContext.getPackageName(); | ||||||||||||||||||||||||||||||||||
| String broadcastTime = readableMap.hasKey(JConstants.BROADCAST_TIME) ? readableMap.getString(JConstants.BROADCAST_TIME) : "0"; | ||||||||||||||||||||||||||||||||||
| JPushLocalNotification notification = new JPushLocalNotification(); | ||||||||||||||||||||||||||||||||||
| notification.setNotificationId(id); | ||||||||||||||||||||||||||||||||||
| notification.setTitle(notificationTitle); | ||||||||||||||||||||||||||||||||||
| notification.setContent(notificationContent); | ||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||
| notification.setBroadcastTime(Long.parseLong(broadcastTime)); | ||||||||||||||||||||||||||||||||||
| }catch (Throwable throwable){ | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| if (readableMap.hasKey(JConstants.EXTRAS)) { | ||||||||||||||||||||||||||||||||||
| ReadableMap notificationExtra = readableMap.getMap(JConstants.EXTRAS); | ||||||||||||||||||||||||||||||||||
| JSONObject notificationExtraJson = new JSONObject(notificationExtra.toHashMap()); | ||||||||||||||||||||||||||||||||||
| notification.setExtras(notificationExtraJson.toString()); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // 设置BuilderId | ||||||||||||||||||||||||||||||||||
| if (readableMap.hasKey(JConstants.BUILDER_NAME)) { | ||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||
| String layoutFileName = readableMap.getString(JConstants.BUILDER_NAME); | ||||||||||||||||||||||||||||||||||
| if (!TextUtils.isEmpty(layoutFileName)) { | ||||||||||||||||||||||||||||||||||
| // 通过布局文件名获取资源ID | ||||||||||||||||||||||||||||||||||
| int builderId = reactContext.getResources().getIdentifier( | ||||||||||||||||||||||||||||||||||
| layoutFileName, | ||||||||||||||||||||||||||||||||||
| "layout", | ||||||||||||||||||||||||||||||||||
| reactContext.getPackageName() | ||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||
| if (builderId != 0) { | ||||||||||||||||||||||||||||||||||
| notification.setBuilderId(builderId); | ||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||
| JLogger.w("Layout file not found: " + layoutFileName); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } catch (Exception e) { | ||||||||||||||||||||||||||||||||||
| JLogger.w("Failed to set BuilderId: " + e.getMessage()); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // 设置Category | ||||||||||||||||||||||||||||||||||
| if (readableMap.hasKey(JConstants.CATEGORY)) { | ||||||||||||||||||||||||||||||||||
| String category = readableMap.getString(JConstants.CATEGORY); | ||||||||||||||||||||||||||||||||||
| if (!TextUtils.isEmpty(category)) { | ||||||||||||||||||||||||||||||||||
| notification.setCategory(category); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // 设置Priority | ||||||||||||||||||||||||||||||||||
| if (readableMap.hasKey(JConstants.PRIORITY)) { | ||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||
| int priority = readableMap.getInt(JConstants.PRIORITY); | ||||||||||||||||||||||||||||||||||
| notification.setPriority(priority); | ||||||||||||||||||||||||||||||||||
| } catch (Exception e) { | ||||||||||||||||||||||||||||||||||
| JLogger.w("Priority must be a number"); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| JPushInterface.addLocalNotification(reactContext, notification); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
Remove extra empty line.
RuboCop flagged an extra empty line at the block body beginning.
As per static analysis hints.
Apply this diff:
Pod::Spec.new do |s| - s.name = "JPushRN"📝 Committable suggestion
🧰 Tools
🪛 RuboCop (1.81.1)
[convention] 5-6: Extra empty line detected at block body beginning.
(Layout/EmptyLinesAroundBlockBody)
🤖 Prompt for AI Agents