Skip to content

Commit

Permalink
适配微信7.0.3
Browse files Browse the repository at this point in the history
1、适配微信7.0.3
2、修改通知栏监听机制,修复Android9.0通知栏不能监听的问题
3、加入腾讯Ticker热更新框架
  • Loading branch information
LnJan committed Jan 30, 2019
1 parent 7b208f0 commit 2bf5aa3
Show file tree
Hide file tree
Showing 10 changed files with 300 additions and 43 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apply plugin: 'com.android.application'
// 依赖插件脚本
//apply from: 'tinker-support.gradle'
apply from: 'tinker-support.gradle'

android {
signingConfigs {
Expand All @@ -16,8 +16,8 @@ android {
applicationId "com.shareder.ln_jan.wechatluckymoneygetter"
minSdkVersion 21
targetSdkVersion 26
versionCode 13
versionName "1.1.5"
versionCode 15
versionName "1.1.7"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
ndk {
//设置支持的SO库架构
Expand Down
20 changes: 15 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.shareder.ln_jan.wechatluckymoneygetter">

<!-- Bugly 权限配置 -->
<!-- Bugly 权限配置 -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<!-- 息屏抢红包相关权限 -->
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<!-- 息屏抢红包相关权限 -->
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<application
android:name=".tinker.LuckyMoneyTinkerApplication"
Expand All @@ -34,6 +34,7 @@
android:name="com.tencent.bugly.beta.ui.BetaActivity"
android:configChanges="keyboardHidden|orientation|screenSize|locale"
android:theme="@android:style/Theme.Translucent" />

<service
android:name=".service.HongbaoService"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
Expand All @@ -44,14 +45,23 @@
android:name="android.accessibilityservice"
android:resource="@xml/accessible_service_config" />
</service>
<service
android:name=".service.HongbaoNotificationListenerService"
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>

<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.fileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
android:resource="@xml/provider_paths" />
</provider>
</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
Expand Down Expand Up @@ -46,6 +47,8 @@ public class MainActivity extends AppCompatActivity implements AccessibilityMana
private AccessibilityManager accessibilityManager;
private Switch service_switch;
private MainActivityHandler mHandler = new MainActivityHandler(this);
private SettingPreferenceFragment mFragment = new SettingPreferenceFragment();
private SharedPreferences mSharedPreferences;
private static final String SHOWDIALOG_TAG = "NotShowPowerDialog";
private static final int HANDLER_REQUEST_AUTHOR = 0x01;
private static final int HANDLER_SHOW_POWER_DIALOG = 0x02;
Expand Down Expand Up @@ -83,12 +86,13 @@ protected void onCreate(Bundle savedInstanceState) {
accessibilityManager.addAccessibilityStateChangeListener(this);
}

mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

service_switch = findViewById(R.id.service_open_switch);
service_switch.setOnClickListener(this);

handleMIUIStatusBar();
loadFragmentActivity();
//requestScreenShot();

FeatureDetectionManager.getInstance().createLuckyMoneyPicture();

Expand Down Expand Up @@ -178,7 +182,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
}
}
if (builder.length() > 0) {
builder.deleteCharAt(builder.length()-1);
builder.deleteCharAt(builder.length() - 1);
Toast.makeText(this, builder.toString(), Toast.LENGTH_SHORT).show();
}
mHandler.sendEmptyMessage(HANDLER_SHOW_POWER_DIALOG);
Expand Down Expand Up @@ -241,19 +245,23 @@ private void handleMIUIStatusBar() {
private void loadFragmentActivity() {
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.preferences_fragment, new SettingPreferenceFragment());
fragmentTransaction.replace(R.id.preferences_fragment, mFragment);
fragmentTransaction.commit();
}

/**
* 更新当前 HongbaoService 显示状态
*/
private void updateServiceStatus() {
SharedPreferences.Editor editor=mSharedPreferences.edit();
if (isServiceEnabled()) {
service_switch.setChecked(true);
editor.putBoolean("HongBaoServiceEnable",true);
} else {
service_switch.setChecked(false);
editor.putBoolean("HongBaoServiceEnable",false);
}
editor.apply();
}

/**
Expand Down Expand Up @@ -293,7 +301,7 @@ public void onClick(boolean isChecked) {
dialog.dismiss();
}
});
if(!isFinishing()){
if (!isFinishing()) {
dialog.show();
}
}
Expand Down Expand Up @@ -331,7 +339,7 @@ private void checkAuthority() {
authorList.add(Manifest.permission.READ_PHONE_STATE);
}
if (!authorList.isEmpty()) {
if(isFinishing()){
if (isFinishing()) {
return;
}
AuthorDetailDialog dialog = new AuthorDetailDialog(this, R.style.Transparent);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
package com.shareder.ln_jan.wechatluckymoneygetter.fragments;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.media.projection.MediaProjectionManager;
import android.net.Uri;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.support.annotation.Nullable;
import android.support.v4.app.NotificationManagerCompat;
import android.widget.Toast;

import com.shareder.ln_jan.wechatluckymoneygetter.R;
import com.shareder.ln_jan.wechatluckymoneygetter.global.MyTransparentDialog;
import com.shareder.ln_jan.wechatluckymoneygetter.service.HongbaoNotificationListenerService;
import com.shareder.ln_jan.wechatluckymoneygetter.utils.ScreenShotter;
import com.tencent.bugly.beta.Beta;

import java.util.Set;

/**
* Created by Ln_Jan on 2018/11/8.
* 功能设置Fragment
*/

public class SettingPreferenceFragment extends PreferenceFragment implements
Expand All @@ -30,11 +38,26 @@ public class SettingPreferenceFragment extends PreferenceFragment implements

private static final int REQUEST_MEDIA_PROJECTION = 0x01;


@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.general_preference);
initPrefListeners();
if (isNotificationListenerEnabled(this.getActivity())) {
toggleNotificationListenerService();
}
}

