Commit 97f6615d by jeffrey

把主干代码合并过来了

parents 9953285b 4139a78e
...@@ -22,8 +22,8 @@ android { ...@@ -22,8 +22,8 @@ android {
applicationId "com.yuqirong.listenwechatnotification" applicationId "com.yuqirong.listenwechatnotification"
minSdkVersion 16 minSdkVersion 16
targetSdkVersion 26 targetSdkVersion 26
versionCode 10 versionCode 12
versionName "1.1" versionName "1.21"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
} }
buildTypes { buildTypes {
...@@ -44,7 +44,7 @@ dependencies { ...@@ -44,7 +44,7 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations' exclude group: 'com.android.support', module: 'support-annotations'
}) })
compile 'com.android.support:appcompat-v7:26.0.2' compile 'com.android.support:appcompat-v7:26.1.0'
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
//添加retrofit-会自动下载okhttp //添加retrofit-会自动下载okhttp
compile 'com.squareup.retrofit2:retrofit:2.1.0' compile 'com.squareup.retrofit2:retrofit:2.1.0'
...@@ -58,4 +58,5 @@ dependencies { ...@@ -58,4 +58,5 @@ dependencies {
compile "io.reactivex.rxjava2:rxjava:2.1.10" compile "io.reactivex.rxjava2:rxjava:2.1.10"
compile 'io.reactivex.rxjava2:rxandroid:2.0.2' compile 'io.reactivex.rxjava2:rxandroid:2.0.2'
compile 'com.orhanobut:logger:2.1.1'
} }
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1},"path":"app-release.apk","properties":{"packageId":"com.yuqirong.listenwechatnotification","split":"","minSdkVersion":"16"}}] [{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":200000},"path":"app-release.apk","properties":{"packageId":"com.yuqirong.listenwechatnotification","split":"","minSdkVersion":"16"}}]
\ No newline at end of file \ No newline at end of file
...@@ -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"
......
...@@ -115,6 +115,7 @@ public class MainActivity extends ParentActivity { ...@@ -115,6 +115,7 @@ public class MainActivity extends ParentActivity {
checkNotificationPermission(); checkNotificationPermission();
awakenUpFucntion(); awakenUpFucntion();
IntentFilter filter = new IntentFilter(); IntentFilter filter = new IntentFilter();
filter.addAction("CashPull"); filter.addAction("CashPull");
my = new MyCashReceiver(); my = new MyCashReceiver();
...@@ -147,7 +148,7 @@ public class MainActivity extends ParentActivity { ...@@ -147,7 +148,7 @@ public class MainActivity extends ParentActivity {
EventBus.getDefault().post(new WorkAction(WorkAction.ACTION_TYPE_BILL)); EventBus.getDefault().post(new WorkAction(WorkAction.ACTION_TYPE_BILL));
} }
}); });
checkWritePermission();
// QRCodeFunction qrThread = new QRCodeFunction("QRCodeFunction---ZFB", Utils.ZFBImgPath); // QRCodeFunction qrThread = new QRCodeFunction("QRCodeFunction---ZFB", Utils.ZFBImgPath);
// qrThread.start(); // qrThread.start();
...@@ -167,6 +168,8 @@ public class MainActivity extends ParentActivity { ...@@ -167,6 +168,8 @@ public class MainActivity extends ParentActivity {
// sb.append(","); // sb.append(",");
// } // }
// Log.d(TAG,"done =" + sb.toString()); // Log.d(TAG,"done =" + sb.toString());
} }
...@@ -189,6 +192,24 @@ public class MainActivity extends ParentActivity { ...@@ -189,6 +192,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;
...@@ -199,7 +220,7 @@ private void checkNotificationPermission() { ...@@ -199,7 +220,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) {
...@@ -214,6 +235,8 @@ private void checkNotificationPermission() { ...@@ -214,6 +235,8 @@ private void checkNotificationPermission() {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
}else {
Toast.makeText(this,"通知权限已经打开",Toast.LENGTH_LONG).show();
} }
} }
...@@ -288,7 +311,10 @@ private void checkNotificationPermission() { ...@@ -288,7 +311,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);
} }
...@@ -301,12 +327,17 @@ private void checkNotificationPermission() { ...@@ -301,12 +327,17 @@ private void checkNotificationPermission() {
} }
@Subscribe(threadMode = ThreadMode.ASYNC)
public void Event(ImageBean bean){
functionUrls.getBeans().add(bean);
Log.d(TAG, "Event: "+bean.getUrl());
}
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
am.cancel(pi); am.cancel(pi);
} }
} }
...@@ -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;
import com.yuqirong.listenwechatnotification.uitl.PayTypeSingleTon; import com.yuqirong.listenwechatnotification.uitl.PayTypeSingleTon;
import com.yuqirong.listenwechatnotification.uitl.Utils; import com.yuqirong.listenwechatnotification.uitl.Utils;
......
package com.yuqirong.listenwechatnotification.bean;
/**
* 创建日期:2018/3/21 on 11:09
* 描述:
* 作者:Li
*/
public class BaseResult {
}
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);
}
} }
package com.yuqirong.listenwechatnotification.function;
import com.yuqirong.listenwechatnotification.bean.ImageBean;
import java.util.ArrayList;
/**
* Created by yanqi on 2018/2/27 0027.
*/
public class BuildUrlsFunction {
ArrayList<ImageBean> beans;
public BuildUrlsFunction() {
this.beans = new ArrayList<>();
}
public ArrayList<ImageBean> getBeans() {
return beans;
}
public void setBeans(ArrayList<ImageBean> beans) {
this.beans = beans;
}
}
...@@ -24,9 +24,11 @@ public interface HttpService { ...@@ -24,9 +24,11 @@ public interface HttpService {
public String base_url = "http://test.fourth-pay.checheng.net/"; public String base_url = "http://test.fourth-pay.checheng.net/";
// public String base_url = "http://www.haoyiwangluo.com/"; // public String base_url = "http://www.haoyiwangluo.com/";
// public String base_url = "http://www.haoyiwangluo.com/";
public String notify_money_come = "index/pay/notify/person_app";
@POST("index/pay/notify/person_app")
public String test_base_url = "http://test.fourth-pay.checheng.net/"; Call<String> postClientMoney(@Field("notify_text") String notify_text, @Field("pay_to") String pay_to, @Field("type") String type);
@GET("/app-api/app/status") @GET("/app-api/app/status")
Call<UpdateBean> postSoftVersion(@Query("version") String version); Call<UpdateBean> postSoftVersion(@Query("version") String version);
......
...@@ -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.uitl.Save2SharedPreferences; import com.yuqirong.listenwechatnotification.uitl.Save2SharedPreferences;
...@@ -47,7 +51,7 @@ public class WeChatNotificationListenerService extends NotificationListenerServi ...@@ -47,7 +51,7 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
private static String paytype; private static String paytype;
private Save2SharedPreferences save2SharedPreferences; // private Save2SharedPreferences save2SharedPreferences;
// @Override // @Override
// public void onCreate() { // public void onCreate() {
...@@ -55,29 +59,42 @@ public class WeChatNotificationListenerService extends NotificationListenerServi ...@@ -55,29 +59,42 @@ 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 AndroidLogAdapter());
Logger.d("WeChatNotificationListenerService onCreate");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Logger.d("WeChatNotificationListenerService onStartCommand");
BuildNotification.foreground(getApplicationContext(),this);
return START_STICKY; return START_STICKY;
} }
@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;
} }
String pay2set = ""; String pay2set = "";
save2SharedPreferences = new Save2SharedPreferences(); // save2SharedPreferences = new Save2SharedPreferences();
if (aliPayPackageName.equals(sbn.getPackageName())) { if (aliPayPackageName.equals(sbn.getPackageName())) {
paytype = aliPayType; paytype = aliPayType;
pay2set = save2SharedPreferences.read(MainActivity.ALIPAYNAME,getApplicationContext()); pay2set = Save2SharedPreferences.read(MainActivity.ALIPAYNAME,getApplicationContext());
} }
if (weChatPayPackageName.equals(sbn.getPackageName())) { if (weChatPayPackageName.equals(sbn.getPackageName())) {
paytype = weChatPayType; paytype = weChatPayType;
pay2set = save2SharedPreferences.read(MainActivity.WECHATPAYNAME,getApplicationContext()); pay2set = Save2SharedPreferences.read(MainActivity.WECHATPAYNAME,getApplicationContext());
} }
...@@ -85,8 +102,8 @@ public class WeChatNotificationListenerService extends NotificationListenerServi ...@@ -85,8 +102,8 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
Log.i("xiaolong", "open" + "-----" + sbn.getPackageName()); Log.i("xiaolong", "open" + "-----" + sbn.getPackageName());
Log.i("xiaolong", "open" + "------" + sbn.getNotification().tickerText); Log.i("xiaolong", "open" + "------" + sbn.getNotification().tickerText);
String alipay = save2SharedPreferences.read(MainActivity.ALIPAYNAME,getApplicationContext()); String alipay = Save2SharedPreferences.read(MainActivity.ALIPAYNAME,getApplicationContext());
String api = save2SharedPreferences.read(MainActivity.API,getApplicationContext()); String api = Save2SharedPreferences.read(MainActivity.API,getApplicationContext());
Log.i("xiaolong", "open" + "-----" + alipay); Log.i("xiaolong", "open" + "-----" + alipay);
Log.i("xiaolong", "open" + "------" + api); Log.i("xiaolong", "open" + "------" + api);
...@@ -153,19 +170,32 @@ public class WeChatNotificationListenerService extends NotificationListenerServi ...@@ -153,19 +170,32 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
} }
// 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);
//开启线程来发起网络请求 //开启线程来发起网络请求
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
OkHttpClient client = new OkHttpClient(); OkHttpClient client = new OkHttpClient();
String api = save2SharedPreferences.read(MainActivity.API,getApplicationContext()); String api = Save2SharedPreferences.read(MainActivity.API,getApplicationContext());
//这边讲请求不用ref的方式,是因为api地址后期会随着变化而变化,不可以写成结构形式 //这边讲请求不用ref的方式,是因为api地址后期会随着变化而变化,不可以写成结构形式
RequestBody requestBody = new FormBody.Builder() RequestBody requestBody = new FormBody.Builder()
...@@ -203,6 +233,14 @@ public class WeChatNotificationListenerService extends NotificationListenerServi ...@@ -203,6 +233,14 @@ 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 ");
stopForeground(true);
super.onDestroy();
} }
public List<String> getText(Notification notification) { public List<String> getText(Notification notification) {
...@@ -252,4 +290,9 @@ public class WeChatNotificationListenerService extends NotificationListenerServi ...@@ -252,4 +290,9 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
return text; return text;
} }
private void showForground(){
}
} }
# APP接口
# APP接口
## 接口URL
http://test.fourth-pay.checheng.net/app-api/
## 接口说明
### 请求方法
POST
### 通用请求参数
token: string,由服务端生成提供
### HTTP返回码
200: 请求成功
401: TOKEN验证失败
422: 请求失败,返回{'message': '错误信息', errors: [...]}
## 接口
### 获取要生成的金额
#### 请求URL
amounts
#### 请求参数
channel: string, 支付宝为'alipaypersonal'、微信为'wechatpersonal'
username: string, 支付宝或微信的账号名称
#### 响应结果
返回所有需要生产的金额: 如[1, 2, 3]
### 提交二维码
#### 请求URL
amounts/submit
#### 请求参数
channel: string, 支付宝为'alipaypersonal'、微信为'wechatpersonal'
username: string, 支付宝或微信的账号名称
data: array, 数组中每条数据结构为{amount: 1, code: 'HTTP://alipay.com/897jas8fau0s9'}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment