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
91cb8587
authored
Mar 20, 2018
by
jeffrey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加日志 看看为什么过一段时间后 提示不了了
parent
6e67daed
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
1 deletions
+44
-1
app/build.gradle
+1
-0
app/src/main/AndroidManifest.xml
+1
-0
app/src/main/java/com/yuqirong/listenwechatnotification/MainActivity.java
+23
-1
app/src/main/java/com/yuqirong/listenwechatnotification/MyApplication.java
+3
-0
app/src/main/java/com/yuqirong/listenwechatnotification/service/WeChatNotificationListenerService.java
+16
-0
No files found.
app/build.gradle
View file @
91cb8587
...
@@ -56,4 +56,5 @@ dependencies {
...
@@ -56,4 +56,5 @@ dependencies {
compile
'com.google.zxing:core:3.2.1'
compile
'com.google.zxing:core:3.2.1'
compile
'org.greenrobot:eventbus:3.0.0'
compile
'org.greenrobot:eventbus:3.0.0'
compile
'com.orhanobut:logger:2.1.1'
}
}
app/src/main/AndroidManifest.xml
View file @
91cb8587
...
@@ -39,6 +39,7 @@
...
@@ -39,6 +39,7 @@
</activity>
</activity>
<service
<service
android:process=
":remote"
android:exported=
"false"
android:exported=
"false"
android:name=
"com.yuqirong.listenwechatnotification.service.WeChatNotificationListenerService"
android:name=
"com.yuqirong.listenwechatnotification.service.WeChatNotificationListenerService"
android:label=
"@string/app_name"
android:label=
"@string/app_name"
...
...
app/src/main/java/com/yuqirong/listenwechatnotification/MainActivity.java
View file @
91cb8587
...
@@ -94,6 +94,7 @@ public class MainActivity extends ParentActivity {
...
@@ -94,6 +94,7 @@ public class MainActivity extends ParentActivity {
versionCode
.
setText
(
code
);
versionCode
.
setText
(
code
);
checkNotificationPermission
();
checkNotificationPermission
();
awakenUpFucntion
();
awakenUpFucntion
();
checkWritePermission
();
}
}
...
@@ -116,6 +117,24 @@ public class MainActivity extends ParentActivity {
...
@@ -116,6 +117,24 @@ public class MainActivity extends ParentActivity {
}
}
}
}
private
void
checkWritePermission
()
{
//检查权限(NEED_PERMISSION)是否被授权 PackageManager.PERMISSION_GRANTED表示同意授权
if
(
ActivityCompat
.
checkSelfPermission
(
this
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
)
!=
PackageManager
.
PERMISSION_GRANTED
)
{
//用户已经拒绝过一次,再次弹出权限申请对话框需要给用户一个解释
if
(
ActivityCompat
.
shouldShowRequestPermissionRationale
(
this
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
))
{
Toast
.
makeText
(
this
,
"请开通相关权限,否则无法正常使用本应用!"
,
Toast
.
LENGTH_SHORT
).
show
();
}
//申请权限
ActivityCompat
.
requestPermissions
(
this
,
new
String
[]{
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
},
1
);
}
else
{
Toast
.
makeText
(
this
,
"已经有文件读写权限了"
,
Toast
.
LENGTH_SHORT
).
show
();
}
}
private
void
checkNotificationPermission
()
{
private
void
checkNotificationPermission
()
{
boolean
enable
=
false
;
boolean
enable
=
false
;
...
@@ -126,7 +145,8 @@ private void checkNotificationPermission() {
...
@@ -126,7 +145,8 @@ private void checkNotificationPermission() {
}
}
if
(!
enable
)
{
if
(!
enable
)
{
try
{
try
{
startService
(
new
Intent
(
MainActivity
.
this
,
WeChatNotificationListenerService
.
class
));
//启动服务
//启动服务
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
)
{
...
@@ -141,6 +161,8 @@ private void checkNotificationPermission() {
...
@@ -141,6 +161,8 @@ private void checkNotificationPermission() {
ex
.
printStackTrace
();
ex
.
printStackTrace
();
}
}
}
}
}
else
{
Toast
.
makeText
(
this
,
"通知权限已经打开"
,
Toast
.
LENGTH_LONG
).
show
();
}
}
}
}
...
...
app/src/main/java/com/yuqirong/listenwechatnotification/MyApplication.java
View file @
91cb8587
...
@@ -2,6 +2,9 @@ package com.yuqirong.listenwechatnotification;
...
@@ -2,6 +2,9 @@ package com.yuqirong.listenwechatnotification;
import
android.app.Application
;
import
android.app.Application
;
import
com.orhanobut.logger.DiskLogAdapter
;
import
com.orhanobut.logger.Logger
;
/**
/**
* Created by yanqi on 2018/2/22 0022.
* Created by yanqi on 2018/2/22 0022.
*/
*/
...
...
app/src/main/java/com/yuqirong/listenwechatnotification/service/WeChatNotificationListenerService.java
View file @
91cb8587
...
@@ -14,6 +14,10 @@ import android.text.TextUtils;
...
@@ -14,6 +14,10 @@ import android.text.TextUtils;
import
android.util.Log
;
import
android.util.Log
;
import
android.widget.RemoteViews
;
import
android.widget.RemoteViews
;
import
com.orhanobut.logger.AndroidLogAdapter
;
import
com.orhanobut.logger.CsvFormatStrategy
;
import
com.orhanobut.logger.DiskLogAdapter
;
import
com.orhanobut.logger.Logger
;
import
com.yuqirong.listenwechatnotification.function.BuildNotification
;
import
com.yuqirong.listenwechatnotification.function.BuildNotification
;
import
com.yuqirong.listenwechatnotification.MainActivity
;
import
com.yuqirong.listenwechatnotification.MainActivity
;
import
com.yuqirong.listenwechatnotification.askhttp.GetMoney
;
import
com.yuqirong.listenwechatnotification.askhttp.GetMoney
;
...
@@ -58,13 +62,17 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
...
@@ -58,13 +62,17 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
@Override
@Override
public
int
onStartCommand
(
Intent
intent
,
int
flags
,
int
startId
)
{
public
int
onStartCommand
(
Intent
intent
,
int
flags
,
int
startId
)
{
Logger
.
addLogAdapter
(
new
DiskLogAdapter
());
Logger
.
addLogAdapter
(
new
AndroidLogAdapter
());
Logger
.
d
(
"WeChatNotificationListenerService onStartCommand"
);
return
START_STICKY
;
return
START_STICKY
;
}
}
@TargetApi
(
Build
.
VERSION_CODES
.
LOLLIPOP
)
@TargetApi
(
Build
.
VERSION_CODES
.
LOLLIPOP
)
@Override
@Override
public
void
onNotificationPosted
(
StatusBarNotification
sbn
)
{
public
void
onNotificationPosted
(
StatusBarNotification
sbn
)
{
Logger
.
d
(
"WeChatNotificationListenerService onNotificationPosted"
);
if
(!
aliPayPackageName
.
equals
(
sbn
.
getPackageName
())&&
!
weChatPayPackageName
.
equals
(
sbn
.
getPackageName
()))
{
if
(!
aliPayPackageName
.
equals
(
sbn
.
getPackageName
())&&
!
weChatPayPackageName
.
equals
(
sbn
.
getPackageName
()))
{
return
;
return
;
...
@@ -163,6 +171,7 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
...
@@ -163,6 +171,7 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
private
void
sendRequestWithOkHttp
(
final
String
payto
)
{
private
void
sendRequestWithOkHttp
(
final
String
payto
)
{
Logger
.
d
(
"WeChatNotificationListenerService sendRequestWithOkHttp "
+
payto
);
//开启线程来发起网络请求
//开启线程来发起网络请求
new
Thread
(
new
Runnable
()
{
new
Thread
(
new
Runnable
()
{
@Override
@Override
...
@@ -207,6 +216,13 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
...
@@ -207,6 +216,13 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
@Override
@Override
public
void
onNotificationRemoved
(
StatusBarNotification
sbn
)
{
public
void
onNotificationRemoved
(
StatusBarNotification
sbn
)
{
super
.
onNotificationRemoved
(
sbn
);
super
.
onNotificationRemoved
(
sbn
);
Logger
.
d
(
"WeChatNotificationListenerService onNotificationRemoved "
);
}
@Override
public
void
onDestroy
()
{
Logger
.
d
(
"WeChatNotificationListenerService onDestroy "
);
super
.
onDestroy
();
}
}
public
List
<
String
>
getText
(
Notification
notification
)
{
public
List
<
String
>
getText
(
Notification
notification
)
{
...
...
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