flutter 适配 2.0 ,2.0以下版本使用 0.6.3

master
qingqing.wang 4 years ago
parent e4618b10d5
commit fa7f70c174

@ -37,6 +37,6 @@ dependencies {
implementation 'cn.jiguang.sdk:jpush:3.9.0' implementation 'cn.jiguang.sdk:jpush:3.9.0'
implementation 'cn.jiguang.sdk:jcore:2.6.0' implementation 'cn.jiguang.sdk:jcore:2.6.0'
// implementation 'com.android.support:appcompat-v7:28.+' // implementation 'com.android.support:appcompat-v7:28.+'
compileOnly files('libs/flutter.jar') // compileOnly files('libs/flutter.jar')
} }

@ -9,14 +9,6 @@ import android.util.Log;
import org.json.JSONObject; import org.json.JSONObject;
import cn.jpush.android.data.JPushLocalNotification;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
@ -26,27 +18,23 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import cn.jpush.android.api.JPushInterface; import cn.jpush.android.api.JPushInterface;
import io.flutter.view.FlutterNativeView; import cn.jpush.android.data.JPushLocalNotification;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
/** JPushPlugin */ import io.flutter.plugin.common.MethodCall;
public class JPushPlugin implements MethodCallHandler { import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
/** Plugin registration. */ /**
public static void registerWith(Registrar registrar) { * JPushPlugin
final MethodChannel channel = new MethodChannel(registrar.messenger(), "jpush"); */
channel.setMethodCallHandler(new JPushPlugin(registrar, channel)); public class JPushPlugin implements FlutterPlugin, MethodCallHandler {
registrar.addViewDestroyListener(new PluginRegistry.ViewDestroyListener() {
@Override
public boolean onViewDestroy(FlutterNativeView flutterNativeView) {
instance.dartIsReady = false;
return false;
}
});
}
private static String TAG = "| JPUSH | Flutter | Android | "; private static String TAG = "| JPUSH | Flutter | Android | ";
public static JPushPlugin instance; public static JPushPlugin instance;
static List<Map<String, Object>> openNotificationCache = new ArrayList<>(); static List<Map<String, Object>> openNotificationCache = new ArrayList<>();
private boolean dartIsReady = false; private boolean dartIsReady = false;
@ -54,26 +42,36 @@ public class JPushPlugin implements MethodCallHandler {
private List<Result> getRidCache; private List<Result> getRidCache;
private final Registrar registrar; private Context context;
private final MethodChannel channel; private MethodChannel channel;
public final Map<Integer, Result> callbackMap; public Map<Integer, Result> callbackMap;
private int sequence; private int sequence;
private JPushPlugin(Registrar registrar, MethodChannel channel) { public JPushPlugin() {
this.registrar = registrar;
this.channel = channel;
this.callbackMap = new HashMap<>(); this.callbackMap = new HashMap<>();
this.sequence = 0; this.sequence = 0;
this.getRidCache = new ArrayList<>(); this.getRidCache = new ArrayList<>();
instance = this; instance = this;
} }
@Override
public void onAttachedToEngine(FlutterPluginBinding flutterPluginBinding) {
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "jpush");
channel.setMethodCallHandler(this);
context = flutterPluginBinding.getApplicationContext();
}
@Override
public void onDetachedFromEngine(FlutterPluginBinding binding) {
channel.setMethodCallHandler(null);
instance.dartIsReady = false;
}
@Override @Override
public void onMethodCall(MethodCall call, Result result) { public void onMethodCall(MethodCall call, Result result) {
Log.i(TAG,call.method); Log.i(TAG, call.method);
if (call.method.equals("getPlatformVersion")) { if (call.method.equals("getPlatformVersion")) {
result.success("Android " + android.os.Build.VERSION.RELEASE); result.success("Android " + android.os.Build.VERSION.RELEASE);
} else if (call.method.equals("setup")) { } else if (call.method.equals("setup")) {
@ -91,7 +89,8 @@ public class JPushPlugin implements MethodCallHandler {
} else if (call.method.equals("setAlias")) { } else if (call.method.equals("setAlias")) {
setAlias(call, result); setAlias(call, result);
} else if (call.method.equals("deleteAlias")) { } else if (call.method.equals("deleteAlias")) {
deleteAlias(call, result);; deleteAlias(call, result);
;
} else if (call.method.equals("stopPush")) { } else if (call.method.equals("stopPush")) {
stopPush(call, result); stopPush(call, result);
} else if (call.method.equals("resumePush")) { } else if (call.method.equals("resumePush")) {
@ -99,7 +98,7 @@ public class JPushPlugin implements MethodCallHandler {
} else if (call.method.equals("clearAllNotifications")) { } else if (call.method.equals("clearAllNotifications")) {
clearAllNotifications(call, result); clearAllNotifications(call, result);
} else if (call.method.equals("clearNotification")) { } else if (call.method.equals("clearNotification")) {
clearNotification(call,result); clearNotification(call, result);
} else if (call.method.equals("getLaunchAppNotification")) { } else if (call.method.equals("getLaunchAppNotification")) {
getLaunchAppNotification(call, result); getLaunchAppNotification(call, result);
} else if (call.method.equals("getRegistrationID")) { } else if (call.method.equals("getRegistrationID")) {
@ -112,21 +111,20 @@ public class JPushPlugin implements MethodCallHandler {
isNotificationEnabled(call, result); isNotificationEnabled(call, result);
} else if (call.method.equals("openSettingsForNotification")) { } else if (call.method.equals("openSettingsForNotification")) {
openSettingsForNotification(call, result); openSettingsForNotification(call, result);
} } else {
else {
result.notImplemented(); result.notImplemented();
} }
} }
// 主线程再返回数据 // 主线程再返回数据
public void runMainThread(final Map<String,Object> map, final Result result, final String method) { public void runMainThread(final Map<String, Object> map, final Result result, final String method) {
Log.d(TAG,"runMainThread:" + "map = " + map + ",method =" + method); Log.d(TAG, "runMainThread:" + "map = " + map + ",method =" + method);
android.os.Handler handler = new Handler(Looper.getMainLooper()); android.os.Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() { handler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
if (result == null && method != null){ if (result == null && method != null) {
channel.invokeMethod(method,map); channel.invokeMethod(method, map);
} else { } else {
result.success(map); result.success(map);
} }
@ -135,16 +133,16 @@ public class JPushPlugin implements MethodCallHandler {
} }
public void setup(MethodCall call, Result result) { public void setup(MethodCall call, Result result) {
Log.d(TAG,"setup :" + call.arguments); Log.d(TAG, "setup :" + call.arguments);
HashMap<String, Object> map = call.arguments(); HashMap<String, Object> map = call.arguments();
boolean debug = (boolean)map.get("debug"); boolean debug = (boolean) map.get("debug");
JPushInterface.setDebugMode(debug); JPushInterface.setDebugMode(debug);
JPushInterface.init(registrar.context()); // 初始化 JPush JPushInterface.init(context); // 初始化 JPush
String channel = (String)map.get("channel"); String channel = (String) map.get("channel");
JPushInterface.setChannel(registrar.context(), channel); JPushInterface.setChannel(context, channel);
JPushPlugin.instance.dartIsReady = true; JPushPlugin.instance.dartIsReady = true;
@ -153,33 +151,33 @@ public class JPushPlugin implements MethodCallHandler {
} }
public void scheduleCache() { public void scheduleCache() {
Log.d(TAG,"scheduleCache:"); Log.d(TAG, "scheduleCache:");
List<Object> tempList = new ArrayList<Object>(); List<Object> tempList = new ArrayList<Object>();
if (dartIsReady) { if (dartIsReady) {
// try to shedule notifcation cache // try to shedule notifcation cache
List<Map<String, Object>> openNotificationCacheList = JPushPlugin.openNotificationCache; List<Map<String, Object>> openNotificationCacheList = JPushPlugin.openNotificationCache;
for (Map<String, Object> notification: openNotificationCacheList) { for (Map<String, Object> notification : openNotificationCacheList) {
JPushPlugin.instance.channel.invokeMethod("onOpenNotification", notification); JPushPlugin.instance.channel.invokeMethod("onOpenNotification", notification);
tempList.add(notification); tempList.add(notification);
} }
openNotificationCacheList.removeAll(tempList); openNotificationCacheList.removeAll(tempList);
} }
if (registrar == null || registrar.context() == null) { if (context == null) {
Log.d(TAG,"scheduleCacheregister context is nil."); Log.d(TAG, "scheduleCacheregister context is nil.");
return; return;
} }
String rid = JPushInterface.getRegistrationID(registrar.context()); String rid = JPushInterface.getRegistrationID(context);
boolean ridAvailable = rid != null && !rid.isEmpty(); boolean ridAvailable = rid != null && !rid.isEmpty();
if (ridAvailable && dartIsReady) { if (ridAvailable && dartIsReady) {
// try to schedule get rid cache // try to schedule get rid cache
tempList.clear(); tempList.clear();
List<Result> resultList = JPushPlugin.instance.getRidCache; List<Result> resultList = JPushPlugin.instance.getRidCache;
for (Result res: resultList) { for (Result res : resultList) {
Log.d(TAG,"scheduleCache rid = " + rid); Log.d(TAG, "scheduleCache rid = " + rid);
res.success(rid); res.success(rid);
tempList.add(res); tempList.add(res);
} }
@ -188,109 +186,110 @@ public class JPushPlugin implements MethodCallHandler {
} }
public void setTags(MethodCall call, Result result) { public void setTags(MethodCall call, Result result) {
Log.d(TAG,"setTags"); Log.d(TAG, "setTags");
List<String>tagList = call.arguments(); List<String> tagList = call.arguments();
Set<String> tags = new HashSet<>(tagList); Set<String> tags = new HashSet<>(tagList);
sequence += 1; sequence += 1;
callbackMap.put(sequence, result); callbackMap.put(sequence, result);
JPushInterface.setTags(registrar.context(), sequence, tags); JPushInterface.setTags(context, sequence, tags);
} }
public void cleanTags(MethodCall call, Result result) { public void cleanTags(MethodCall call, Result result) {
Log.d(TAG,"cleanTags:"); Log.d(TAG, "cleanTags:");
sequence += 1; sequence += 1;
callbackMap.put(sequence, result); callbackMap.put(sequence, result);
JPushInterface.cleanTags(registrar.context(), sequence); JPushInterface.cleanTags(context, sequence);
} }
public void addTags(MethodCall call, Result result) { public void addTags(MethodCall call, Result result) {
Log.d(TAG,"addTags: " + call.arguments); Log.d(TAG, "addTags: " + call.arguments);
List<String>tagList = call.arguments(); List<String> tagList = call.arguments();
Set<String> tags = new HashSet<>(tagList); Set<String> tags = new HashSet<>(tagList);
sequence += 1; sequence += 1;
callbackMap.put(sequence, result); callbackMap.put(sequence, result);
JPushInterface.addTags(registrar.context(), sequence, tags); JPushInterface.addTags(context, sequence, tags);
} }
public void deleteTags(MethodCall call, Result result) { public void deleteTags(MethodCall call, Result result) {
Log.d(TAG,"deleteTags " + call.arguments); Log.d(TAG, "deleteTags " + call.arguments);
List<String>tagList = call.arguments(); List<String> tagList = call.arguments();
Set<String> tags = new HashSet<>(tagList); Set<String> tags = new HashSet<>(tagList);
sequence += 1; sequence += 1;
callbackMap.put(sequence, result); callbackMap.put(sequence, result);
JPushInterface.deleteTags(registrar.context(), sequence, tags); JPushInterface.deleteTags(context, sequence, tags);
} }
public void getAllTags(MethodCall call, Result result) { public void getAllTags(MethodCall call, Result result) {
Log.d(TAG,"getAllTags "); Log.d(TAG, "getAllTags ");
sequence += 1; sequence += 1;
callbackMap.put(sequence, result); callbackMap.put(sequence, result);
JPushInterface.getAllTags(registrar.context(), sequence); JPushInterface.getAllTags(context, sequence);
} }
public void setAlias(MethodCall call, Result result) { public void setAlias(MethodCall call, Result result) {
Log.d(TAG,"setAlias: " + call.arguments); Log.d(TAG, "setAlias: " + call.arguments);
String alias= call.arguments(); String alias = call.arguments();
sequence += 1; sequence += 1;
callbackMap.put(sequence, result); callbackMap.put(sequence, result);
JPushInterface.setAlias(registrar.context(), sequence, alias); JPushInterface.setAlias(context, sequence, alias);
} }
public void deleteAlias(MethodCall call, Result result) { public void deleteAlias(MethodCall call, Result result) {
Log.d(TAG,"deleteAlias:"); Log.d(TAG, "deleteAlias:");
String alias= call.arguments(); String alias = call.arguments();
sequence += 1; sequence += 1;
callbackMap.put(sequence, result); callbackMap.put(sequence, result);
JPushInterface.deleteAlias(registrar.context(), sequence); JPushInterface.deleteAlias(context, sequence);
} }
public void stopPush(MethodCall call, Result result) { public void stopPush(MethodCall call, Result result) {
Log.d(TAG,"stopPush:"); Log.d(TAG, "stopPush:");
JPushInterface.stopPush(registrar.context()); JPushInterface.stopPush(context);
} }
public void resumePush(MethodCall call, Result result) { public void resumePush(MethodCall call, Result result) {
Log.d(TAG,"resumePush:"); Log.d(TAG, "resumePush:");
JPushInterface.resumePush(registrar.context()); JPushInterface.resumePush(context);
} }
public void clearAllNotifications(MethodCall call, Result result) { public void clearAllNotifications(MethodCall call, Result result) {
Log.d(TAG,"clearAllNotifications: "); Log.d(TAG, "clearAllNotifications: ");
JPushInterface.clearAllNotifications(registrar.context()); JPushInterface.clearAllNotifications(context);
} }
public void clearNotification(MethodCall call, Result result) { public void clearNotification(MethodCall call, Result result) {
Log.d(TAG,"clearNotification: "); Log.d(TAG, "clearNotification: ");
Object id = call.arguments; Object id = call.arguments;
if (id != null) { if (id != null) {
JPushInterface.clearNotificationById(registrar.context(),(int)id); JPushInterface.clearNotificationById(context, (int) id);
} }
} }
public void getLaunchAppNotification(MethodCall call, Result result) { public void getLaunchAppNotification(MethodCall call, Result result) {
Log.d(TAG,""); Log.d(TAG, "");
} }
public void getRegistrationID(MethodCall call, Result result) { public void getRegistrationID(MethodCall call, Result result) {
Log.d(TAG,"getRegistrationID: "); Log.d(TAG, "getRegistrationID: ");
if (registrar == null || registrar.context() == null) { if (context == null) {
Log.d(TAG,"register context is nil."); Log.d(TAG, "register context is nil.");
return; return;
} }
String rid = JPushInterface.getRegistrationID(registrar.context()); String rid = JPushInterface.getRegistrationID(context);
if (rid == null || rid.isEmpty()) { if (rid == null || rid.isEmpty()) {
getRidCache.add(result); getRidCache.add(result);
} else { } else {
@ -300,17 +299,17 @@ public class JPushPlugin implements MethodCallHandler {
public void sendLocalNotification(MethodCall call, Result result) { public void sendLocalNotification(MethodCall call, Result result) {
Log.d(TAG,"sendLocalNotification: " + call.arguments); Log.d(TAG, "sendLocalNotification: " + call.arguments);
try { try {
HashMap<String, Object> map = call.arguments(); HashMap<String, Object> map = call.arguments();
JPushLocalNotification ln = new JPushLocalNotification(); JPushLocalNotification ln = new JPushLocalNotification();
ln.setBuilderId((Integer)map.get("buildId")); ln.setBuilderId((Integer) map.get("buildId"));
ln.setNotificationId((Integer)map.get("id")); ln.setNotificationId((Integer) map.get("id"));
ln.setTitle((String) map.get("title")); ln.setTitle((String) map.get("title"));
ln.setContent((String) map.get("content")); ln.setContent((String) map.get("content"));
HashMap<String, Object> extra = (HashMap<String, Object>)map.get("extra"); HashMap<String, Object> extra = (HashMap<String, Object>) map.get("extra");
if (extra != null) { if (extra != null) {
JSONObject json = new JSONObject(extra); JSONObject json = new JSONObject(extra);
@ -320,39 +319,39 @@ public class JPushPlugin implements MethodCallHandler {
long date = (long) map.get("fireTime"); long date = (long) map.get("fireTime");
ln.setBroadcastTime(date); ln.setBroadcastTime(date);
JPushInterface.addLocalNotification(registrar.context(), ln); JPushInterface.addLocalNotification(context, ln);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
public void setBadge(MethodCall call, Result result) { public void setBadge(MethodCall call, Result result) {
Log.d(TAG,"setBadge: " + call.arguments); Log.d(TAG, "setBadge: " + call.arguments);
HashMap<String, Object> map = call.arguments(); HashMap<String, Object> map = call.arguments();
Object numObject = map.get("badge"); Object numObject = map.get("badge");
if (numObject != null) { if (numObject != null) {
int num = (int)numObject; int num = (int) numObject;
JPushInterface.setBadgeNumber(registrar.context(),num); JPushInterface.setBadgeNumber(context, num);
result.success(true); result.success(true);
} }
} }
/// 检查当前应用的通知开关是否开启 /// 检查当前应用的通知开关是否开启
private void isNotificationEnabled(MethodCall call, Result result) { private void isNotificationEnabled(MethodCall call, Result result) {
Log.d(TAG,"isNotificationEnabled: "); Log.d(TAG, "isNotificationEnabled: ");
int isEnabled = JPushInterface.isNotificationEnabled(registrar.context()); int isEnabled = JPushInterface.isNotificationEnabled(context);
//1表示开启0表示关闭-1表示检测失败 //1表示开启0表示关闭-1表示检测失败
HashMap<String, Object> map = new HashMap(); HashMap<String, Object> map = new HashMap();
map.put("isEnabled",isEnabled==1?true:false); map.put("isEnabled", isEnabled == 1 ? true : false);
runMainThread(map,result,null); runMainThread(map, result, null);
} }
private void openSettingsForNotification(MethodCall call, Result result) { private void openSettingsForNotification(MethodCall call, Result result) {
Log.d(TAG,"openSettingsForNotification: " ); Log.d(TAG, "openSettingsForNotification: ");
JPushInterface.goToAppNotificationSettings(registrar.context()); JPushInterface.goToAppNotificationSettings(context);
} }
@ -369,14 +368,13 @@ public class JPushPlugin implements MethodCallHandler {
} }
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
String action = intent.getAction(); String action = intent.getAction();
if (action.equals(JPushInterface.ACTION_REGISTRATION_ID)) { if (action.equals(JPushInterface.ACTION_REGISTRATION_ID)) {
String rId = intent.getStringExtra(JPushInterface.EXTRA_REGISTRATION_ID); String rId = intent.getStringExtra(JPushInterface.EXTRA_REGISTRATION_ID);
Log.d("JPushPlugin","on get registration"); Log.d("JPushPlugin", "on get registration");
JPushPlugin.transmitReceiveRegistrationId(rId); JPushPlugin.transmitReceiveRegistrationId(rId);
} else if (action.equals(JPushInterface.ACTION_MESSAGE_RECEIVED)) { } else if (action.equals(JPushInterface.ACTION_MESSAGE_RECEIVED)) {
@ -389,7 +387,7 @@ public class JPushPlugin implements MethodCallHandler {
} }
private void handlingMessageReceive(Intent intent) { private void handlingMessageReceive(Intent intent) {
Log.d(TAG,"handlingMessageReceive " + intent.getAction()); Log.d(TAG, "handlingMessageReceive " + intent.getAction());
String msg = intent.getStringExtra(JPushInterface.EXTRA_MESSAGE); String msg = intent.getStringExtra(JPushInterface.EXTRA_MESSAGE);
Map<String, Object> extras = getNotificationExtras(intent); Map<String, Object> extras = getNotificationExtras(intent);
@ -397,7 +395,7 @@ public class JPushPlugin implements MethodCallHandler {
} }
private void handlingNotificationOpen(Context context, Intent intent) { private void handlingNotificationOpen(Context context, Intent intent) {
Log.d(TAG,"handlingNotificationOpen " + intent.getAction()); Log.d(TAG, "handlingNotificationOpen " + intent.getAction());
String title = intent.getStringExtra(JPushInterface.EXTRA_NOTIFICATION_TITLE); String title = intent.getStringExtra(JPushInterface.EXTRA_NOTIFICATION_TITLE);
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT); String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
@ -413,7 +411,7 @@ public class JPushPlugin implements MethodCallHandler {
} }
private void handlingNotificationReceive(Context context, Intent intent) { private void handlingNotificationReceive(Context context, Intent intent) {
Log.d(TAG,"handlingNotificationReceive " + intent.getAction()); Log.d(TAG, "handlingNotificationReceive " + intent.getAction());
String title = intent.getStringExtra(JPushInterface.EXTRA_NOTIFICATION_TITLE); String title = intent.getStringExtra(JPushInterface.EXTRA_NOTIFICATION_TITLE);
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT); String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
@ -422,7 +420,7 @@ public class JPushPlugin implements MethodCallHandler {
} }
private Map<String, Object> getNotificationExtras(Intent intent) { private Map<String, Object> getNotificationExtras(Intent intent) {
Log.d(TAG,""); Log.d(TAG, "");
Map<String, Object> extrasMap = new HashMap<String, Object>(); Map<String, Object> extrasMap = new HashMap<String, Object>();
for (String key : intent.getExtras().keySet()) { for (String key : intent.getExtras().keySet()) {
@ -440,12 +438,12 @@ public class JPushPlugin implements MethodCallHandler {
static void transmitMessageReceive(String message, Map<String, Object> extras) { static void transmitMessageReceive(String message, Map<String, Object> extras) {
Log.d(TAG,"transmitMessageReceive " + "message=" + message + "extras=" + extras); Log.d(TAG, "transmitMessageReceive " + "message=" + message + "extras=" + extras);
if (instance == null) { if (instance == null) {
return; return;
} }
Map<String, Object> msg= new HashMap<>(); Map<String, Object> msg = new HashMap<>();
msg.put("message", message); msg.put("message", message);
msg.put("extras", extras); msg.put("extras", extras);
@ -453,9 +451,9 @@ public class JPushPlugin implements MethodCallHandler {
} }
static void transmitNotificationOpen(String title, String alert, Map<String, Object> extras) { static void transmitNotificationOpen(String title, String alert, Map<String, Object> extras) {
Log.d(TAG,"transmitNotificationOpen " + "title=" + title + "alert=" + alert + "extras=" + extras); Log.d(TAG, "transmitNotificationOpen " + "title=" + title + "alert=" + alert + "extras=" + extras);
Map<String, Object> notification= new HashMap<>(); Map<String, Object> notification = new HashMap<>();
notification.put("title", title); notification.put("title", title);
notification.put("alert", alert); notification.put("alert", alert);
notification.put("extras", extras); notification.put("extras", extras);
@ -475,13 +473,13 @@ public class JPushPlugin implements MethodCallHandler {
} }
static void transmitNotificationReceive(String title, String alert, Map<String, Object> extras) { static void transmitNotificationReceive(String title, String alert, Map<String, Object> extras) {
Log.d(TAG,"transmitNotificationReceive " + "title=" + title + "alert=" + alert + "extras=" + extras); Log.d(TAG, "transmitNotificationReceive " + "title=" + title + "alert=" + alert + "extras=" + extras);
if (instance == null) { if (instance == null) {
return; return;
} }
Map<String, Object> notification= new HashMap<>(); Map<String, Object> notification = new HashMap<>();
notification.put("title", title); notification.put("title", title);
notification.put("alert", alert); notification.put("alert", alert);
notification.put("extras", extras); notification.put("extras", extras);
@ -489,7 +487,7 @@ public class JPushPlugin implements MethodCallHandler {
} }
static void transmitReceiveRegistrationId(String rId) { static void transmitReceiveRegistrationId(String rId) {
Log.d(TAG,"transmitReceiveRegistrationId " + rId); Log.d(TAG, "transmitReceiveRegistrationId " + rId);
if (instance == null) { if (instance == null) {
return; return;

@ -28,12 +28,27 @@
there is no splash screen (such as the default splash screen there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). --> defined in @style/LaunchTheme). -->
<meta-data <meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame" android:name="io.flutter.embedding.android.NormalTheme"
android:value="true" /> android:resource="@style/NormalTheme"
/>
<!-- Displays an Android View that continues showing the launch screen
Drawable until Flutter paints its first frame, then this splash
screen fades out. A splash screen is useful to avoid any visual
gap between the end of Android's launch screen and the painting of
Flutter's first frame. -->
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
/>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter> </intent-filter>
</activity> </activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application> </application>
</manifest> </manifest>

@ -1,13 +1,6 @@
package com.jiguang.jpushexample; package com.jiguang.jpushexample;
import android.os.Bundle; import io.flutter.embedding.android.FlutterActivity;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity { public class MainActivity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
} }

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>

@ -1,8 +1,18 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar"> <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when <!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame --> Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item> <item name="android:windowBackground">@drawable/launch_background</item>
</style> </style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources> </resources>

@ -336,14 +336,13 @@ class CustomButton extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new FlatButton( return new TextButton(
onPressed: onPressed, onPressed: onPressed,
child: new Text("$title"), child: new Text("$title"),
color: Color(0xff585858), style: new ButtonStyle(foregroundColor: MaterialStateProperty.all(Colors.white),
highlightColor: Color(0xff888888), overlayColor: MaterialStateProperty.all(Color(0xff888888)),
splashColor: Color(0xff888888), backgroundColor: MaterialStateProperty.all(Color(0xff585858)),
textColor: Colors.white, padding: MaterialStateProperty.all(EdgeInsets.fromLTRB(10, 5, 10, 5)), ),
//padding: EdgeInsets.fromLTRB(5, 5, 5, 5),
); );
} }
} }

@ -6,7 +6,7 @@ import 'package:platform/platform.dart';
typedef Future<dynamic> EventHandler(Map<String, dynamic> event); typedef Future<dynamic> EventHandler(Map<String, dynamic> event);
class JPush { class JPush {
final String flutter_log = "| JPUSH | Flutter | "; static const String flutter_log = "| JPUSH | Flutter | ";
factory JPush() => _instance; factory JPush() => _instance;
final MethodChannel _channel; final MethodChannel _channel;

@ -1,6 +1,6 @@
name: jpush_flutter name: jpush_flutter
description: JIGUANG officially supported JPush Flutter plugin (Android & iOS). 极光推送官方支持的 Flutter 插件Android & iOS(https://www.jiguang.cn). description: JIGUANG officially supported JPush Flutter plugin (Android & iOS). 极光推送官方支持的 Flutter 插件Android & iOS(https://www.jiguang.cn).
version: 0.6.3 version: 2.0.1
# author: xudong.rao <xudong.rao@outlook.com> # author: xudong.rao <xudong.rao@outlook.com>
homepage: https://www.jiguang.cn homepage: https://www.jiguang.cn
@ -9,13 +9,13 @@ environment:
flutter: ">=1.10.0" flutter: ">=1.10.0"
dependencies: dependencies:
platform: ^2.0.0 platform: ^3.0.0
flutter: flutter:
sdk: flutter sdk: flutter
dev_dependencies: dev_dependencies:
test: ^1.3.0 test: ^1.16.8
mockito: ^3.0.0 mockito: ^5.0.2
# For information on the generic Dart part of this file, see the # For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec # following page: https://www.dartlang.org/tools/pub/pubspec

Loading…
Cancel
Save