Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
严琪
/
paysplug-in
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
4139a78e
authored
Mar 20, 2018
by
jeffrey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1 把service放到前台 2 把日志写入文件
parent
91cb8587
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
9 deletions
+59
-9
app/build.gradle
+2
-2
app/src/main/java/com/yuqirong/listenwechatnotification/MainActivity.java
+8
-3
app/src/main/java/com/yuqirong/listenwechatnotification/function/BuildNotification.java
+22
-1
app/src/main/java/com/yuqirong/listenwechatnotification/service/WeChatNotificationListenerService.java
+27
-3
No files found.
app/build.gradle
View file @
4139a78e
...
@@ -23,8 +23,8 @@ android {
...
@@ -23,8 +23,8 @@ android {
applicationId
"com.yuqirong.listenwechatnotification"
applicationId
"com.yuqirong.listenwechatnotification"
minSdkVersion
16
minSdkVersion
16
targetSdkVersion
26
targetSdkVersion
26
versionCode
1
1
versionCode
1
2
versionName
"1.2"
versionName
"1.2
1
"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
}
buildTypes
{
buildTypes
{
...
...
app/src/main/java/com/yuqirong/listenwechatnotification/MainActivity.java
View file @
4139a78e
...
@@ -100,6 +100,9 @@ public class MainActivity extends ParentActivity {
...
@@ -100,6 +100,9 @@ public class MainActivity extends ParentActivity {
private
void
checkPermission
()
{
private
void
checkPermission
()
{
//检查权限(NEED_PERMISSION)是否被授权 PackageManager.PERMISSION_GRANTED表示同意授权
//检查权限(NEED_PERMISSION)是否被授权 PackageManager.PERMISSION_GRANTED表示同意授权
if
(
ActivityCompat
.
checkSelfPermission
(
this
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
)
if
(
ActivityCompat
.
checkSelfPermission
(
this
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
)
...
@@ -145,8 +148,7 @@ private void checkNotificationPermission() {
...
@@ -145,8 +148,7 @@ private void checkNotificationPermission() {
}
}
if
(!
enable
)
{
if
(!
enable
)
{
try
{
try
{
//启动服务
startService
(
new
Intent
(
MainActivity
.
this
,
WeChatNotificationListenerService
.
class
));
Intent
intent
=
new
Intent
(
Settings
.
ACTION_NOTIFICATION_LISTENER_SETTINGS
);
Intent
intent
=
new
Intent
(
Settings
.
ACTION_NOTIFICATION_LISTENER_SETTINGS
);
startActivity
(
intent
);
startActivity
(
intent
);
}
catch
(
ActivityNotFoundException
e
)
{
}
catch
(
ActivityNotFoundException
e
)
{
...
@@ -202,7 +204,10 @@ private void checkNotificationPermission() {
...
@@ -202,7 +204,10 @@ private void checkNotificationPermission() {
@Override
@Override
protected
void
onResume
()
{
protected
void
onResume
()
{
super
.
onResume
();
super
.
onResume
();
//启动服务,不停的启动 确保服务一直在
Intent
serviceIntent
=
new
Intent
(
MainActivity
.
this
,
WeChatNotificationListenerService
.
class
);
startService
(
serviceIntent
);
// startForegroundService(serviceIntent);
}
}
...
...
app/src/main/java/com/yuqirong/listenwechatnotification/function/BuildNotification.java
View file @
4139a78e
package
com
.
yuqirong
.
listenwechatnotification
.
function
;
package
com
.
yuqirong
.
listenwechatnotification
.
function
;
import
android.app.Notification
;
import
android.app.NotificationManager
;
import
android.app.NotificationManager
;
import
android.app.PendingIntent
;
import
android.app.Service
;
import
android.content.Context
;
import
android.content.Context
;
import
android.support.v7.app.NotificationCompat
;
import
android.content.Intent
;
import
android.support.v4.app.NotificationCompat
;
import
com.yuqirong.listenwechatnotification.MainActivity
;
import
com.yuqirong.listenwechatnotification.R
;
import
com.yuqirong.listenwechatnotification.R
;
import
static
android
.
app
.
PendingIntent
.
FLAG_UPDATE_CURRENT
;
/**
/**
* Created by yanqi on 2018/2/22 0022.
* Created by yanqi on 2018/2/22 0022.
*/
*/
...
@@ -52,4 +59,18 @@ public class BuildNotification {
...
@@ -52,4 +59,18 @@ public class BuildNotification {
//通过builder.build()方法生成Notification对象,并发送通知,id=1
//通过builder.build()方法生成Notification对象,并发送通知,id=1
this
.
mNotifyManager
.
notify
(
2
,
builder
.
build
());
this
.
mNotifyManager
.
notify
(
2
,
builder
.
build
());
}
}
public
static
void
foreground
(
Context
context
,
Service
service
){
NotificationCompat
.
Builder
builder
=
new
NotificationCompat
.
Builder
(
context
,
"88"
)
//设置小图标
.
setSmallIcon
(
R
.
mipmap
.
ic_launcher
)
//设置通知标题
.
setContentTitle
(
"我正在运行"
)
.
setContentIntent
(
PendingIntent
.
getActivity
(
context
,
1
,
new
Intent
(
context
,
MainActivity
.
class
),
FLAG_UPDATE_CURRENT
))
//设置通知内容
.
setContentText
(
"有这个说明正在运行"
);
Notification
notification
=
builder
.
build
();
service
.
startForeground
(
88
,
notification
);
}
}
}
app/src/main/java/com/yuqirong/listenwechatnotification/service/WeChatNotificationListenerService.java
View file @
4139a78e
...
@@ -60,12 +60,20 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
...
@@ -60,12 +60,20 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
// android.os.Debug.waitForDebugger();
// android.os.Debug.waitForDebugger();
// }
// }
@Override
@Override
public
int
onStartCommand
(
Intent
intent
,
int
flags
,
int
startId
)
{
public
void
onCreate
()
{
super
.
onCreate
();
Logger
.
addLogAdapter
(
new
DiskLogAdapter
());
Logger
.
addLogAdapter
(
new
DiskLogAdapter
());
Logger
.
addLogAdapter
(
new
AndroidLogAdapter
());
Logger
.
addLogAdapter
(
new
AndroidLogAdapter
());
Logger
.
d
(
"WeChatNotificationListenerService onCreate"
);
}
@Override
public
int
onStartCommand
(
Intent
intent
,
int
flags
,
int
startId
)
{
Logger
.
d
(
"WeChatNotificationListenerService onStartCommand"
);
Logger
.
d
(
"WeChatNotificationListenerService onStartCommand"
);
BuildNotification
.
foreground
(
getApplicationContext
(),
this
);
return
START_STICKY
;
return
START_STICKY
;
}
}
...
@@ -163,12 +171,22 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
...
@@ -163,12 +171,22 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
}
}
cancelNotification
(
sbn
.
getKey
());
//
cancelNotification(sbn.getKey());
cancelAllNotifications
();
}
}
@Override
public
void
onListenerConnected
()
{
Logger
.
d
(
"WeChatNotificationListenerService onListenerConnected "
);
super
.
onListenerConnected
();
}
@Override
public
void
onListenerDisconnected
()
{
Logger
.
d
(
"WeChatNotificationListenerService onListenerDisconnected "
);
super
.
onListenerDisconnected
();
}
private
void
sendRequestWithOkHttp
(
final
String
payto
)
{
private
void
sendRequestWithOkHttp
(
final
String
payto
)
{
Logger
.
d
(
"WeChatNotificationListenerService sendRequestWithOkHttp "
+
payto
);
Logger
.
d
(
"WeChatNotificationListenerService sendRequestWithOkHttp "
+
payto
);
...
@@ -222,6 +240,7 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
...
@@ -222,6 +240,7 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
@Override
@Override
public
void
onDestroy
()
{
public
void
onDestroy
()
{
Logger
.
d
(
"WeChatNotificationListenerService onDestroy "
);
Logger
.
d
(
"WeChatNotificationListenerService onDestroy "
);
stopForeground
(
true
);
super
.
onDestroy
();
super
.
onDestroy
();
}
}
...
@@ -272,4 +291,9 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
...
@@ -272,4 +291,9 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
return
text
;
return
text
;
}
}
private
void
showForground
(){
}
}
}
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