Skip to content

Commit 3992f6d

Browse files
committed
v1.6版本
1 parent 8849afc commit 3992f6d

File tree

7 files changed

+320
-6
lines changed

7 files changed

+320
-6
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ V免签为完全开源项目,开源项目意味着作者没有任何收入来
7272
+ 微信店员收款推送通知
7373

7474
## 更新记录
75+
+ v1.6(2019.05.16)
76+
+ 启用新方式监听到账通知,理论支持更多设备!
7577

7678
+ v1.5(2019.04.24)
7779
+ 修复部分手机扫码配置失败的问题!

app/app-release.apk

-9.25 KB
Binary file not shown.

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ android {
55
buildToolsVersion "26.0.0"
66
defaultConfig {
77
applicationId "com.vone.qrcode"
8-
minSdkVersion 15
8+
minSdkVersion 19
99
targetSdkVersion 26
1010
versionCode 1
1111
versionName "1.0"

app/src/main/AndroidManifest.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@
3838
<action android:name="android.accessibilityservice.AccessibilityService"/>
3939
</intent-filter>
4040
</service>
41+
42+
43+
<service
44+
android:name="com.vone.vmq.NeNotificationService2"
45+
android:label="@string/app_name"
46+
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
47+
<intent-filter>
48+
<action android:name="android.service.notification.NotificationListenerService" />
49+
</intent-filter>
50+
</service>
51+
52+
4153
</application>
4254

4355
</manifest>

app/src/main/java/com/vone/vmq/MainActivity.java

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import android.support.annotation.NonNull;
1919
import android.support.v4.app.ActivityCompat;
2020
import android.support.v4.app.NotificationCompat;
21+
import android.support.v4.app.NotificationManagerCompat;
2122
import android.support.v7.app.AppCompatActivity;
2223
import android.text.TextUtils;
2324
import android.util.Log;
@@ -35,6 +36,7 @@
3536
import java.security.MessageDigest;
3637
import java.security.NoSuchAlgorithmException;
3738
import java.util.Date;
39+
import java.util.Set;
3840

3941
import okhttp3.Call;
4042
import okhttp3.Callback;
@@ -79,6 +81,16 @@ protected void onCreate(Bundle savedInstanceState) {
7981
btnStart.setText("检测服务状态");
8082
}
8183

84+
if (!isNotificationListenersEnabled()) {
85+
gotoNotificationAccessSetting();
86+
}
87+
88+
// if (!isNotificationListenerServiceEnabled(this)){
89+
//
90+
// }
91+
toggleNotificationListenerService(this);
92+
93+
8294

8395
//读入保存的配置数据并显示
8496
SharedPreferences read = getSharedPreferences("vone", MODE_PRIVATE);
@@ -310,10 +322,12 @@ private boolean gotoNotificationAccessSetting(Context context) {
310322

311323

312324
public void checkPush(View v){
313-
if (!btnStart.getText().equals("检测服务状态")){
314-
Toast.makeText(MainActivity.this, "请先开启服务!", Toast.LENGTH_SHORT).show();
315-
return;
316-
}
325+
// if (!btnStart.getText().equals("检测服务状态")){
326+
// Toast.makeText(MainActivity.this, "请先开启服务!", Toast.LENGTH_SHORT).show();
327+
// return;
328+
// }
329+
330+
317331

318332
Notification mNotification;
319333
NotificationManager mNotificationManager;
@@ -344,7 +358,24 @@ public void checkPush(View v){
344358
}
345359

346360

361+
private static boolean isNotificationListenerServiceEnabled(Context context) {
362+
Set<String> packageNames = NotificationManagerCompat.getEnabledListenerPackages(context);
363+
if (packageNames.contains(context.getPackageName())) {
364+
return true;
365+
}
366+
return false;
367+
}
368+
369+
private void toggleNotificationListenerService(Context context) {
370+
PackageManager pm = context.getPackageManager();
371+
pm.setComponentEnabledSetting(new ComponentName(context, NeNotificationService2.class),
372+
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
347373

374+
pm.setComponentEnabledSetting(new ComponentName(context, NeNotificationService2.class),
375+
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
376+
377+
Toast.makeText(MainActivity.this, "监听服务启动中...", Toast.LENGTH_SHORT).show();
378+
}
348379

349380

350381

@@ -372,6 +403,46 @@ public static String md5(String string) {
372403
return "";
373404
}
374405

406+
public boolean isNotificationListenersEnabled() {
407+
String pkgName = getPackageName();
408+
final String flat = Settings.Secure.getString(getContentResolver(), "enabled_notification_listeners");
409+
if (!TextUtils.isEmpty(flat)) {
410+
final String[] names = flat.split(":");
411+
for (int i = 0; i < names.length; i++) {
412+
final ComponentName cn = ComponentName.unflattenFromString(names[i]);
413+
if (cn != null) {
414+
if (TextUtils.equals(pkgName, cn.getPackageName())) {
415+
return true;
416+
}
417+
}
418+
}
419+
}
420+
return false;
421+
}
422+
protected boolean gotoNotificationAccessSetting() {
423+
try {
424+
Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
425+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
426+
startActivity(intent);
427+
return true;
428+
429+
} catch (ActivityNotFoundException e) {//普通情况下找不到的时候需要再特殊处理找一次
430+
try {
431+
Intent intent = new Intent();
432+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
433+
ComponentName cn = new ComponentName("com.android.settings", "com.android.settings.Settings$NotificationAccessSettingsActivity");
434+
intent.setComponent(cn);
435+
intent.putExtra(":settings:show_fragment", "NotificationAccessSettings");
436+
startActivity(intent);
437+
return true;
438+
} catch (Exception e1) {
439+
e1.printStackTrace();
440+
}
441+
Toast.makeText(this, "对不起,您的手机暂不支持", Toast.LENGTH_SHORT).show();
442+
e.printStackTrace();
443+
return false;
444+
}
445+
}
375446

376447

377448
@Override

app/src/main/java/com/vone/vmq/NeNotificationService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void onAccessibilityEvent(AccessibilityEvent event) {
7474
Log.d(TAG,"onAccessibilityEvent: 应用包名:" + event.getPackageName());
7575
Log.d(TAG,"onAccessibilityEvent: 推送内容:" + event.getText());
7676

77-
77+
/*
7878
7979
List<CharSequence> texts = event.getText();
8080
@@ -144,6 +144,7 @@ public void run(){
144144
}
145145
}
146146
}
147+
*/
147148

148149
}
149150

0 commit comments

Comments
 (0)