Skip to content

Commit

Permalink
v1.6版本
Browse files Browse the repository at this point in the history
  • Loading branch information
szvone committed May 16, 2019
1 parent 8849afc commit 3992f6d
Show file tree
Hide file tree
Showing 7 changed files with 320 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ V免签为完全开源项目,开源项目意味着作者没有任何收入来
+ 微信店员收款推送通知

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

+ v1.5(2019.04.24)
+ 修复部分手机扫码配置失败的问题!
Expand Down
Binary file modified app/app-release.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ android {
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.vone.qrcode"
minSdkVersion 15
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@
<action android:name="android.accessibilityservice.AccessibilityService"/>
</intent-filter>
</service>


<service
android:name="com.vone.vmq.NeNotificationService2"
android:label="@string/app_name"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>


</application>

</manifest>
79 changes: 75 additions & 4 deletions app/src/main/java/com/vone/vmq/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
Expand All @@ -35,6 +36,7 @@
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Date;
import java.util.Set;

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

if (!isNotificationListenersEnabled()) {
gotoNotificationAccessSetting();
}

// if (!isNotificationListenerServiceEnabled(this)){
//
// }
toggleNotificationListenerService(this);



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


public void checkPush(View v){
if (!btnStart.getText().equals("检测服务状态")){
Toast.makeText(MainActivity.this, "请先开启服务!", Toast.LENGTH_SHORT).show();
return;
}
// if (!btnStart.getText().equals("检测服务状态")){
// Toast.makeText(MainActivity.this, "请先开启服务!", Toast.LENGTH_SHORT).show();
// return;
// }



Notification mNotification;
NotificationManager mNotificationManager;
Expand Down Expand Up @@ -344,7 +358,24 @@ public void checkPush(View v){
}


private static boolean isNotificationListenerServiceEnabled(Context context) {
Set<String> packageNames = NotificationManagerCompat.getEnabledListenerPackages(context);
if (packageNames.contains(context.getPackageName())) {
return true;
}
return false;
}

private void toggleNotificationListenerService(Context context) {
PackageManager pm = context.getPackageManager();
pm.setComponentEnabledSetting(new ComponentName(context, NeNotificationService2.class),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

pm.setComponentEnabledSetting(new ComponentName(context, NeNotificationService2.class),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);

Toast.makeText(MainActivity.this, "监听服务启动中...", Toast.LENGTH_SHORT).show();
}



Expand Down Expand Up @@ -372,6 +403,46 @@ public static String md5(String string) {
return "";
}

public boolean isNotificationListenersEnabled() {
String pkgName = getPackageName();
final String flat = Settings.Secure.getString(getContentResolver(), "enabled_notification_listeners");
if (!TextUtils.isEmpty(flat)) {
final String[] names = flat.split(":");
for (int i = 0; i < names.length; i++) {
final ComponentName cn = ComponentName.unflattenFromString(names[i]);
if (cn != null) {
if (TextUtils.equals(pkgName, cn.getPackageName())) {
return true;
}
}
}
}
return false;
}
protected boolean gotoNotificationAccessSetting() {
try {
Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
return true;

} catch (ActivityNotFoundException e) {//普通情况下找不到的时候需要再特殊处理找一次
try {
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ComponentName cn = new ComponentName("com.android.settings", "com.android.settings.Settings$NotificationAccessSettingsActivity");
intent.setComponent(cn);
intent.putExtra(":settings:show_fragment", "NotificationAccessSettings");
startActivity(intent);
return true;
} catch (Exception e1) {
e1.printStackTrace();
}
Toast.makeText(this, "对不起,您的手机暂不支持", Toast.LENGTH_SHORT).show();
e.printStackTrace();
return false;
}
}


@Override
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/vone/vmq/NeNotificationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void onAccessibilityEvent(AccessibilityEvent event) {
Log.d(TAG,"onAccessibilityEvent: 应用包名:" + event.getPackageName());
Log.d(TAG,"onAccessibilityEvent: 推送内容:" + event.getText());


/*
List<CharSequence> texts = event.getText();
Expand Down Expand Up @@ -144,6 +144,7 @@ public void run(){
}
}
}
*/

}

Expand Down
Loading

0 comments on commit 3992f6d

Please sign in to comment.