@Override
public void onResume() {
super.onResume();
setWatchNotificationPref(isNotificationListenerEnabled(this.getActivity()));
}

@Override
public void onDestroy() {
super.onDestroy();
}

@Override
Expand All @@ -48,6 +71,8 @@ public boolean onPreferenceChange(Preference preference, Object o) {
b = handleWatchList(preference);
} else if (preference.getKey().equals("pref_watch_exclude_words")) {
b = handleExcludeWords(preference, o);
} else if (preference.getKey().equals("pref_watch_notification")) {
b = handleWatchNotification();
}
return b;
}
Expand Down Expand Up @@ -88,6 +113,13 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
}
}

private void setWatchNotificationPref(boolean b) {
CheckBoxPreference preference = (CheckBoxPreference) findPreference("pref_watch_notification");
if (preference != null) {
preference.setChecked(b);
}
}

private boolean handleWatchChart() {
if (isAutoClickPermit()) {
return true;
Expand All @@ -97,6 +129,14 @@ private boolean handleWatchChart() {
}
}

private boolean handleWatchNotification() {
if (!isNotificationListenerEnabled(this.getActivity())) {
Toast.makeText(this.getActivity(), getString(R.string.notification_tips), Toast.LENGTH_LONG).show();
openNotificationListenSettings();
}
return true;
}

private boolean handleWatchSelf(Preference preference) {
CheckBoxPreference preference1 = (CheckBoxPreference) findPreference("pref_watch_chat");
if (preference1 != null) {
Expand Down Expand Up @@ -150,6 +190,42 @@ private boolean handleExcludeWords(Preference preference, Object o) {
return true;
}

//打开通知监听设置页面
public void openNotificationListenSettings() {
try {
Intent intent;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP_MR1) {
intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS);
} else {
intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
}
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}

//检测通知监听服务是否被授权
public boolean isNotificationListenerEnabled(Context context) {
Set<String> packageNames = NotificationManagerCompat.getEnabledListenerPackages(this.getActivity());
if (packageNames.contains(context.getPackageName())) {
return true;
}
return false;
}

//把应用的NotificationListenerService实现类disable再enable,即可触发系统rebind操作
private void toggleNotificationListenerService() {
PackageManager pm = this.getActivity().getPackageManager();
pm.setComponentEnabledSetting(
new ComponentName(this.getActivity(), HongbaoNotificationListenerService.class),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

pm.setComponentEnabledSetting(
new ComponentName(this.getActivity(), HongbaoNotificationListenerService.class),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
}

/**
* 是否支持自动点击
* API >23 支持
Expand Down Expand Up @@ -180,7 +256,13 @@ private void initPrefListeners() {
CheckBoxPreference watchListPreference = (CheckBoxPreference) findPreference("pref_watch_list");
CheckBoxPreference openPockeyPreference = (CheckBoxPreference) findPreference("pref_watch_chat");
CheckBoxPreference openSelfPockeyPreference = (CheckBoxPreference) findPreference("pref_watch_self");
CheckBoxPreference watchNotificationPreference = (CheckBoxPreference) findPreference("pref_watch_notification");
Preference excludeWordsPref = findPreference("pref_watch_exclude_words");
if (watchListPreference == null || openPockeyPreference == null ||
openSelfPockeyPreference == null || watchNotificationPreference == null ||
excludeWordsPref == null) {
return;
}
String summary = getResources().getString(R.string.pref_watch_exclude_words_summary);
String value = PreferenceManager.getDefaultSharedPreferences(getActivity()).getString("pref_watch_exclude_words", "");
if (value.length() > 0) {
Expand All @@ -190,6 +272,7 @@ private void initPrefListeners() {
watchListPreference.setOnPreferenceChangeListener(this);
openPockeyPreference.setOnPreferenceChangeListener(this);
openSelfPockeyPreference.setOnPreferenceChangeListener(this);
watchNotificationPreference.setOnPreferenceChangeListener(this);
if (watchListPreference.isChecked()) {
requestScreenShot();
}
Expand Down
Loading

0 comments on commit 2bf5aa3

Please sign in to comment.