Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
polysoft-nafmii
/
polysoft-android
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit e07f9982
authored
Nov 03, 2021
by
amateur
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
1
1 parent
526e99b2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
126 additions
and
2 deletions
app/src/main/java/com/polysoft/nafmii/jpush/JPushReceiver.java
app/src/main/java/com/whaty/nafmii/activity/MainActivity.java
app/src/main/java/com/polysoft/nafmii/jpush/JPushReceiver.java
View file @
e07f998
...
...
@@ -2,10 +2,19 @@ package com.polysoft.nafmii.jpush;
import
android.content.Context
;
import
android.content.Intent
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
com.alibaba.fastjson.JSON
;
import
com.polysoft.nafmii.bean.JPushBean
;
import
com.polysoft.nafmii.bean.OpenUrlBean
;
import
com.polysoft.nafmii.database.ObjectBox
;
import
com.polysoft.nafmii.database.entity.DataEntity
;
import
com.polysoft.nafmii.enums.ModulesEnum
;
import
com.polysoft.nafmii.utils.ExecutorUtils
;
import
com.polysoft.nafmii.utils.SystemUtils
;
import
com.whaty.nafmii.activity.HomeActivity
;
import
com.whaty.nafmii.activity.OutsideWebviewActivity
;
import
java.util.HashMap
;
import
java.util.Map
;
...
...
@@ -27,12 +36,53 @@ public class JPushReceiver extends JPushMessageReceiver {
@Override
public
void
onMessage
(
Context
context
,
CustomMessage
customMessage
)
{
String
message
=
customMessage
.
message
;
String
messageId
=
customMessage
.
messageId
;
if
(
TextUtils
.
isEmpty
(
message
))
{
return
;
}
ExecutorUtils
.
main
(()
->
{
JPushMgr
.
sendLearnLocalNotice
(
"自定义消息标题"
,
"自定义消息内容"
,
message
);
});
Log
.
e
(
TAG
,
"[onMessage] "
+
customMessage
);
}
@Override
public
void
onNotifyMessageOpened
(
Context
context
,
NotificationMessage
message
)
{
Log
.
e
(
TAG
,
"[onNotifyMessageOpened] "
+
message
);
String
json
=
message
.
notificationExtras
;
if
(
TextUtils
.
isEmpty
(
json
))
{
return
;
}
JPushBean
bean
=
JSON
.
parseObject
(
json
,
JPushBean
.
class
);
if
(
null
==
bean
)
{
return
;
}
if
(
"learn"
.
equals
(
bean
.
getType
()))
{
String
url
=
bean
.
getUrl
();
if
(
null
!=
bean
.
getParams
())
{
url
=
bean
.
getParams
().
getUrl
();
}
if
(
TextUtils
.
isEmpty
(
url
))
return
;
OpenUrlBean
dataBean
=
new
OpenUrlBean
();
dataBean
.
setLinkUrl
(
url
);
dataBean
.
setLinkType
(
"2"
);
this
.
startLearnActivity
(
context
,
dataBean
);
// Map<String, Object> map = new HashMap<>();
// map.put("moduleName", ModulesEnum.HOME.name);
// map.put("query", dataBean);
//
// Intent intent = new Intent(context, HomeActivity.class);
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP );
// intent.putExtra("changeRoute", JSON.toJSONString(map));
// context.startActivity(intent);
}
// try{
// //打开自定义的Activity
// Intent i = new Intent(context, TestActivity.class);
...
...
@@ -93,7 +143,7 @@ public class JPushReceiver extends JPushMessageReceiver {
Log
.
e
(
TAG
,
"[onCommandResult] "
+
cmdMessage
);
}
// @Override
// @Override
// public void onTagOperatorResult(Context context, JPushMessage jPushMessage) {
// TagAliasOperatorHelper.getInstance().onTagOperatorResult(context,jPushMessage);
// super.onTagOperatorResult(context, jPushMessage);
...
...
@@ -128,4 +178,45 @@ public class JPushReceiver extends JPushMessageReceiver {
Log
.
e
(
TAG
,
"[onNotificationSettingsCheck] isOn:"
+
isOn
+
",source:"
+
source
);
}
private
void
startLearnActivity
(
Context
context
,
OpenUrlBean
dataBean
)
{
if
(
SystemUtils
.
isAppAlive
(
context
,
context
.
getPackageName
()))
{
//如果存活的话,就直接启动DetailActivity,但要考虑一种情况,就是app的进程虽然仍然在
//但Task栈已经空了,比如用户点击Back键退出应用,但进程还没有被系统回收,如果直接启动
//DetailActivity,再按Back键就不会返回MainActivity了。所以在启动
//DetailActivity前,要先启动MainActivity。
Log
.
i
(
"NotificationReceiver"
,
"the app process is alive"
);
Intent
mainIntent
=
new
Intent
(
context
,
HomeActivity
.
class
);
//将MainAtivity的launchMode设置成SingleTask, 或者在下面flag中加上Intent.FLAG_CLEAR_TOP,
//如果Task栈中有MainActivity的实例,就会把它移到栈顶,把在它之上的Activity都清理出栈,
//如果Task栈不存在MainActivity实例,则在栈顶创建
mainIntent
.
setFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
|
Intent
.
FLAG_ACTIVITY_CLEAR_TOP
);
Intent
detailIntent
=
new
Intent
(
context
,
OutsideWebviewActivity
.
class
);
detailIntent
.
putExtra
(
"data"
,
JSON
.
toJSONString
(
dataBean
));
Intent
[]
intents
=
{
mainIntent
,
detailIntent
};
context
.
startActivities
(
intents
);
}
else
{
//如果app进程已经被杀死,先重新启动app,将DetailActivity的启动参数传入Intent中,参数经过
//SplashActivity传入MainActivity,此时app的初始化已经完成,在MainActivity中就可以根据传入 //参数跳转到DetailActivity中去了
Intent
launchIntent
=
context
.
getPackageManager
().
getLaunchIntentForPackage
(
context
.
getPackageName
());
launchIntent
.
setFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
|
Intent
.
FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
);
Map
<
String
,
Object
>
dataMap
=
new
HashMap
<>();
dataMap
.
put
(
"moduleName"
,
ModulesEnum
.
HOME
.
name
);
dataMap
.
put
(
"query"
,
dataBean
);
Map
<
String
,
Object
>
jpushMap
=
new
HashMap
<>();
jpushMap
.
put
(
"type"
,
"learn"
);
jpushMap
.
put
(
"changeRoute"
,
dataMap
);
launchIntent
.
putExtra
(
"jpush"
,
JSON
.
toJSONString
(
jpushMap
));
context
.
startActivity
(
launchIntent
);
}
}
}
app/src/main/java/com/whaty/nafmii/activity/MainActivity.java
View file @
e07f998
package
com
.
whaty
.
nafmii
.
activity
;
import
android.Manifest
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.text.TextUtils
;
import
androidx.annotation.NonNull
;
import
androidx.fragment.app.Fragment
;
import
androidx.fragment.app.FragmentTransaction
;
import
com.alibaba.fastjson.JSON
;
import
com.polysoft.nafmii.constants.Constants
;
import
com.polysoft.nafmii.fragment.AdvertisementFragment
;
import
com.polysoft.nafmii.fragment.GuideFragment
;
...
...
@@ -19,6 +22,8 @@ import com.polysoft.nafmii.utils.ToastUtils;
import
com.polysoft.nafmii.viewmodel.AdvertisementViewModel
;
import
com.whaty.nafmii.R
;
import
java.util.Map
;
import
cn.jpush.android.api.JPushInterface
;
public
class
MainActivity
extends
BaseActivity
{
...
...
@@ -45,7 +50,9 @@ public class MainActivity extends BaseActivity {
if
(
this
.
checkPermissionSetting
())
{
JPushInterface
.
resumePush
(
this
);
this
.
showLayout
();
if
(!
this
.
isParamStart
())
{
this
.
showLayout
();
}
}
}
...
...
@@ -60,6 +67,7 @@ public class MainActivity extends BaseActivity {
}
else
if
(
IActivityEvent
.
EVENT_ADVERTISEMENT
.
equals
(
event
))
{
}
IntentUtils
.
toHomeActivity
(
this
);
}
private
void
checkAndRequestPermission
()
{
...
...
@@ -120,4 +128,29 @@ public class MainActivity extends BaseActivity {
return
SpUtils
.
getBoolean
(
SpUtils
.
KEY_FIRST_RUN
,
false
);
}
private
boolean
isParamStart
()
{
Intent
intent
=
getIntent
();
String
jpush
=
intent
.
getStringExtra
(
"jpush"
);
if
(
TextUtils
.
isEmpty
(
jpush
))
{
return
false
;
}
Map
<
String
,
Object
>
jpushMap
=
JSON
.
parseObject
(
jpush
,
Map
.
class
);
if
(
null
==
jpushMap
||
jpushMap
.
isEmpty
())
{
return
false
;
}
if
(
"learn"
.
equals
(
jpushMap
.
get
(
"type"
)))
{
Object
data
=
jpushMap
.
get
(
"changeRoute"
);
if
(
null
==
data
)
{
return
false
;
}
Intent
intent1
=
new
Intent
();
intent1
.
putExtra
(
"changeRoute"
,
JSON
.
toJSONString
(
data
));
IntentUtils
.
toHomeActivity
(
this
,
intent1
);
}
return
true
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
Attach a file
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 post a comment