Skip to content

Commit

Permalink
补上可以收款类app的接受通知log,c-kzxvldkhX#28
Browse files Browse the repository at this point in the history
  • Loading branch information
weihuagu authored and xcorp1986 committed Sep 19, 2020
1 parent e96eeec commit cf7fa70
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dependencies {
implementation 'io.socket:socket.io-client:1.0.0'
implementation 'com.google.code.gson:gson:2.8.5'
testImplementation 'junit:junit:4.12'
testImplementation "org.mockito:mockito-core:2.27.0"
testImplementation "org.mockito:mockito-core:3.+"
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
androidTestImplementation 'org.mockito:mockito-android:+'
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/weihuagu/receiptnotice/NLService.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public void onNotificationPosted(StatusBarNotification sbn) {
if(notihandle!=null){
notihandle.setStatusBarNotification(sbn);
notihandle.setActionStatusbar(this);
notihandle.printNotify();
notihandle.handleNotification();
notihandle.removeNotification();
return;
Expand All @@ -62,7 +63,8 @@ public void onNotificationPosted(StatusBarNotification sbn) {
LogUtil.debugLog("接受到通知消息");
LogUtil.debugLog("这是检测之外的其它通知");
LogUtil.debugLog("包名是"+pkg);
printNotify(getNotitime(notification),getNotiTitle(extras),getNotiContent(extras));
NotificationUtil.printNotify(notification);
//printNotify(getNotitime(notification),getNotiTitle(extras),getNotiContent(extras));
LogUtil.debugLog("**********************");


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,32 @@ protected boolean predictIsPost(String content){
Pattern pattern = Pattern.compile("(收到|收款|向你付款|向您付款|入账)(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,2})?元");
Matcher matcher = pattern.matcher(content);
if(matcher.find())
return true;
return true;
else
return false;
return false;

}

protected void removeNotification(){
if(actionstatusbar==null|sbn==null)
return ;
return ;
if(predictIsPost(content))
actionstatusbar.removeNotification(sbn);
actionstatusbar.removeNotification(sbn);
}

protected void printNotify(){
LogUtil.debugLog("-----------------");
LogUtil.debugLog("接受到支付类app消息");
LogUtil.debugLog("包名是"+this.pkgtype);
NotificationUtil.printNotify(notification);
LogUtil.debugLog("**********************");


}







Expand Down
46 changes: 46 additions & 0 deletions app/src/main/java/com/weihuagu/receiptnotice/NotificationUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Created By WeihuaGu (email:[email protected])
* Copyright (c) 2017
* All right reserved.
*/

package com.weihuagu.receiptnotice;
import android.app.Notification;
import android.os.Bundle;
import java.text.SimpleDateFormat;
import java.util.Date;



public class NotificationUtil {
private static String getNotitime(Notification notification){

long when=notification.when;
Date date=new Date(when);
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm");
String notitime=format.format(date);
return notitime;

}

private static String getNotiTitle(Bundle extras){
String title=null;
// 获取通知标题
title = extras.getString(Notification.EXTRA_TITLE, "");
return title;
}

private static String getNotiContent(Bundle extras){
String content=null;
// 获取通知内容
content = extras.getString(Notification.EXTRA_TEXT, "");
return content;
}

public static void printNotify(Notification notification){
LogUtil.debugLog(getNotitime(notification));
LogUtil.debugLog(getNotiTitle(notification.extras));
LogUtil.debugLog(getNotiContent(notification.extras));
}

}

0 comments on commit cf7fa70

Please sign in to comment.