Commit 91cb8587 by jeffrey

添加日志 看看为什么过一段时间后 提示不了了

parent 6e67daed
......@@ -56,4 +56,5 @@ dependencies {
compile 'com.google.zxing:core:3.2.1'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.orhanobut:logger:2.1.1'
}
......@@ -39,6 +39,7 @@
</activity>
<service
android:process=":remote"
android:exported="false"
android:name="com.yuqirong.listenwechatnotification.service.WeChatNotificationListenerService"
android:label="@string/app_name"
......
......@@ -94,6 +94,7 @@ public class MainActivity extends ParentActivity {
versionCode.setText(code);
checkNotificationPermission();
awakenUpFucntion();
checkWritePermission();
}
......@@ -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() {
boolean enable = false;
......@@ -126,7 +145,8 @@ private void checkNotificationPermission() {
}
if (!enable) {
try {
startService(new Intent(MainActivity.this, WeChatNotificationListenerService.class));//启动服务
//启动服务
startService(new Intent(MainActivity.this, WeChatNotificationListenerService.class));
Intent intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS);
startActivity(intent);
} catch (ActivityNotFoundException e) {
......@@ -141,6 +161,8 @@ private void checkNotificationPermission() {
ex.printStackTrace();
}
}
}else {
Toast.makeText(this,"通知权限已经打开",Toast.LENGTH_LONG).show();
}
}
......
......@@ -2,6 +2,9 @@ package com.yuqirong.listenwechatnotification;
import android.app.Application;
import com.orhanobut.logger.DiskLogAdapter;
import com.orhanobut.logger.Logger;
/**
* Created by yanqi on 2018/2/22 0022.
*/
......
......@@ -14,6 +14,10 @@ import android.text.TextUtils;
import android.util.Log;
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.MainActivity;
import com.yuqirong.listenwechatnotification.askhttp.GetMoney;
......@@ -58,13 +62,17 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Logger.addLogAdapter(new DiskLogAdapter());
Logger.addLogAdapter(new AndroidLogAdapter());
Logger.d("WeChatNotificationListenerService onStartCommand");
return START_STICKY;
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
Logger.d("WeChatNotificationListenerService onNotificationPosted");
if (!aliPayPackageName.equals(sbn.getPackageName())&& !weChatPayPackageName.equals(sbn.getPackageName())) {
return;
......@@ -163,6 +171,7 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
private void sendRequestWithOkHttp(final String payto) {
Logger.d("WeChatNotificationListenerService sendRequestWithOkHttp " + payto);
//开启线程来发起网络请求
new Thread(new Runnable() {
@Override
......@@ -207,6 +216,13 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
@Override
public void onNotificationRemoved(StatusBarNotification sbn) {
super.onNotificationRemoved(sbn);
Logger.d("WeChatNotificationListenerService onNotificationRemoved ");
}
@Override
public void onDestroy() {
Logger.d("WeChatNotificationListenerService onDestroy ");
super.onDestroy();
}
public List<String> getText(Notification notification) {
......
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