Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
RvApp
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lify
RvApp
Commits
2bb34864
Commit
2bb34864
authored
Sep 07, 2019
by
linfeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
推送
parent
4f93c399
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
247 additions
and
4 deletions
+247
-4
build.gradle
RvClient/build.gradle
+10
-1
AndroidManifest.xml
RvClient/src/main/AndroidManifest.xml
+41
-3
RvClientApplication.java
RvClient/src/main/java/com/xxfc/rv/RvClientApplication.java
+5
-0
MyJPushMessageReceiver.java
...c/main/java/com/xxfc/rv/other/MyJPushMessageReceiver.java
+77
-0
MyReceiver.java
RvClient/src/main/java/com/xxfc/rv/other/MyReceiver.java
+107
-0
PushService.java
RvClient/src/main/java/com/xxfc/rv/other/PushService.java
+7
-0
No files found.
RvClient/build.gradle
View file @
2bb34864
...
...
@@ -13,7 +13,7 @@ android {
multiDexEnabled
true
ndk
{
abiFilters
"armeabi"
,
"armeabi-v7a"
,
"x86"
,
"mips"
abiFilters
"armeabi"
,
"armeabi-v7a"
,
"x86"
,
"mips"
,
'arm64-v8a'
}
//新版Gradle 是 implementation 为了兼容compile,写上这句话
javaCompileOptions
{
...
...
@@ -22,6 +22,13 @@ android {
}
}
manifestPlaceholders
=
[
JPUSH_PKGNAME
:
appId
,
JPUSH_APPKEY
:
"530b223034b92715e0295047"
,
//JPush 上注册的包名对应的 Appkey.
JPUSH_CHANNEL
:
"developer-default"
,
//暂时填写默认值即可.
]
// javaCompileOptions {
//
// annotationProcessorOptions {
...
...
@@ -111,6 +118,8 @@ dependencies {
debugApi
'com.squareup.leakcanary:leakcanary-android:1.6.1'
releaseApi
'com.squareup.leakcanary:leakcanary-android-no-op:1.6.1'
api
'cn.jiguang.sdk:jpush:3.3.4'
// 此处以JPush 3.3.4 版本为例。
api
'cn.jiguang.sdk:jcore:2.1.2'
// 此处以JCore 2.1.2 版本为例。
// api project(path: ':RvTravel')
api
project
(
':component_resource'
)
...
...
RvClient/src/main/AndroidManifest.xml
View file @
2bb34864
...
...
@@ -129,7 +129,8 @@
android:enabled=
"true"
android:process=
":remote"
/>
<service
android:name=
"com.tencent.smtt.export.external.DexClassLoaderProviderService"
<service
android:name=
"com.tencent.smtt.export.external.DexClassLoaderProviderService"
android:label=
"dexopt"
android:process=
":dexopt"
/>
...
...
@@ -188,8 +189,8 @@
<activity
android:name=
".MainActivity"
android:
screenOrientation=
"portrait
"
android:
launchMode=
"singleTask
"
/>
android:
launchMode=
"singleTask
"
android:
screenOrientation=
"portrait
"
/>
<activity
android:name=
"com.rv.home.rv.module.ui.login.LoginRvActivity"
android:screenOrientation=
"portrait"
/>
...
...
@@ -387,6 +388,43 @@
</intent-filter>
</activity>
<activity
android:name=
".GuideActivity"
></activity>
<!--======================================== 极光 ==============================================================-->
<!-- Since JCore2.0.0 Required SDK核心功能-->
<!-- 这个Service要继承JCommonService -->
<service
android:name=
".other.PushService"
android:process=
":pushcore"
>
<intent-filter>
<action
android:name=
"cn.jiguang.user.service.action"
/>
</intent-filter>
</service>
<!-- User defined. For test only 用户自定义接收消息器,3.0.7开始支持,目前新tag/alias接口设置结果会在该广播接收器对应的方法中回调-->
<receiver
android:name=
".other.MyJPushMessageReceiver"
>
<intent-filter>
<action
android:name=
"cn.jpush.android.intent.RECEIVE_MESSAGE"
/>
<category
android:name=
"com.xxfc.rv"
></category>
</intent-filter>
</receiver>
<!-- User defined. For test only 用户自定义的广播接收器-->
<receiver
android:name=
".other.MyReceiver"
android:enabled=
"true"
android:exported=
"false"
>
<intent-filter>
<action
android:name=
"cn.jpush.android.intent.REGISTRATION"
/>
<!--Required 用户注册SDK的intent-->
<action
android:name=
"cn.jpush.android.intent.MESSAGE_RECEIVED"
/>
<!--Required 用户接收SDK消息的intent-->
<action
android:name=
"cn.jpush.android.intent.NOTIFICATION_RECEIVED"
/>
<!--Required 用户接收SDK通知栏信息的intent-->
<action
android:name=
"cn.jpush.android.intent.NOTIFICATION_OPENED"
/>
<!--Required 用户打开自定义通知栏的intent-->
<action
android:name=
"cn.jpush.android.intent.CONNECTION"
/>
<!-- 接收网络变化 连接/断开 since 1.6.3 -->
<category
android:name=
"com.xxfc.rv"
/>
</intent-filter>
</receiver>
<!--===========================================================================================================-->
</application>
</manifest>
\ No newline at end of file
RvClient/src/main/java/com/xxfc/rv/RvClientApplication.java
View file @
2bb34864
...
...
@@ -34,6 +34,7 @@ import com.yuyife.okgo.OkGoUtil;
import
java.util.HashMap
;
import
java.util.Locale
;
import
cn.jpush.android.api.JPushInterface
;
import
cn.pedant.SweetAlert.SweetAlertDialog
;
import
me.jessyan.autosize.AutoSize
;
import
me.jessyan.autosize.AutoSizeConfig
;
...
...
@@ -107,6 +108,10 @@ public class RvClientApplication extends FrameApp {
}
ARouter
.
init
(
RvClientApplication
.
this
);
JPushInterface
.
setDebugMode
(
true
);
JPushInterface
.
init
(
this
);
/**********************内存检测****************************/
/* if (LeakCanary.isInAnalyzerProcess(this)) {
// This process is dedicated to LeakCanary for heap analysis.
...
...
RvClient/src/main/java/com/xxfc/rv/other/MyJPushMessageReceiver.java
0 → 100644
View file @
2bb34864
package
com
.
xxfc
.
rv
.
other
;
import
android.content.Context
;
import
android.util.Log
;
import
cn.jpush.android.api.CustomMessage
;
import
cn.jpush.android.api.JPushMessage
;
import
cn.jpush.android.api.NotificationMessage
;
import
cn.jpush.android.service.JPushMessageReceiver
;
/**
* 自定义JPush message 接收器,包括操作tag/alias的结果返回(仅仅包含tag/alias新接口部分)
* */
public
class
MyJPushMessageReceiver
extends
JPushMessageReceiver
{
private
static
final
String
TAG
=
"JIGUANG"
;
/**
* TODO 连接极光服务器
*/
@Override
public
void
onConnected
(
Context
context
,
boolean
b
)
{
super
.
onConnected
(
context
,
b
);
Log
.
e
(
TAG
,
"onConnected"
);
}
/**
* TODO 注册极光时的回调
*/
@Override
public
void
onRegister
(
Context
context
,
String
s
)
{
super
.
onRegister
(
context
,
s
);
Log
.
e
(
TAG
,
"onRegister"
+
s
);
}
/**
* TODO 注册以及解除注册别名时回调
*/
@Override
public
void
onAliasOperatorResult
(
Context
context
,
JPushMessage
jPushMessage
)
{
super
.
onAliasOperatorResult
(
context
,
jPushMessage
);
Log
.
e
(
TAG
,
jPushMessage
.
toString
());
}
/**
* TODO 接收到推送下来的通知
* 可以利用附加字段(notificationMessage.notificationExtras)来区别Notication,指定不同的动作,附加字段是个json字符串
* 通知(Notification),指在手机的通知栏(状态栏)上会显示的一条通知信息
*/
@Override
public
void
onNotifyMessageArrived
(
Context
context
,
NotificationMessage
notificationMessage
)
{
super
.
onNotifyMessageArrived
(
context
,
notificationMessage
);
Log
.
e
(
TAG
,
notificationMessage
.
toString
());
}
/**
* TODO 打开了通知
* notificationMessage.notificationExtras(附加字段)的内容处理代码
* 比如打开新的Activity, 打开一个网页等..
*/
@Override
public
void
onNotifyMessageOpened
(
Context
context
,
NotificationMessage
notificationMessage
)
{
super
.
onNotifyMessageOpened
(
context
,
notificationMessage
);
Log
.
e
(
TAG
,
notificationMessage
.
notificationExtras
);
}
/**
* TODO 接收到推送下来的自定义消息
* 自定义消息不是通知,默认不会被SDK展示到通知栏上,极光推送仅负责透传给SDK。其内容和展示形式完全由开发者自己定义。
* 自定义消息主要用于应用的内部业务逻辑和特殊展示需求
*/
@Override
public
void
onMessage
(
Context
context
,
CustomMessage
customMessage
)
{
super
.
onMessage
(
context
,
customMessage
);
Log
.
e
(
TAG
,
"onMessage"
);
}
}
RvClient/src/main/java/com/xxfc/rv/other/MyReceiver.java
0 → 100644
View file @
2bb34864
package
com
.
xxfc
.
rv
.
other
;
import
android.content.BroadcastReceiver
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
com.xxfc.rv.MainActivity
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
java.util.Iterator
;
import
cn.jpush.android.api.JPushInterface
;
/**
* 自定义接收器
*
* 如果不定义这个 Receiver,则:
* 1) 默认用户会打开主界面
* 2) 接收不到自定义消息
*/
public
class
MyReceiver
extends
BroadcastReceiver
{
private
static
final
String
TAG
=
"JIGUANG-Example"
;
@Override
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
try
{
Bundle
bundle
=
intent
.
getExtras
();
Log
.
d
(
TAG
,
"[MyReceiver] onReceive - "
+
intent
.
getAction
()
+
", extras: "
+
printBundle
(
bundle
));
if
(
JPushInterface
.
ACTION_REGISTRATION_ID
.
equals
(
intent
.
getAction
()))
{
String
regId
=
bundle
.
getString
(
JPushInterface
.
EXTRA_REGISTRATION_ID
);
Log
.
d
(
TAG
,
"[MyReceiver] 接收Registration Id : "
+
regId
);
//send the Registration Id to your server...
}
else
if
(
JPushInterface
.
ACTION_MESSAGE_RECEIVED
.
equals
(
intent
.
getAction
()))
{
Log
.
d
(
TAG
,
"[MyReceiver] 接收到推送下来的自定义消息: "
+
bundle
.
getString
(
JPushInterface
.
EXTRA_MESSAGE
));
}
else
if
(
JPushInterface
.
ACTION_NOTIFICATION_RECEIVED
.
equals
(
intent
.
getAction
()))
{
Log
.
d
(
TAG
,
"[MyReceiver] 接收到推送下来的通知"
);
int
notifactionId
=
bundle
.
getInt
(
JPushInterface
.
EXTRA_NOTIFICATION_ID
);
Log
.
d
(
TAG
,
"[MyReceiver] 接收到推送下来的通知的ID: "
+
notifactionId
);
}
else
if
(
JPushInterface
.
ACTION_NOTIFICATION_OPENED
.
equals
(
intent
.
getAction
()))
{
Log
.
d
(
TAG
,
"[MyReceiver] 用户点击打开了通知"
);
// //打开自定义的Activity
// Intent i = new Intent(context, TestActivity.class);
// i.putExtras(bundle);
// //i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP );
// context.startActivity(i);
}
else
if
(
JPushInterface
.
ACTION_RICHPUSH_CALLBACK
.
equals
(
intent
.
getAction
()))
{
Log
.
d
(
TAG
,
"[MyReceiver] 用户收到到RICH PUSH CALLBACK: "
+
bundle
.
getString
(
JPushInterface
.
EXTRA_EXTRA
));
//在这里根据 JPushInterface.EXTRA_EXTRA 的内容处理代码,比如打开新的Activity, 打开一个网页等..
}
else
if
(
JPushInterface
.
ACTION_CONNECTION_CHANGE
.
equals
(
intent
.
getAction
()))
{
boolean
connected
=
intent
.
getBooleanExtra
(
JPushInterface
.
EXTRA_CONNECTION_CHANGE
,
false
);
Log
.
w
(
TAG
,
"[MyReceiver]"
+
intent
.
getAction
()
+
" connected state change to "
+
connected
);
}
else
{
Log
.
d
(
TAG
,
"[MyReceiver] Unhandled intent - "
+
intent
.
getAction
());
}
}
catch
(
Exception
e
){
}
}
// 打印所有的 intent extra 数据
private
static
String
printBundle
(
Bundle
bundle
)
{
StringBuilder
sb
=
new
StringBuilder
();
for
(
String
key
:
bundle
.
keySet
())
{
if
(
key
.
equals
(
JPushInterface
.
EXTRA_NOTIFICATION_ID
))
{
sb
.
append
(
"\nkey:"
+
key
+
", value:"
+
bundle
.
getInt
(
key
));
}
else
if
(
key
.
equals
(
JPushInterface
.
EXTRA_CONNECTION_CHANGE
)){
sb
.
append
(
"\nkey:"
+
key
+
", value:"
+
bundle
.
getBoolean
(
key
));
}
else
if
(
key
.
equals
(
JPushInterface
.
EXTRA_EXTRA
))
{
if
(
TextUtils
.
isEmpty
(
bundle
.
getString
(
JPushInterface
.
EXTRA_EXTRA
)))
{
Log
.
i
(
TAG
,
"This message has no Extra data"
);
continue
;
}
try
{
JSONObject
json
=
new
JSONObject
(
bundle
.
getString
(
JPushInterface
.
EXTRA_EXTRA
));
Iterator
<
String
>
it
=
json
.
keys
();
while
(
it
.
hasNext
())
{
String
myKey
=
it
.
next
();
sb
.
append
(
"\nkey:"
+
key
+
", value: ["
+
myKey
+
" - "
+
json
.
optString
(
myKey
)
+
"]"
);
}
}
catch
(
JSONException
e
)
{
Log
.
e
(
TAG
,
"Get message extra JSON error!"
);
}
}
else
{
sb
.
append
(
"\nkey:"
+
key
+
", value:"
+
bundle
.
get
(
key
));
}
}
return
sb
.
toString
();
}
}
RvClient/src/main/java/com/xxfc/rv/other/PushService.java
0 → 100644
View file @
2bb34864
package
com
.
xxfc
.
rv
.
other
;
import
cn.jpush.android.service.JCommonService
;
public
class
PushService
extends
JCommonService
{
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment