Skip to content

Commit e8837fe

Browse files
committed
Add new API setGeofenceInterval for Android
1 parent ed726bf commit e8837fe

File tree

3 files changed

+67
-11
lines changed

3 files changed

+67
-11
lines changed

android/src/main/java/cn/jpush/reactnativejpush/JPushModule.java

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import android.content.pm.ApplicationInfo;
1313
import android.os.Build;
1414
import android.os.Bundle;
15+
import android.util.Log;
1516
import android.util.SparseArray;
1617

1718
import com.facebook.react.bridge.Arguments;
@@ -108,7 +109,7 @@ public void onCatalystInstanceDestroy() {
108109

109110
@ReactMethod
110111
public void initPush() {
111-
mContext = getCurrentActivity();
112+
mContext = getReactApplicationContext();
112113
JPushInterface.init(getReactApplicationContext());
113114
Logger.toast(mContext, "Init push success");
114115
Logger.i(TAG, "init Success!");
@@ -133,7 +134,7 @@ public void getInfo(Callback successCallback) {
133134

134135
@ReactMethod
135136
public void stopPush() {
136-
mContext = getCurrentActivity();
137+
mContext = getReactApplicationContext();
137138
JPushInterface.stopPush(getReactApplicationContext());
138139
Logger.i(TAG, "Stop push");
139140
Logger.toast(mContext, "Stop push success");
@@ -148,7 +149,7 @@ public void hasPermission(Callback callback) {
148149

149150
@ReactMethod
150151
public void resumePush() {
151-
mContext = getCurrentActivity();
152+
mContext = getReactApplicationContext();
152153
JPushInterface.resumePush(getReactApplicationContext());
153154
Logger.i(TAG, "Resume push");
154155
Logger.toast(mContext, "Resume push success");
@@ -451,7 +452,7 @@ public void clearAllNotifications() {
451452
@ReactMethod
452453
public void clearNotificationById(int id) {
453454
try {
454-
mContext = getCurrentActivity();
455+
mContext = getReactApplicationContext();
455456
JPushInterface.clearNotificationById(mContext, id);
456457
} catch (Exception e) {
457458
e.printStackTrace();
@@ -461,7 +462,7 @@ public void clearNotificationById(int id) {
461462
@ReactMethod
462463
public void setLatestNotificationNumber(int number) {
463464
try {
464-
mContext = getCurrentActivity();
465+
mContext = getReactApplicationContext();
465466
JPushInterface.setLatestNotificationNumber(mContext, number);
466467
} catch (Exception e) {
467468
e.printStackTrace();
@@ -471,7 +472,7 @@ public void setLatestNotificationNumber(int number) {
471472
@ReactMethod
472473
public void setPushTime(ReadableMap map) {
473474
try {
474-
mContext = getCurrentActivity();
475+
mContext = getReactApplicationContext();
475476
ReadableArray array = map.getArray("days");
476477
Set<Integer> days = new HashSet<Integer>();
477478
for (int i=0; i < array.size(); i++) {
@@ -492,7 +493,7 @@ public void setPushTime(ReadableMap map) {
492493
@ReactMethod
493494
public void setSilenceTime(ReadableMap map) {
494495
try {
495-
mContext = getCurrentActivity();
496+
mContext = getReactApplicationContext();
496497
String starTime = map.getString("startTime");
497498
String endTime = map.getString("endTime");
498499
String[] sTime = starTime.split(":");
@@ -504,6 +505,30 @@ public void setSilenceTime(ReadableMap map) {
504505
}
505506
}
506507

508+
509+
@ReactMethod
510+
public void setGeofenceInterval(double interval) {
511+
Log.i("tessss",interval+"interval");
512+
try {
513+
mContext = getReactApplicationContext();
514+
JPushInterface.setGeofenceInterval(mContext, (long)interval);
515+
} catch (Exception e) {
516+
e.printStackTrace();
517+
}
518+
}
519+
520+
521+
@ReactMethod
522+
public void setMaxGeofenceNumber(int maxNumber) {
523+
Log.i("tessss",maxNumber+"maxNumber");
524+
try {
525+
mContext = getReactApplicationContext();
526+
JPushInterface.setMaxGeofenceNumber(mContext, maxNumber);
527+
} catch (Exception e) {
528+
e.printStackTrace();
529+
}
530+
}
531+
507532
@ReactMethod
508533
public void sendLocalNotification(ReadableMap map) {
509534
try {
@@ -778,7 +803,7 @@ public void finishActivity() {
778803

779804
private boolean hasPermission(String appOpsServiceId) {
780805

781-
Context context = getCurrentActivity().getApplicationContext();
806+
Context context = getReactApplicationContext();
782807
if (Build.VERSION.SDK_INT >= 24) {
783808
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(
784809
Context.NOTIFICATION_SERVICE);

index.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,15 @@ declare class JPush {
161161
*/
162162
static setPushTime(config: object): void
163163

164+
/**
165+
* Android Only
166+
*/
167+
static setGeofenceInterval(interval: number): void
168+
169+
/**
170+
* Android Only
171+
*/
172+
static setMaxGeofenceNumber(maxNumber: number): void
164173
/**
165174
* Android Only
166175
*/

index.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,15 +273,19 @@ export default class JPush {
273273
* Android Only
274274
*/
275275
static setLatestNotificationNumber (maxNumber) {
276-
JPushModule.setLatestNotificationNumber(maxNumber)
276+
if (Platform.OS == "android") {
277+
JPushModule.setLatestNotificationNumber(maxNumber)
278+
}
277279
}
278280

279281
/**
280282
* Android Only
281283
* @param {object} config = {"startTime": String, "endTime": String} // 例如:{startTime: "20:30", endTime: "8:30"}
282284
*/
283285
static setSilenceTime (config) {
284-
JPushModule.setSilenceTime(config)
286+
if (Platform.OS == "android") {
287+
JPushModule.setSilenceTime(config)
288+
}
285289
}
286290

287291
/**
@@ -290,7 +294,25 @@ export default class JPush {
290294
* // 例如:{days: [0, 6], startHour: 8, endHour: 23} 表示星期天和星期六的上午 8 点到晚上 11 点都可以推送
291295
*/
292296
static setPushTime (config) {
293-
JPushModule.setPushTime(config)
297+
if (Platform.OS == "android") {
298+
JPushModule.setPushTime(config)
299+
}
300+
}
301+
302+
/**
303+
* Android Only
304+
*/
305+
static setGeofenceInterval(interval) {
306+
if (Platform.OS == "android") {
307+
JPushModule.setGeofenceInterval(interval)
308+
}
309+
}
310+
311+
/**
312+
* Android Only
313+
*/
314+
static setMaxGeofenceNumber(maxNumber) {
315+
JPushModule.setMaxGeofenceNumber(maxNumber)
294316
}
295317

296318
/**

0 commit comments

Comments
 (0)