capacitor-plugin-getui
Advanced tools
| package com.yufu.plugin.getui; | ||
| import android.content.Context; | ||
| import com.getcapacitor.JSObject; | ||
| import com.igexin.sdk.GTIntentService; | ||
| import com.igexin.sdk.message.GTCmdMessage; | ||
| import com.igexin.sdk.message.GTNotificationMessage; | ||
| import com.igexin.sdk.message.GTTransmitMessage; | ||
| import org.json.JSONException; | ||
| public class GetuiIntentService extends GTIntentService { | ||
| @Override | ||
| public void onReceiveServicePid(Context context, int pid) { | ||
| } | ||
| // 处理透传消息 | ||
| @Override | ||
| public void onReceiveMessageData(Context context, GTTransmitMessage msg) { | ||
| byte[] payload = msg.getPayload(); | ||
| JSObject data = new JSObject(); | ||
| data.put("appid", msg.getAppid()); | ||
| data.put("taskid", msg.getTaskId()); | ||
| data.put("messageid", msg.getMessageId()); | ||
| data.put("pkg", msg.getPkgName()); | ||
| data.put("cid", msg.getClientId()); | ||
| if (payload != null) { | ||
| String string = new String(payload); | ||
| try { | ||
| data.put("payload", new JSObject(string)); | ||
| } catch (JSONException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
| GetuiPlugin.triggerListeners("onReceiveMessageData", data, true); | ||
| } | ||
| // 接收 cid | ||
| @Override | ||
| public void onReceiveClientId(Context context, String clientid) { | ||
| JSObject data = new JSObject(); | ||
| data.put("client_id", clientid); | ||
| GetuiPlugin.triggerListeners("onReceiveClientId", data, true); | ||
| } | ||
| // cid 离线上线通知 | ||
| @Override | ||
| public void onReceiveOnlineState(Context context, boolean online) { | ||
| JSObject data = new JSObject(); | ||
| data.put("online", online); | ||
| GetuiPlugin.triggerListeners("onReceiveClientId", data, true); | ||
| } | ||
| // 各种事件处理回执 | ||
| @Override | ||
| public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) { | ||
| } | ||
| // 通知到达,只有个推通道下发的通知会回调此方法 | ||
| @Override | ||
| public void onNotificationMessageArrived(Context context, GTNotificationMessage msg) { | ||
| } | ||
| // 通知点击,只有个推通道下发的通知会回调此方法 | ||
| @Override | ||
| public void onNotificationMessageClicked(Context context, GTNotificationMessage msg) { | ||
| } | ||
| } |
| package com.yufu.plugin.getui; | ||
| import com.igexin.sdk.PushService; | ||
| public class GetuiPushService extends PushService { | ||
| } |
+50
-40
| ext { | ||
| junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.1' | ||
| androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.2.0' | ||
| androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.2' | ||
| androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.3.0' | ||
| junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.1' | ||
| androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.2.0' | ||
| androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.2' | ||
| androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.3.0' | ||
| } | ||
| buildscript { | ||
| repositories { | ||
| google() | ||
| jcenter() | ||
| } | ||
| dependencies { | ||
| classpath 'com.android.tools.build:gradle:4.2.1' | ||
| } | ||
| repositories { | ||
| google() | ||
| jcenter() | ||
| } | ||
| dependencies { | ||
| classpath 'com.android.tools.build:gradle:4.1.3' | ||
| } | ||
| } | ||
@@ -21,29 +21,35 @@ | ||
| android { | ||
| compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 30 | ||
| defaultConfig { | ||
| minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 21 | ||
| targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 30 | ||
| versionCode 1 | ||
| versionName "1.0" | ||
| testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
| compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 30 | ||
| defaultConfig { | ||
| minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 21 | ||
| targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 30 | ||
| versionCode 1 | ||
| versionName "1.0" | ||
| testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
| manifestPlaceholders = [ | ||
| //从 3.1.2.0 版本开始,APPID 占位符从 GETUI_APP_ID 切换为 GETUI_APPID | ||
| //后续所有产品的 APPID 均统一配置为 GETUI_APPID 占位符 | ||
| GETUI_APPID: "Dhemgn99KI9xnNOVowRpC9", | ||
| ] | ||
| } | ||
| buildTypes { | ||
| release { | ||
| minifyEnabled false | ||
| proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
| } | ||
| buildTypes { | ||
| release { | ||
| minifyEnabled false | ||
| proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
| } | ||
| } | ||
| lintOptions { | ||
| abortOnError false | ||
| } | ||
| compileOptions { | ||
| sourceCompatibility JavaVersion.VERSION_1_8 | ||
| targetCompatibility JavaVersion.VERSION_1_8 | ||
| } | ||
| } | ||
| lintOptions { | ||
| abortOnError false | ||
| } | ||
| compileOptions { | ||
| sourceCompatibility JavaVersion.VERSION_1_8 | ||
| targetCompatibility JavaVersion.VERSION_1_8 | ||
| } | ||
| } | ||
| repositories { | ||
| google() | ||
| mavenCentral() | ||
| jcenter() | ||
| google() | ||
| mavenCentral() | ||
| jcenter() | ||
| } | ||
@@ -53,8 +59,12 @@ | ||
| dependencies { | ||
| implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
| implementation project(':capacitor-android') | ||
| implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion" | ||
| testImplementation "junit:junit:$junitVersion" | ||
| androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion" | ||
| androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion" | ||
| implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
| implementation "com.getui:gtsdk:3.2.10.0" | ||
| implementation "com.getui:gtc:3.1.9.0" | ||
| implementation project(':capacitor-android') | ||
| implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion" | ||
| testImplementation "junit:junit:$junitVersion" | ||
| androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion" | ||
| androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion" | ||
| } | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| package="com.yufu.plugin.getui"> | ||
| xmlns:tools="http://schemas.android.com/tools" | ||
| package="com.yufu.plugin.getui"> | ||
| <queries> | ||
| <intent> | ||
| <action android:name="com.getui.sdk.action" /> | ||
| </intent> | ||
| </queries> | ||
| <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> | ||
| <uses-permission android:name="android.permission.WAKE_LOCK" /> | ||
| <uses-permission android:name="android.permission.INTERNET" /> | ||
| <uses-permission android:name="android.permission.READ_PHONE_STATE" /> | ||
| <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
| <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | ||
| <uses-permission android:name="android.permission.VIBRATE" /> | ||
| <uses-permission android:name="android.permission.GET_TASKS" /> | ||
| <uses-permission android:name="getui.permission.GetuiService.{$applicationId}" /> | ||
| <permission | ||
| android:name="getui.permission.GetuiService.{$applicationId}" | ||
| android:protectionLevel="signature" /> | ||
| <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" /> | ||
| <uses-permission android:name="com.vivo.notification.permission.BADGE_ICON" /> | ||
| <uses-permission android:name="android.permission.BLUETOOTH" /> | ||
| <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> | ||
| <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> | ||
| <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> | ||
| <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> | ||
| <application | ||
| android:allowBackup="true" | ||
| android:label="@string/app_name" | ||
| android:usesCleartextTraffic="true" | ||
| tools:ignore="GoogleAppIndexingWarning" | ||
| tools:targetApi="m"> | ||
| <receiver android:name="com.yufu.plugin.getui.TimedNotificationPublisher" /> | ||
| <receiver android:name="com.yufu.plugin.getui.NotificationDismissReceiver" /> | ||
| <receiver | ||
| android:name="com.yufu.plugin.getui.LocalNotificationRestoreReceiver" | ||
| android:directBootAware="true" | ||
| android:exported="false"> | ||
| <intent-filter> | ||
| <action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" /> | ||
| <action android:name="android.intent.action.BOOT_COMPLETED" /> | ||
| <action android:name="android.intent.action.QUICKBOOT_POWERON" /> | ||
| </intent-filter> | ||
| </receiver> | ||
| <service | ||
| android:name="com.yufu.plugin.getui.GetuiPushService" | ||
| android:exported="false" | ||
| android:label="PushService" | ||
| android:process=":pushservice" /> | ||
| <service android:name="com.yufu.plugin.getui.GetuiIntentService" /> | ||
| <meta-data | ||
| android:name="GETUI_APPID" | ||
| android:value="pdr0zMG65GAcnCl91qZ1k4" | ||
| tools:replace="android:value" /> | ||
| </application> | ||
| </manifest> |
@@ -5,2 +5,3 @@ package com.yufu.plugin.getui; | ||
| public class Getui { | ||
@@ -12,2 +13,3 @@ | ||
| } | ||
| } |
| package com.yufu.plugin.getui; | ||
| import android.annotation.SuppressLint; | ||
| import android.content.Context; | ||
| import android.net.Uri; | ||
| import com.getcapacitor.Bridge; | ||
| import com.getcapacitor.JSArray; | ||
| import com.getcapacitor.JSObject; | ||
| import com.getcapacitor.Plugin; | ||
| import com.getcapacitor.PluginCall; | ||
| import com.getcapacitor.PluginHandle; | ||
| import com.getcapacitor.PluginMethod; | ||
| import com.getcapacitor.annotation.CapacitorPlugin; | ||
| import com.igexin.sdk.PushConsts; | ||
| import com.igexin.sdk.PushManager; | ||
| import com.igexin.sdk.Tag; | ||
| import org.json.JSONArray; | ||
| import org.json.JSONException; | ||
| import java.util.List; | ||
| @CapacitorPlugin(name = "Getui") | ||
| public class GetuiPlugin extends Plugin { | ||
| private Getui implementation = new Getui(); | ||
| public static Bridge staticBridge = null; | ||
| private final Getui implementation = new Getui(); | ||
| @SuppressLint("StaticFieldLeak") | ||
| public static Context staticContext; | ||
| private static PushManager pushManager = PushManager.getInstance(); | ||
| private String clientId = null; | ||
| private LocalNotificationManager manager; | ||
| private NotificationStorage notificationStorage; | ||
| @PluginMethod | ||
| public void echo(PluginCall call) { | ||
| String value = call.getString("value"); | ||
| @Override | ||
| public void load() { | ||
| super.load(); | ||
| staticBridge = this.bridge; | ||
| staticContext = getActivity(); | ||
| pushManager = PushManager.getInstance(); | ||
| } | ||
| JSObject ret = new JSObject(); | ||
| ret.put("value", implementation.echo(value)); | ||
| call.resolve(ret); | ||
| @PluginMethod | ||
| public void echo(PluginCall call) { | ||
| String value = call.getString("value"); | ||
| JSObject ret = new JSObject(); | ||
| ret.put("value", implementation.echo(value)); | ||
| call.resolve(ret); | ||
| } | ||
| /** | ||
| * 初始化SDK | ||
| */ | ||
| @PluginMethod | ||
| public void init(PluginCall call) { | ||
| JSObject ret = new JSObject(); | ||
| PushManager.getInstance().initialize(staticContext); | ||
| ret.put("version", pushManager.getVersion(staticContext)); | ||
| ret.put("client_id", getClientId()); | ||
| call.resolve(ret); | ||
| } | ||
| /** | ||
| * 获取当前 SDK 版本号 | ||
| */ | ||
| @PluginMethod | ||
| public void getVersion(PluginCall call) { | ||
| JSObject ret = new JSObject(); | ||
| ret.put("version", pushManager.getVersion(staticContext)); | ||
| call.resolve(ret); | ||
| } | ||
| /** | ||
| * 获取当前用户的clientId | ||
| */ | ||
| @PluginMethod | ||
| public void getClientId(PluginCall call) { | ||
| JSObject ret = new JSObject(); | ||
| ret.put("client_id", getClientId()); | ||
| call.resolve(ret); | ||
| } | ||
| /** | ||
| * 为当前用户设置一组标签,后续推送可以指定标签名进行定向推送。 | ||
| */ | ||
| @PluginMethod | ||
| public void setTag(PluginCall call) { | ||
| if (clientId == null) { | ||
| call.reject("clientId is empty"); | ||
| return; | ||
| } | ||
| String sn = call.getString("sn", "sn"); | ||
| JSArray tags = call.getArray("tags"); | ||
| int length = tags.length(); | ||
| Tag[] tagParam = new Tag[length]; | ||
| for (int i = 0; i < length; i++) { | ||
| String tag = ""; | ||
| try { | ||
| tag = tags.getString(i); | ||
| } catch (JSONException ignored) { | ||
| } | ||
| if (!tag.equals("")) { | ||
| Tag t = new Tag(); | ||
| //name 字段只支持:中文、英文字母(大小写)、数字、除英文逗号以外的其他特殊符号 | ||
| t.setName(tag); | ||
| tagParam[i] = t; | ||
| } | ||
| } | ||
| int resultCode = pushManager.setTag(staticContext, tagParam, sn); | ||
| String resultMessage = "设置标签失败,未知异常"; | ||
| switch (resultCode) { | ||
| case PushConsts.SETTAG_SUCCESS: | ||
| resultMessage = "设置标签成功"; | ||
| break; | ||
| case PushConsts.SETTAG_ERROR_COUNT: | ||
| resultMessage = "设置标签失败, tag数量过大, 最大不能超过200个"; | ||
| break; | ||
| case PushConsts.SETTAG_ERROR_FREQUENCY: | ||
| resultMessage = "设置标签失败, 频率过快, 两次间隔应大于1s"; | ||
| break; | ||
| case PushConsts.SETTAG_ERROR_REPEAT: | ||
| resultMessage = "设置标签失败, 标签重复"; | ||
| break; | ||
| case PushConsts.SETTAG_ERROR_UNBIND: | ||
| resultMessage = "设置标签失败, 服务未初始化成功"; | ||
| break; | ||
| case PushConsts.SETTAG_ERROR_EXCEPTION: | ||
| resultMessage = "设置标签失败, 未知异常"; | ||
| break; | ||
| case PushConsts.SETTAG_ERROR_NULL: | ||
| resultMessage = "设置标签失败, tag 为空"; | ||
| break; | ||
| case PushConsts.SETTAG_NOTONLINE: | ||
| resultMessage = "还未登陆成功"; | ||
| break; | ||
| case PushConsts.SETTAG_IN_BLACKLIST: | ||
| resultMessage = "该应用已经在黑名单中,请联系售后支持!"; | ||
| break; | ||
| case PushConsts.SETTAG_NUM_EXCEED: | ||
| resultMessage = "已存 tag 超过限制"; | ||
| break; | ||
| default: | ||
| break; | ||
| } | ||
| JSObject ret = new JSObject(); | ||
| ret.put("resultCode", resultCode); | ||
| ret.put("resultMessage", resultMessage); | ||
| call.resolve(ret); | ||
| } | ||
| /** | ||
| * 开启Push推送, 默认是开启状态, 关闭状态则收不到推送。turnOnPush 默认打开 | ||
| */ | ||
| @PluginMethod | ||
| public void turnOnPush(PluginCall call) { | ||
| pushManager.turnOnPush(staticContext); | ||
| JSObject ret = new JSObject(); | ||
| ret.put("state", isPushTurnedOn()); | ||
| call.resolve(ret); | ||
| } | ||
| /** | ||
| * 关闭Push推送, 关闭后则无法收到推送消息 | ||
| */ | ||
| @PluginMethod | ||
| public void turnOffPush(PluginCall call) { | ||
| pushManager.turnOffPush(staticContext); | ||
| JSObject ret = new JSObject(); | ||
| ret.put("state", isPushTurnedOn()); | ||
| call.resolve(ret); | ||
| } | ||
| /** | ||
| * 设置静默时间,静默期间SDK将不再联网 | ||
| */ | ||
| @PluginMethod | ||
| public void setSilentTime(PluginCall call) { | ||
| Integer beginHour = call.getInt("begin_hour", 0); | ||
| Integer duration = call.getInt("begin_hour", 0); | ||
| assert (beginHour != null && duration != null); | ||
| pushManager.setSilentTime(staticContext, beginHour, duration); | ||
| JSObject ret = new JSObject(); | ||
| ret.put("state", isPushTurnedOn()); | ||
| call.resolve(ret); | ||
| } | ||
| /** | ||
| * 获取 SDK 服务状态 | ||
| * true:当前推送已打开;false:当前推送已关闭 | ||
| */ | ||
| @PluginMethod | ||
| public void isPushTurnedOn(PluginCall call) { | ||
| JSObject ret = new JSObject(); | ||
| ret.put("state", isPushTurnedOn()); | ||
| call.resolve(ret); | ||
| } | ||
| /** | ||
| * 检测用户设备是否开启通知权限 | ||
| * 返回true,表示用户设备正常开启通知权限,推送通知在设备上可以正常到达、展示;返回false,表示用户设备未开启通知权限 | ||
| */ | ||
| @PluginMethod | ||
| public void areNotificationsEnabled(PluginCall call) { | ||
| boolean state = pushManager.areNotificationsEnabled(staticContext); | ||
| JSObject ret = new JSObject(); | ||
| ret.put("state", state); | ||
| call.resolve(ret); | ||
| } | ||
| /** | ||
| * 开启通知权限 | ||
| * 调用方法,将跳转到系统开启通知功能页面,引导用户开启通知权限 | ||
| */ | ||
| @PluginMethod | ||
| public void openNotification(PluginCall call) { | ||
| pushManager.openNotification(staticContext); | ||
| } | ||
| /** | ||
| * 设置华为设备上的应用角标 | ||
| * num: 角标数量 | ||
| */ | ||
| @PluginMethod | ||
| public void setHwBadgeNum(PluginCall call) { | ||
| Integer num = call.getInt("num", 1); | ||
| assert (num != null); | ||
| boolean result = pushManager.setHwBadgeNum(staticContext, num); | ||
| JSObject ret = new JSObject(); | ||
| ret.put("result", result); | ||
| call.resolve(ret); | ||
| } | ||
| /** | ||
| * 设置Oppo角标。需要oppo官方设置白名单 | ||
| * num: 角标数量 | ||
| */ | ||
| @PluginMethod | ||
| public void setOPPOBadgeNum(PluginCall call) { | ||
| Integer num = call.getInt("num", 1); | ||
| assert (num != null); | ||
| boolean result = pushManager.setOPPOBadgeNum(staticContext, num); | ||
| JSObject ret = new JSObject(); | ||
| ret.put("result", result); | ||
| call.resolve(ret); | ||
| } | ||
| /** | ||
| * 设置vivo设备上的角标数 | ||
| * num: 角标数量 | ||
| */ | ||
| @PluginMethod | ||
| public void setVivoAppBadgeNum(PluginCall call) { | ||
| Integer num = call.getInt("num", 1); | ||
| assert (num != null); | ||
| boolean result = pushManager.setVivoAppBadgeNum(staticContext, num); | ||
| JSObject ret = new JSObject(); | ||
| ret.put("result", result); | ||
| call.resolve(ret); | ||
| } | ||
| /** | ||
| * 创建本地通知 | ||
| */ | ||
| @PluginMethod | ||
| public void schedule(PluginCall call) { | ||
| List<LocalNotification> localNotifications = LocalNotification.buildNotificationList(call); | ||
| if (localNotifications == null) { | ||
| return; | ||
| } | ||
| JSONArray ids = manager.schedule(call, localNotifications); | ||
| if (ids != null) { | ||
| notificationStorage.appendNotifications(localNotifications); | ||
| JSObject result = new JSObject(); | ||
| JSArray jsArray = new JSArray(); | ||
| for (int i = 0; i < ids.length(); i++) { | ||
| try { | ||
| JSObject notification = new JSObject().put("id", ids.getInt(i)); | ||
| jsArray.put(notification); | ||
| } catch (Exception ex) { | ||
| } | ||
| } | ||
| result.put("notifications", jsArray); | ||
| call.resolve(result); | ||
| } | ||
| } | ||
| public static GetuiPlugin getInstance() { | ||
| if (staticBridge != null && staticBridge.getWebView() != null) { | ||
| PluginHandle handle = staticBridge.getPlugin("Getui"); | ||
| if (handle == null) { | ||
| return null; | ||
| } | ||
| return (GetuiPlugin) handle.getInstance(); | ||
| } | ||
| return null; | ||
| } | ||
| public static void fireReceived(JSObject notification) { | ||
| GetuiPlugin getuiPlugin = GetuiPlugin.getInstance(); | ||
| if (getuiPlugin != null) { | ||
| getuiPlugin.notifyListeners("localNotificationReceived", notification, true); | ||
| } | ||
| } | ||
| public static void triggerListeners(String eventName, JSObject data, boolean retainUntilConsumed) { | ||
| GetuiPlugin getuiPlugin = GetuiPlugin.getInstance(); | ||
| if (getuiPlugin != null) { | ||
| getuiPlugin.notifyListeners(eventName, data, retainUntilConsumed); | ||
| } | ||
| } | ||
| public static void triggerListeners(String eventName, JSObject data) { | ||
| triggerListeners(eventName, data, false); | ||
| } | ||
| public String getClientId() { | ||
| clientId = pushManager.getClientid(staticContext); | ||
| return clientId; | ||
| } | ||
| public Boolean isPushTurnedOn() { | ||
| return pushManager.isPushTurnedOn(staticContext); | ||
| } | ||
| } |
+1
-1
| { | ||
| "name": "capacitor-plugin-getui", | ||
| "version": "0.0.3", | ||
| "version": "0.0.4", | ||
| "description": "个推", | ||
@@ -5,0 +5,0 @@ "main": "dist/plugin.cjs.js", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
29260
94.55%29
7.41%470
270.08%1
Infinity%