Skip to content

Commit

Permalink
开始尝试解决无障碍转账码,有时收到款后不会推送,等会再收到款后会把两条推送问题#95
Browse files Browse the repository at this point in the history
  • Loading branch information
WeihuaGu committed Aug 11, 2020
1 parent cffbb8a commit e459a04
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ public DatabaseHelper(@Nullable Context context, @Nullable String name, @Nullabl

@Override
public void onCreate(SQLiteDatabase db) {
String sql = "create table plat(id integer primary key autoincrement,name varchar(64),address varchar(64))";
db.execSQL(sql);
String plat = "create table plat(id integer primary key autoincrement,name varchar(64),address varchar(64))";
String pushrecord = "create table pushrecord(id integer primary key autoincrement,type varchar(64),time varchar(64),title varchar(64),money varchar(64),content varchar(64))";

db.execSQL(plat);
db.execSQL(pushrecord);

}

Expand Down
47 changes: 47 additions & 0 deletions app/src/main/java/com/weihuagu/receiptnotice/ForTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.weihuagu.receiptnotice;

import android.app.Application;
import android.app.Notification;
import android.content.Intent;
import android.content.Context.*;
import android.app.PendingIntent;
import android.app.Notification.Builder;
import android.app.NotificationManager;
import android.widget.Toast;


import com.weihuagu.receiptnotice.action.HandlePost;
import com.weihuagu.receiptnotice.view.MainActivity;

public class ForTest {
public void makeAPostTest(String pkg, Notification notification){
//接受推送处理
NotificationHandle notihandle =new NotificationHandleFactory().getNotificationHandle(pkg,notification,new HandlePost());
if(notihandle!=null){
notihandle.printNotify();
notihandle.handleNotification();
notihandle.removeNotification();
return;
}
}
private void GenerateNotification() {
Intent intent = new Intent(MainApplication.getAppContext(), MainActivity.class);
PendingIntent pintent = PendingIntent.getActivity(MainApplication.getAppContext(), 0, intent, 0);
Builder builder = new Builder(MainApplication.getAppContext());
builder.setSmallIcon(R.drawable.ic_launcher);
builder.setTicker("这是手记状态栏提示");
builder.setWhen(System.currentTimeMillis());
builder.setContentTitle("woshi biaoti");
builder.setContentText("标题内容我是");
builder.setContentIntent(pintent);
builder.setDefaults(Notification.DEFAULT_SOUND);
builder.setDefaults(Notification.DEFAULT_LIGHTS);
// builder.getNotification();//4.0以及以下版本用这个获取notification
Notification notification = builder.build();// 4.1以及以上版本用这个
Toast.makeText(MainApplication.getAppContext(), "生成通知", 50).show();
NotificationManager manager = (NotificationManager) MainApplication.getAppContext()
.getSystemService(android.content.Context.NOTIFICATION_SERVICE);
manager.notify(23, notification);// 发出通知
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.weihuagu.receiptnotice;

import java.util.Map;
import com.weihuagu.receiptnotice.util.DataBaseHolder;
import com.google.gson.Gson;

public class OnlyWriteToDateBase {
DataBaseHolder database = DataBaseHolder.getInstance();
public void onePostWriteToDateBase(String postjson){
Gson gson=new Gson();
Map<String,String> postmap=gson.fromJson(postjson,Map.class);
String type=postmap.get("type");
String time=postmap.get("time");
String title=postmap.get("title");
String money=postmap.get("money");
String content=postmap.get("content");
checkHavePlatName(type);

}


public boolean checkHavePlatName(String plattype){
database.sqliteDatabase.query("plat",new String[]{"name"},plattype,null,null,null,null);
return false;
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.weihuagu.receiptnotice;

import android.accessibilityservice.AccessibilityService;
import android.accessibilityservice.GestureDescription;
import android.app.KeyguardManager;
import android.content.Context;
import android.graphics.Path;
import android.os.Build;
import android.os.PowerManager;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.AccessibilityWindowInfo;
Expand All @@ -19,7 +23,9 @@
import com.weihuagu.receiptnotice.util.message.MessageConsumer;
import com.weihuagu.receiptnotice.util.message.MessageSendBus;

import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

public class ReceiptnoticeAccessibilityService extends AccessibilityService implements MessageConsumer {
PowerManager pm=null;
Expand All @@ -29,6 +35,7 @@ public class ReceiptnoticeAccessibilityService extends AccessibilityService impl
private KeyguardManager.KeyguardLock kl;
private String lastpoststr = "";
private String lastnotistr = "";
private Queue<String> poststrqueue = new LinkedList<String>();
private void setLastPostStr(String str){
lastpoststr=str;
}
Expand Down Expand Up @@ -73,6 +80,44 @@ public void onInterrupt() {
debugLogWithDeveloper( "oninterrupt");
}

private void mockSwipe(){
if(Build.VERSION.SDK_INT >= 24) {
//获取屏幕中心点坐标
WindowManager wm = (WindowManager) MainApplication.getAppContext()
.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics dm = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
int cx = width/2;
int cy = height / 2;
final Path path = new Path();

path.moveTo(cx, cy); //滑动的起始位置,例如屏幕的中心点X、Y
path.lineTo(cx, 0); //需要滑动的位置,如从中心点滑到屏幕的顶部
GestureDescription.Builder builder = new GestureDescription.Builder();
GestureDescription gestureDescription = builder.addStroke(
new GestureDescription.StrokeDescription(path, 100, 400)
).build(); //移动到中心点,100ms后开始滑动,滑动的时间持续400ms,可以调整
dispatchGesture(gestureDescription, new GestureResultCallback() {
@Override
//如果滑动成功,会回调如下函数,可以在下面记录是否滑动成功,滑动成功或失败都要关闭该路径笔画
public void onCompleted(GestureDescription gestureDescription) {
super.onCompleted(gestureDescription);
Log.d(TAG, "swipe success.");
path.close();
}

@Override
public void onCancelled(GestureDescription gestureDescription) {
super.onCancelled(gestureDescription);
Log.d(TAG, " swipe fail.");
path.close();
}
},null);
}
}


public void subMessage(){
LiveEventBus
Expand Down Expand Up @@ -117,6 +162,7 @@ public void onChanged(@Nullable String s) {
@Override
public void onChanged(@Nullable String s) {
LogUtil.debugLog("收到订阅消息:update_laststr " + s);
poststrqueue.offer(s);
setLastPostStr(s);
}
});
Expand All @@ -129,6 +175,7 @@ public void getAlipayTransferInfo(String classname){
String transremarkid="com.alipay.mobile.chatapp:id/biz_title";
debugLogWithDeveloper( ":窗口状态改变,类名为"+classname);
if(classname.equals("com.alipay.mobile.chatapp.ui.PersonalChatMsgActivity_")){
mockSwipe();
AccessibilityNodeInfo nodepersonalchat=null;
AccessibilityWindowInfo windowInfopersonalchat=null;
if(pm.isScreenOn()) {
Expand All @@ -154,7 +201,7 @@ public void getAlipayTransferInfo(String classname){
AlipayTransferBean transferbean=new AlipayTransferBean();
transferbean.setNum(transnum);
transferbean.setRemark(transremark);
if(!lastpoststr.equals(lastnotistr))
if(!poststrqueue.poll().equals(lastnotistr))
MessageSendBus.postMessageWithget_alipay_transfer_money(transferbean);
}catch (ArrayIndexOutOfBoundsException e){

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


import com.weihuagu.receiptnotice.MainApplication;
import com.weihuagu.receiptnotice.OnlyWriteToDateBase;
import com.weihuagu.receiptnotice.filteringmiddleware.PostMapFilter;
import com.weihuagu.receiptnotice.util.LogUtil;
import com.weihuagu.receiptnotice.util.PreferenceUtil;
Expand Down Expand Up @@ -66,6 +67,7 @@ public void onDataReceivedSuccess(String[] returnstr) {
LogUtil.debugLog(returnstr[2]);
LogUtil.postResultLog(returnstr[0],returnstr[1],returnstr[2]);
MessageSendBus.postMessageWithFinishedonePost(returnstr);
new OnlyWriteToDateBase().onePostWriteToDateBase(returnstr[2]);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void handleNotification(){
}

private void transfercodePush(){
Map<String,String> postmap=new HashMap<String,String>();
Map<String,String> postmap=new HashMap<String,String>();
postmap.put("type","alipay-transfer");
postmap.put("time",notitime);
postmap.put("title","转账");
Expand Down
41 changes: 41 additions & 0 deletions app/src/main/java/com/weihuagu/receiptnotice/view/TestActiviy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.weihuagu.receiptnotice.view;

import android.os.Bundle;
import android.webkit.WebView;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.weihuagu.receiptnotice.R;
import com.weihuagu.receiptnotice.ForTest;


import org.w3c.dom.Text;
import android.widget.Button;
import android.view.View;

public class TestActiviy extends AppCompatActivity implements View.OnClickListener{

private TextView money;
private Button button;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
money = (TextView) findViewById(R.id.money);
button = (Button) findViewById(R.id.action_nitification);
button.setOnClickListener(this);

}

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.action_nitification:
new ForTest();
break;

}
}
}
68 changes: 68 additions & 0 deletions app/src/main/res/layout/activity_test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.weihuagu.receiptnotice.view.MainActivity">

<androidx.appcompat.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
app:layout_constraintTop_toTopOf="parent"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar" />



<LinearLayout
android:id="@+id/inputlinearlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical"
app:layout_constraintTop_toBottomOf="@id/my_toolbar">

<TextView
android:id="@+id/money"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:text=""></TextView>

<Button
android:id="@+id/action_nitification"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="模拟通知" />
</LinearLayout>


<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewpager"
layout_constraintBottom_toBottomOf="parent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="0dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/inputlinearlayout"
app:layout_constraintVertical_bias="0.0"
tools:layout_editor_absoluteX="-40dp" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/floatingshowlog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="5dp"
android:src="@drawable/log_icon"
app:backgroundTint="@color/white"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit e459a04

Please sign in to comment.