正在查看: Vi App v10.18.0 应用的 RNPushNotification.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Vi App v10.18.0 应用的 RNPushNotification.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.dieam.reactnativepushnotification.modules;
import android.app.Activity;
import android.app.Application;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationManagerCompat;
import com.dieam.reactnativepushnotification.helpers.ApplicationBadgeHelper;
import com.facebook.react.bridge.ActivityEventListener;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.google.android.exoplayer2.offline.DownloadService;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.messaging.Constants;
import com.google.firebase.messaging.FirebaseMessaging;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class RNPushNotification extends ReactContextBaseJavaModule implements ActivityEventListener {
public static ArrayList<RNIntentHandler> IntentHandlers = new ArrayList<>();
public static final String KEY_TEXT_REPLY = "key_text_reply";
public static final String LOG_TAG = "RNPushNotification";
private RNPushNotificationJsDelivery mJsDelivery;
private RNPushNotificationHelper mRNPushNotificationHelper;
private final SecureRandom mRandomNumberGenerator;
public interface RNIntentHandler {
@Nullable
Bundle getBundleFromIntent(Intent intent);
void onNewIntent(Intent intent);
}
public RNPushNotification(ReactApplicationContext reactApplicationContext) {
super(reactApplicationContext);
this.mRandomNumberGenerator = new SecureRandom();
reactApplicationContext.addActivityEventListener(this);
this.mRNPushNotificationHelper = new RNPushNotificationHelper((Application) reactApplicationContext.getApplicationContext());
this.mJsDelivery = new RNPushNotificationJsDelivery(reactApplicationContext);
}
private Bundle getBundleFromIntent(Intent intent) {
Bundle bundle;
if (intent.hasExtra("notification")) {
bundle = intent.getBundleExtra("notification");
} else if (intent.hasExtra(Constants.MessagePayloadKeys.MSGID)) {
bundle = new Bundle();
bundle.putBundle("data", intent.getExtras());
} else {
bundle = null;
}
if (bundle == null) {
Iterator<RNIntentHandler> it = IntentHandlers.iterator();
while (it.hasNext()) {
bundle = it.next().getBundleFromIntent(intent);
}
}
if (bundle != null && !bundle.getBoolean(DownloadService.KEY_FOREGROUND, false) && !bundle.containsKey("userInteraction")) {
bundle.putBoolean("userInteraction", true);
}
return bundle;
}
@ReactMethod
public void abandonPermissions() {
FirebaseMessaging.getInstance().deleteToken();
}
@ReactMethod
public void cancelAllLocalNotifications() {
this.mRNPushNotificationHelper.cancelAllScheduledNotifications();
this.mRNPushNotificationHelper.clearNotifications();
}
@ReactMethod
public void cancelLocalNotification(String str) {
this.mRNPushNotificationHelper.cancelScheduledNotification(str);
}
@ReactMethod
public void channelBlocked(String str, Callback callback) {
boolean channelBlocked = this.mRNPushNotificationHelper.channelBlocked(str);
if (callback != null) {
callback.invoke(Boolean.valueOf(channelBlocked));
}
}
@ReactMethod
public void channelExists(String str, Callback callback) {
boolean channelExists = this.mRNPushNotificationHelper.channelExists(str);
if (callback != null) {
callback.invoke(Boolean.valueOf(channelExists));
}
}
@ReactMethod
public void checkPermissions(Promise promise) {
promise.resolve(Boolean.valueOf(NotificationManagerCompat.from(getReactApplicationContext()).areNotificationsEnabled()));
}
@ReactMethod
public void clearLocalNotification(String str, int i) {
this.mRNPushNotificationHelper.clearNotification(str, i);
}
@ReactMethod
public void createChannel(ReadableMap readableMap, Callback callback) {
boolean createChannel = this.mRNPushNotificationHelper.createChannel(readableMap);
if (callback != null) {
callback.invoke(Boolean.valueOf(createChannel));
}
}
@ReactMethod
public void deleteChannel(String str) {
this.mRNPushNotificationHelper.deleteChannel(str);
}
@ReactMethod
public void getChannels(Callback callback) {
WritableArray fromList = Arguments.fromList(this.mRNPushNotificationHelper.listChannels());
if (callback != null) {
callback.invoke(fromList);
}
}
@Override
public Map<String, Object> getConstants() {
return new HashMap();
}
@ReactMethod
public void getDeliveredNotifications(Callback callback) {
callback.invoke(this.mRNPushNotificationHelper.getDeliveredNotifications());
}
@ReactMethod
public void getInitialNotification(Promise promise) {
Bundle bundleFromIntent;
WritableMap createMap = Arguments.createMap();
Activity currentActivity = getCurrentActivity();
if (currentActivity != null && (bundleFromIntent = getBundleFromIntent(currentActivity.getIntent())) != null) {
bundleFromIntent.putBoolean(DownloadService.KEY_FOREGROUND, false);
createMap.putString("dataJSON", this.mJsDelivery.convertJSON(bundleFromIntent));
}
promise.resolve(createMap);
}
@Override
public String getName() {
return "ReactNativePushNotification";
}
@ReactMethod
public void getScheduledLocalNotifications(Callback callback) {
callback.invoke(this.mRNPushNotificationHelper.getScheduledLocalNotifications());
}
@ReactMethod
public void invokeApp(ReadableMap readableMap) {
this.mRNPushNotificationHelper.invokeApp(readableMap != null ? Arguments.toBundle(readableMap) : null);
}
public void onActivityResult(int i, int i2, Intent intent) {
}
@Override
public void onActivityResult(Activity activity, int i, int i2, Intent intent) {
onActivityResult(i, i2, intent);
}
@Override
public void onNewIntent(Intent intent) {
Iterator<RNIntentHandler> it = IntentHandlers.iterator();
while (it.hasNext()) {
it.next().onNewIntent(intent);
}
Bundle bundleFromIntent = getBundleFromIntent(intent);
if (bundleFromIntent != null) {
this.mJsDelivery.notifyNotification(bundleFromIntent);
}
}
@ReactMethod
public void presentLocalNotification(ReadableMap readableMap) {
Bundle bundle = Arguments.toBundle(readableMap);
if (bundle.getString(com.clevertap.android.sdk.Constants.KEY_ID) == null) {
bundle.putString(com.clevertap.android.sdk.Constants.KEY_ID, String.valueOf(this.mRandomNumberGenerator.nextInt()));
}
this.mRNPushNotificationHelper.sendToNotificationCentre(bundle);
}
@ReactMethod
public void removeAllDeliveredNotifications() {
this.mRNPushNotificationHelper.clearNotifications();
}
@ReactMethod
public void removeDeliveredNotifications(ReadableArray readableArray) {
this.mRNPushNotificationHelper.clearDeliveredNotifications(readableArray);
}
@ReactMethod
public void requestPermissions() {
final RNPushNotificationJsDelivery rNPushNotificationJsDelivery = this.mJsDelivery;
FirebaseMessaging.getInstance().getToken().addOnCompleteListener(new OnCompleteListener<String>() {
public void onComplete(@NonNull Task<String> task) {
if (!task.isSuccessful()) {
task.getException();
return;
}
WritableMap createMap = Arguments.createMap();
createMap.putString("deviceToken", (String) task.getResult());
rNPushNotificationJsDelivery.sendEvent("remoteNotificationsRegistered", createMap);
}
});
}
@ReactMethod
public void scheduleLocalNotification(ReadableMap readableMap) {
Bundle bundle = Arguments.toBundle(readableMap);
if (bundle.getString(com.clevertap.android.sdk.Constants.KEY_ID) == null) {
bundle.putString(com.clevertap.android.sdk.Constants.KEY_ID, String.valueOf(this.mRandomNumberGenerator.nextInt()));
}
this.mRNPushNotificationHelper.sendNotificationScheduled(bundle);
}
@ReactMethod
public void setApplicationIconBadgeNumber(int i) {
ApplicationBadgeHelper.INSTANCE.setApplicationIconBadgeNumber(getReactApplicationContext(), i);
}
@ReactMethod
public void subscribeToTopic(String str) {
FirebaseMessaging.getInstance().subscribeToTopic(str);
}
@ReactMethod
public void unsubscribeFromTopic(String str) {
FirebaseMessaging.getInstance().unsubscribeFromTopic(str);
}
}