diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 29e30c9..3bb66ca 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,11 +1,13 @@ + + diff --git a/app/src/main/java/monitor/mobie/hdy/im/MainActivity.java b/app/src/main/java/monitor/mobie/hdy/im/MainActivity.java index 0ee36ec..73c7aea 100644 --- a/app/src/main/java/monitor/mobie/hdy/im/MainActivity.java +++ b/app/src/main/java/monitor/mobie/hdy/im/MainActivity.java @@ -10,10 +10,13 @@ import android.database.sqlite.SQLiteDatabase; import android.graphics.drawable.Drawable; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Message; +import android.os.PowerManager; import android.support.annotation.NonNull; +import android.support.annotation.RequiresApi; import android.support.v4.app.NotificationManagerCompat; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; @@ -44,7 +47,6 @@ public class MainActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //检查更新 - Log.i("APP checking update","loading"); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); @@ -67,6 +69,7 @@ private void init() { tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("介绍", null).setContent(R.id.tab1)); tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("推送设置", null).setContent(R.id.tab2)); tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("通知设置", null).setContent(R.id.tab3)); + tabHost.addTab(tabHost.newTabSpec("tab4").setIndicator("更多设置", null).setContent(R.id.tab4)); if (!isNotificationListenerServiceEnabled(this)) { Toast.makeText(this, "请先勾选手机监听器的读取通知栏权限!", Toast.LENGTH_LONG).show(); return; @@ -145,6 +148,11 @@ protected void onResume() { //说明需要重新获取数据 myHandler.sendEmptyMessage(0x3); } + if(Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { + if (!isIgnoringBatteryOptimizations()) { + Toast.makeText(this, "请将省电优化设置为无限制,关闭对通知器的省电优化有助于防止程序被杀!!", Toast.LENGTH_LONG).show(); + } + } startService(serviceIntent); } @@ -175,6 +183,24 @@ private static boolean isNotificationListenerServiceEnabled(Context context) { return false; } + /** + * 判断系统是否已经关闭省电优化 + * @return + */ + @RequiresApi(api = Build.VERSION_CODES.M) + private boolean isIgnoringBatteryOptimizations() { + boolean isIgnoring = false; + PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); + if (powerManager != null) { + isIgnoring = powerManager.isIgnoringBatteryOptimizations(getPackageName()); + } + if (!isIgnoring){ + Intent i = new Intent(android.provider.Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); + startActivity(i); + } + return isIgnoring; + } + private static final String ACTION_NOTIFICATION_LISTENER_SETTINGS = "android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"; private void openNotificationAccess() { @@ -228,4 +254,24 @@ public void run() { } }).start(); } + + /** + * 跳转到指定应用的首页 + */ + private void showActivity(@NonNull String packageName) { + Intent intent = getPackageManager().getLaunchIntentForPackage(packageName); + startActivity(intent); + } + + /** + * 跳转到指定应用的指定页面 + */ + private void showActivity(@NonNull String packageName, @NonNull String activityDir) { + Intent intent = new Intent(); + intent.setComponent(new ComponentName(packageName, activityDir)); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + } + + } diff --git a/app/src/main/java/monitor/mobie/hdy/im/broadcastreciver/BootBroadcastReciver.java b/app/src/main/java/monitor/mobie/hdy/im/broadcastreciver/BootBroadcastReciver.java index cbde4e6..571b5d5 100644 --- a/app/src/main/java/monitor/mobie/hdy/im/broadcastreciver/BootBroadcastReciver.java +++ b/app/src/main/java/monitor/mobie/hdy/im/broadcastreciver/BootBroadcastReciver.java @@ -11,8 +11,6 @@ */ public class BootBroadcastReciver extends BroadcastReceiver { - private MonitorService monitorService; - private boolean flag; @Override public void onReceive(Context context, Intent intent) { diff --git a/app/src/main/java/monitor/mobie/hdy/im/config/Constant.java b/app/src/main/java/monitor/mobie/hdy/im/config/Constant.java index 639ffb6..9c74f87 100644 --- a/app/src/main/java/monitor/mobie/hdy/im/config/Constant.java +++ b/app/src/main/java/monitor/mobie/hdy/im/config/Constant.java @@ -30,4 +30,121 @@ public interface Constant { public static final String EMAIL_TYPE = "email_type"; public static final String EMAIL_RECEIVER = "email_receiver"; + + /** + * 预设常用的软件包名,一键启用对对应软件的通知接收 + */ + //中国常用社交软件 + public static final String[] ChinaTalkAPP = { + "com.tencent.mobileqq", + "com.tencent.mm", + "com.alibaba.android.rimet", + "com.tencent.qqlite", + "com.tencent.minihd.qq", + "com.tencent.mobileqqi", + "com.tencent.tim", + "com.bullet.messenger", + "im.yixin", + "com.juphoon.justalk", + "com.tencent.eim", + "com.tencent.wework", + "com.sina.weibo", + "com.p1.mobile.putong", + "com.immomo.momo" + }; + + //中国常用购物消费软件 + public static final String[] ChinaShopAPP = { + "com.taobao.taobao", + "com.eg.android.AlipayGphone", + "com.jingdong.app.mall", + "com.sankuai.meituan", + "com.taobao.idlefish", + "com.xunmeng.pinduoduo", + "com.xiaomi.shop", + "com.tmall.wireless", + "com.suning.mobile.ebuy", + "com.alibaba.wireless", + "com.xingin.xhs", + "com.nuomi", + "com.dangdang.buy2", + "com.netease.yanxuan", + "com.koudai.weidian.buyer", + "com.thestore.main", + "com.gome.eshopnew", + "com.huodao.hdphone", + "com.fenqile.fenqile", + "com.taobao.litetao", + "com.jm.android.jumei", + "com.meilishuo", + "com.jd.jdlite", + "com.meituan.retail.v.android", + "cn.missfresh.application", + "com.baidu.wallet", + "com.wangyin.payment" + }; + + //国外常用社交软件 + public static final String[] OtherTalkAPP = { + "com.twitter.android", + "jp.naver.line.android", + "com.skype.raider", + "com.facebook.katana", + "com.android.chrome", + "com.whatsapp", + "com.facebook.orca" + }; + + //新闻类软件 + public static final String[] NewsAPP = { + "com.ss.android.article.news", + "com.sina.weibo", + "com.netease.newsreader.activity", + "com.sohu.newsclient" + }; + + //短视频类 + public static final String[] ShortVideos = { + "com.ss.android.ugc.aweme", + "com.smile.gifmaker", + "com.ss.android.ugc.live", + "com.yixia.videoeditor", + "com.youku.phone", + "com.qiyi.video", + "com.tencent.qqlive", + "air.tv.douyu.android", + "com.panda.videoliveplatform" + }; + + + //外卖类 + public static final String[] TakeOut = { + "me.ele", + "com.sankuai.meituan.takeoutnew", + "com.dianping.v1" + }; + + + //音乐类 + public static final String[] Music = { + "com.tencent.qqmusic", + "com.kugou.android", + "com.tencent.karaoke", + "cn.kuwo.player", + "fm.xiami.main", + "com.changba", + "com.netease.cloudmusic", + "com.ximalaya.ting.android" + }; + + // 短信和电话 + public static final String[] PhoneAndMessage = { + "com.android.contacts", + "com.android.dialer", + "com.android.mms", + "com.android.providers.telephony", + "com.android.phone", + "com.android.incallui" + }; + } diff --git a/app/src/main/java/monitor/mobie/hdy/im/fragment/NotificationSettingFrament.java b/app/src/main/java/monitor/mobie/hdy/im/fragment/NotificationSettingFrament.java index 962cc6c..550452a 100644 --- a/app/src/main/java/monitor/mobie/hdy/im/fragment/NotificationSettingFrament.java +++ b/app/src/main/java/monitor/mobie/hdy/im/fragment/NotificationSettingFrament.java @@ -32,14 +32,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) { private void init() { final SQLiteDatabase writeInstance = AppinfosDatabase.getWriteInstance(getContext()); - SwitchPreference listenAll = (SwitchPreference) findPreference("listenAll"); - Preference light = findPreference("LIGHT"); - light.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - return true; - } - }); + SwitchPreference listenAll = (SwitchPreference) findPreference("customListen"); listenAll.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { @@ -47,9 +40,9 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { MainActivity mainActivity = (MainActivity) getActivity(); if (b) { AppinfosDatabase.getInstance(getContext()).removeAll(writeInstance); - mainActivity.myHandler.sendEmptyMessage(0x2); - } else { mainActivity.myHandler.sendEmptyMessage(0x3); + } else { + mainActivity.myHandler.sendEmptyMessage(0x2); } return true; } diff --git a/app/src/main/java/monitor/mobie/hdy/im/fragment/OtherSettingFrament.java b/app/src/main/java/monitor/mobie/hdy/im/fragment/OtherSettingFrament.java new file mode 100644 index 0000000..8ee2d10 --- /dev/null +++ b/app/src/main/java/monitor/mobie/hdy/im/fragment/OtherSettingFrament.java @@ -0,0 +1,43 @@ +package monitor.mobie.hdy.im.fragment; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.os.Build; +import android.os.Bundle; +import android.preference.Preference; +import android.preference.PreferenceFragment; +import android.preference.SwitchPreference; +import android.support.annotation.Nullable; +import android.support.annotation.RequiresApi; + +import monitor.mobie.hdy.im.MainActivity; +import monitor.mobie.hdy.im.R; +import monitor.mobie.hdy.im.database.AppinfosDatabase; + +/** + * Created by hdy on 2021/9/29. + * 其他设置fragment + */ + +public class OtherSettingFrament extends PreferenceFragment { + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + getPreferenceManager().setSharedPreferencesName("data"); + getPreferenceManager().setSharedPreferencesMode(Context.MODE_MULTI_PROCESS); + addPreferencesFromResource(R.xml.preference_others); + } + + @RequiresApi(api = Build.VERSION_CODES.M) + private void init() { + + } + + @RequiresApi(api = Build.VERSION_CODES.M) + @Override + public void onStart() { + super.onStart(); + init(); + } + +} diff --git a/app/src/main/java/monitor/mobie/hdy/im/service/NotificationCollectorService.java b/app/src/main/java/monitor/mobie/hdy/im/service/NotificationCollectorService.java index 1135af1..5ae3929 100644 --- a/app/src/main/java/monitor/mobie/hdy/im/service/NotificationCollectorService.java +++ b/app/src/main/java/monitor/mobie/hdy/im/service/NotificationCollectorService.java @@ -13,6 +13,7 @@ import java.util.HashMap; import java.util.regex.Pattern; +import monitor.mobie.hdy.im.config.Constant; import monitor.mobie.hdy.im.database.AppinfosDatabase; import monitor.mobie.hdy.im.provider.BarkProvider; import monitor.mobie.hdy.im.provider.CustomProvider; @@ -38,6 +39,8 @@ public void onNotificationPosted(StatusBarNotification sbn) { boolean light = data.getBoolean("LIGHT", false); //是否监听所有的应用 boolean listenAll = data.getBoolean("listenAll", true); + //是否开启了自定义应用监听 + boolean customApp = data.getBoolean("customListen",false); //获取屏蔽关键词 String block = data.getString("block", ""); //获取内容 @@ -46,6 +49,21 @@ public void onNotificationPosted(StatusBarNotification sbn) { String title = sbn.getNotification().extras.get("android.title").toString(); //获取推送应用的包名 String packageName = sbn.getPackageName(); + + + + // 预设通知转发 + boolean PhoneAndMessage = data.getBoolean("PhoneAndMessage",false); + boolean ChinaTalkAPP = data.getBoolean("ChinaTalkAPP",false); + boolean ChinaShopAPP = data.getBoolean("ChinaShopAPP",false); + boolean NewsAPP = data.getBoolean("NewsAPP",false); + boolean OtherTalkAPP = data.getBoolean("OtherTalkAPP",false); + boolean ShortVideos = data.getBoolean("ShortVideos",false); + boolean TakeOut = data.getBoolean("TakeOut",false); + boolean Music = data.getBoolean("Music",false); + + + Log.i("接收到数据", text); if (!block.isEmpty()) { //判断是否包含关键词 @@ -78,7 +96,8 @@ public void onNotificationPosted(StatusBarNotification sbn) { } } //判断当前的app是否需要能被push - boolean appNeedPush = isAppNeedPush(packageName, listenAll); + boolean appNeedPush = isAppNeedPush(packageName, listenAll,customApp + ,PhoneAndMessage,ChinaTalkAPP,ChinaShopAPP,NewsAPP,OtherTalkAPP,ShortVideos,TakeOut,Music); if (appNeedPush) { try { //进行Server酱推送 @@ -109,22 +128,85 @@ public void onNotificationRemoved(StatusBarNotification sbn) { /** * 判断app是否需要推送 - * * @param packageName 包名 * @param listenAll 是否监听所有 + * @param customApp 是否自定义监听 + * @param phoneAndMessage + * @param chinaTalkAPP + * @param chinaShopAPP + * @param newsAPP + * @param otherTalkAPP + * @param shortVideos + * @param takeOut + * @param music */ - private boolean isAppNeedPush(String packageName, boolean listenAll) { + private boolean isAppNeedPush(String packageName, boolean listenAll, boolean customApp, boolean phoneAndMessage, boolean chinaTalkAPP, boolean chinaShopAPP, boolean newsAPP, boolean otherTalkAPP, boolean shortVideos, boolean takeOut, boolean music) { //这里要进行判断,不需要的packageName就不用通知了. if (!listenAll) { //如果不是全部监听的话 //这里判断当前的包名是否和用户勾选的应用包名相同.如果相同的话就进行通知 //如果不相同就跳过.避免不必要的通知. - SQLiteDatabase database = AppinfosDatabase.getReadInstance(this); - HashMap infos = AppinfosDatabase.getInstance(this).selectAll(database); - if (!infos.containsKey(packageName)) { - return false; + if (customApp) { + SQLiteDatabase database = AppinfosDatabase.getReadInstance(this); + HashMap infos = AppinfosDatabase.getInstance(this).selectAll(database); + if (infos.containsKey(packageName)) { + return true; + } + } + + //系统预设app + if (phoneAndMessage){ + if(appInArray(Constant.PhoneAndMessage,packageName)){ + return true; + }; } + + if (chinaShopAPP){ + if(appInArray(Constant.ChinaShopAPP,packageName)){ + return true; + }; } + + if(chinaTalkAPP){ + if(appInArray(Constant.ChinaTalkAPP,packageName)){ + return true; + }; } + + if(newsAPP){ + if(appInArray(Constant.NewsAPP,packageName)){ + return true; + }; } + + if(otherTalkAPP){ + if(appInArray(Constant.OtherTalkAPP,packageName)){ + return true; + }; } + + if(shortVideos){ + if(appInArray(Constant.ShortVideos,packageName)){ + return true; + }; } + + if(takeOut){ + if(appInArray(Constant.TakeOut,packageName)){ + return true; + }; } + + if(music){ + if(appInArray(Constant.Music,packageName)){ + return true; + }; + } + return false; } return true; } + + private boolean appInArray(String[] arr,String packageName){ + for(int i = 0;i + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3f7620a..ff7d4da 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,7 +1,7 @@ 恶搞大王通知转发器 恶搞大王 - 4.1 + 4.3 本程序完全免费开源 开源地址请点击这里 @@ -17,7 +17,7 @@ 欢迎使用恶搞大王通知转发器!本转发器完全开源免费使用,请勿用于任何的非法用途。\n 本工具的初衷刚开始只是为了方便自身的生活,后来发现效果不错于是决定开源出去希望能帮助更多的人。\n\n - 目的:对于一个多张手机卡的人来说有时候携带好几个手机实在太麻烦,我为了解决这个问题于是开发这个工具能够监听Android手机的通知栏并将数据转发到微信或自身的服务器上。这样我就可以远程接收到短信或者电话的了!\n + 目的:对于一个多张手机卡的人来说有时候携带好几个手机实在太麻烦,我为了解决这个问题于是开发这个工具能够监听Android手机的通知栏并将数据转发到微信或自身的服务器上。这样我就可以远程接收到短信或者电话的通知了!\n \n \n 目前支持的功能:\n @@ -25,11 +25,16 @@ 2. 企业微信推送->普通微信(支持多行输入,但必须要保证顺序)\n 3. 自定义推送地址(可以多行输入,同时发送给任意多个自定义地址)\n 4. 自定义选择需要推送应用\n + 5. Bark推送\n + 6. 邮箱推送 \n \n - 本转发器完全开源免费使用,请勿用于任何的非法用途。\n - 本转发器完全开源免费使用,请勿用于任何的非法用途。\n - 本转发器完全开源免费使用,请勿用于任何的非法用途。\n + 如何防止程序被杀:\n + 1. 确保给程序加锁,防止清理被清理后台\n + 2. 关闭对通知转发器的省电优化功能\n + 3. 开启通知转发器的自启动功能\n + \n + 声明:本转发器完全开源免费使用,请勿用于任何的非法用途。\n diff --git a/app/src/main/res/xml/preference_notification.xml b/app/src/main/res/xml/preference_notification.xml index f7db757..b882fd1 100644 --- a/app/src/main/res/xml/preference_notification.xml +++ b/app/src/main/res/xml/preference_notification.xml @@ -2,23 +2,13 @@ - - + android:defaultValue="false" + android:key="customListen" + android:summary="自定义选择要监听的应用" + android:title="监听自定义应用" /> diff --git a/app/src/main/res/xml/preference_others.xml b/app/src/main/res/xml/preference_others.xml new file mode 100644 index 0000000..a0fd2f5 --- /dev/null +++ b/app/src/main/res/xml/preference_others.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file