Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
F
flutter-push
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
openSourceLibrary
flutter-push
Commits
66dfeb53
提交
66dfeb53
authored
12月 14, 2022
作者:
张国庆
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改推送插件
上级
b890cc7b
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
40 行增加
和
70 行删除
+40
-70
.gitignore
.gitignore
+1
-0
.gitignore
android/.gitignore
+2
-0
RammusPlugin.kt
android/src/main/kotlin/com/jarvanmo/rammus/RammusPlugin.kt
+37
-22
widget_test.dart
example/test/widget_test.dart
+0
-27
rammus_test.dart
test/rammus_test.dart
+0
-21
没有找到文件。
.gitignore
浏览文件 @
66dfeb53
...
...
@@ -11,3 +11,4 @@ build/
*.iml
*.lock
/android/gradlew.bat
android/.gitignore
浏览文件 @
66dfeb53
...
...
@@ -6,3 +6,5 @@
.DS_Store
/build
/captures
/gradle/
/gradlew
android/src/main/kotlin/com/jarvanmo/rammus/RammusPlugin.kt
浏览文件 @
66dfeb53
...
...
@@ -10,29 +10,28 @@ import android.content.Context
import
android.content.pm.PackageManager
import
android.os.Build
import
android.os.Handler
import
android.os.Looper
import
android.util.Log
import
com.alibaba.sdk.android.push.CommonCallback
import
com.alibaba.sdk.android.push.HonorRegister
import
com.alibaba.sdk.android.push.huawei.HuaWeiRegister
import
com.alibaba.sdk.android.push.noonesdk.PushServiceFactory
import
com.alibaba.sdk.android.push.register.*
import
io.flutter.embedding.engine.plugins.FlutterPlugin
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.Registrar
class
RammusPlugin
(
private
val
registrar
:
Registrar
,
private
val
methodChannel
:
MethodChannel
)
:
MethodCallHandler
{
class
RammusPlugin
:
FlutterPlugin
,
MethodCallHandler
{
companion
object
{
private
const
val
TAG
=
"RammusPlugin"
private
val
inHandler
=
Handler
()
private
val
inHandler
=
Handler
(
Looper
.
getMainLooper
()
)
private
var
gottenApplication
:
Application
?
=
null
@JvmStatic
fun
registerWith
(
registrar
:
Registrar
)
{
val
channel
=
MethodChannel
(
registrar
.
messenger
(),
"com.jarvanmo/rammus"
)
RammusPushHandler
.
methodChannel
=
channel
channel
.
setMethodCallHandler
(
RammusPlugin
(
registrar
,
channel
))
}
@JvmStatic
fun
initPushService
(
application
:
Application
){
gottenApplication
=
application
...
...
@@ -41,6 +40,7 @@ class RammusPlugin(private val registrar: Registrar, private val methodChannel:
pushService
.
setPushIntentService
(
RammusPushIntentService
::
class
.
java
)
}
}
private
lateinit
var
channel
:
MethodChannel
override
fun
onMethodCall
(
call
:
MethodCall
,
result
:
Result
)
{
when
(
call
.
method
)
{
...
...
@@ -69,10 +69,10 @@ class RammusPlugin(private val registrar: Registrar, private val methodChannel:
private
fun
register
()
{
if
(
gottenApplication
==
null
)
{
Log
.
w
(
TAG
,
"注册推送服务失败,请检查是否在运行本语句前执行了`RammusPlugin.initPushService`."
)
return
;
return
}
val
pushService
=
PushServiceFactory
.
getCloudPushService
()
pushService
.
register
(
gottenApplication
!!
.
applicationContext
,
object
:
CommonCallback
{
pushService
.
register
(
gottenApplication
,
object
:
CommonCallback
{
override
fun
onSuccess
(
response
:
String
?)
{
inHandler
.
postDelayed
({
RammusPushHandler
.
methodChannel
?.
invokeMethod
(
"initCloudChannelResult"
,
mapOf
(
...
...
@@ -99,26 +99,31 @@ class RammusPlugin(private val registrar: Registrar, private val methodChannel:
if
((
xiaomiAppId
!=
null
&&
xiaomiAppId
.
isNotBlank
())
&&
(
xiaomiAppKey
!=
null
&&
xiaomiAppKey
.
isNotBlank
())){
Log
.
d
(
TAG
,
"正在注册小米推送服务..."
)
MiPushRegister
.
register
(
gottenApplication
!!
.
applicationContext
,
xiaomiAppId
,
xiaomiAppKey
)
MiPushRegister
.
register
(
gottenApplication
,
xiaomiAppId
,
xiaomiAppKey
)
}
val
huaweiAppId
=
appInfo
.
metaData
.
getString
(
"com.huawei.hms.client.appid"
)
if
(
huaweiAppId
!=
null
&&
huaweiAppId
.
toString
().
isNotBlank
()){
Log
.
d
(
TAG
,
"正在注册华为推送服务..."
)
HuaWeiRegister
.
register
(
gottenApplication
!!
)
HuaWeiRegister
.
register
(
gottenApplication
)
}
val
oppoAppKey
=
appInfo
.
metaData
.
getString
(
"com.oppo.push.client.app_key"
)
val
oppoAppSecret
=
appInfo
.
metaData
.
getString
(
"com.oppo.push.client.app_secret"
)
if
((
oppoAppKey
!=
null
&&
oppoAppKey
.
isNotBlank
())
&&
(
oppoAppSecret
!=
null
&&
oppoAppSecret
.
isNotBlank
())){
Log
.
d
(
TAG
,
"正在注册Oppo推送服务..."
)
OppoRegister
.
register
(
gottenApplication
!!
.
applicationContext
,
oppoAppKey
,
oppoAppSecret
)
OppoRegister
.
register
(
gottenApplication
,
oppoAppKey
,
oppoAppSecret
)
}
val
vivoAppId
=
appInfo
.
metaData
.
getString
(
"com.vivo.push.app_id"
)
val
vivoApiKey
=
appInfo
.
metaData
.
getString
(
"com.vivo.push.api_key"
)
if
((
vivoAppId
!=
null
&&
vivoAppId
.
isNotBlank
())
&&
(
vivoApiKey
!=
null
&&
vivoApiKey
.
isNotBlank
())){
Log
.
d
(
TAG
,
"正在注册Vivo推送服务..."
)
VivoRegister
.
register
(
gottenApplication
!!
.
applicationContext
)
VivoRegister
.
register
(
gottenApplication
)
}
val
hihonorId
=
appInfo
.
metaData
.
getString
(
"com.hihonor.push.app_id"
)
if
(
hihonorId
!=
null
&&
hihonorId
.
toString
().
isNotBlank
()){
Log
.
d
(
TAG
,
"正在注册荣耀推送服务..."
)
HonorRegister
.
register
(
gottenApplication
)
}
}
...
...
@@ -431,15 +436,15 @@ class RammusPlugin(private val registrar: Registrar, private val methodChannel:
private
fun
setupNotificationManager
(
call
:
MethodCall
,
result
:
Result
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
val
channels
=
call
.
arguments
as
List
<
Map
<
String
,
Any
?>>
val
mNotificationManager
=
registrar
.
context
()
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
)
as
NotificationManager
val
mNotificationManager
=
gottenApplication
?
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
)
as
NotificationManager
val
notificationChannels
=
mutableListOf
<
NotificationChannel
>()
for
(
channel
in
channels
){
// 通知渠道的id
val
id
=
channel
[
"id"
]
?:
registrar
.
context
()
.
packageName
val
id
=
channel
[
"id"
]
?:
gottenApplication
?
.
packageName
// 用户可以看到的通知渠道的名字.
val
name
=
channel
[
"name"
]
?:
registrar
.
context
()
.
packageName
val
name
=
channel
[
"name"
]
?:
gottenApplication
?
.
packageName
// 用户可以看到的通知渠道的描述
val
description
=
channel
[
"description"
]
?:
registrar
.
context
()
.
packageName
val
description
=
channel
[
"description"
]
?:
gottenApplication
?
.
packageName
val
importance
=
channel
[
"importance"
]
?:
NotificationManager
.
IMPORTANCE_DEFAULT
val
mChannel
=
NotificationChannel
(
id
as
String
,
name
as
String
,
importance
as
Int
)
// 配置通知渠道的属性
...
...
@@ -460,7 +465,7 @@ class RammusPlugin(private val registrar: Registrar, private val methodChannel:
val
appInfo
=
gottenApplication
!!
.
packageManager
.
getApplicationInfo
(
gottenApplication
!!
.
packageName
,
PackageManager
.
GET_META_DATA
)
va
r
num
=
call
.
argument
(
"num"
)
as
Int
?
?:
0
va
l
num
=
call
.
argument
(
"num"
)
as
Int
?
?:
0
setHuaWeiApplicationBadgeNumber
(
num
,
appInfo
)
}
...
...
@@ -471,8 +476,8 @@ class RammusPlugin(private val registrar: Registrar, private val methodChannel:
if
(
huaweiAppId
!=
null
&&
huaweiAppId
.
toString
().
isNotBlank
()){
try
{
val
bundle
=
Bundle
()
bundle
.
putString
(
"package"
,
registrar
.
context
()
.
packageName
)
// com.test.badge is your package name
bundle
.
putString
(
"class"
,
registrar
.
context
()
.
packageName
+
".MainActivity"
)
// com.test. badge.MainActivity is your apk main activity
bundle
.
putString
(
"package"
,
gottenApplication
?
.
packageName
)
// com.test.badge is your package name
bundle
.
putString
(
"class"
,
gottenApplication
?
.
packageName
+
".MainActivity"
)
// com.test. badge.MainActivity is your apk main activity
bundle
.
putInt
(
"badgenumber"
,
num
)
gottenApplication
!!
.
contentResolver
.
call
(
Uri
.
parse
(
"content://com.huawei.android.launcher.settings/badge/"
),
"change_badge"
,
null
,
bundle
)
...
...
@@ -483,4 +488,14 @@ class RammusPlugin(private val registrar: Registrar, private val methodChannel:
}
override
fun
onAttachedToEngine
(
flutterPluginBinding
:
FlutterPlugin
.
FlutterPluginBinding
)
{
channel
=
MethodChannel
(
flutterPluginBinding
.
binaryMessenger
,
"com.jarvanmo/rammus"
)
channel
.
setMethodCallHandler
(
this
)
}
override
fun
onDetachedFromEngine
(
binding
:
FlutterPlugin
.
FlutterPluginBinding
)
{
channel
.
setMethodCallHandler
(
null
)
}
}
example/test/widget_test.dart
deleted
100644 → 0
浏览文件 @
b890cc7b
// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility that Flutter provides. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import
'package:flutter/material.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:rammus_example/main.dart'
;
void
main
(
)
{
testWidgets
(
'Verify Platform version'
,
(
WidgetTester
tester
)
async
{
// Build our app and trigger a frame.
await
tester
.
pumpWidget
(
MyApp
());
// Verify that platform version is retrieved.
expect
(
find
.
byWidgetPredicate
(
(
Widget
widget
)
=>
widget
is
Text
&&
widget
.
data
!.
startsWith
(
'Running on:'
),
),
findsOneWidget
,
);
});
}
test/rammus_test.dart
deleted
100644 → 0
浏览文件 @
b890cc7b
import
'package:flutter/services.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:rammus/rammus.dart'
;
void
main
(
)
{
const
MethodChannel
channel
=
MethodChannel
(
'rammus'
);
setUp
(()
{
channel
.
setMockMethodCallHandler
((
MethodCall
methodCall
)
async
{
return
'42'
;
});
});
tearDown
(()
{
channel
.
setMockMethodCallHandler
(
null
);
});
test
(
'getPlatformVersion'
,
()
async
{
// expect(await Rammus.platformVersion, '42');
});
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论