修复:无标题通知导致空指针FC
整理:代码梳理,删除无用图标
@ -31,6 +31,7 @@ import com.idormy.sms.forwarder.utils.PhoneUtils;
|
|||||||
import com.idormy.sms.forwarder.utils.SettingUtil;
|
import com.idormy.sms.forwarder.utils.SettingUtil;
|
||||||
import com.idormy.sms.forwarder.utils.SmsUtil;
|
import com.idormy.sms.forwarder.utils.SmsUtil;
|
||||||
import com.idormy.sms.forwarder.utils.TimeUtil;
|
import com.idormy.sms.forwarder.utils.TimeUtil;
|
||||||
|
import com.umeng.analytics.MobclickAgent;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -67,9 +68,13 @@ public class MainActivity extends AppCompatActivity implements RefreshListView.I
|
|||||||
NetUtil.init(this);
|
NetUtil.init(this);
|
||||||
|
|
||||||
//前台服务
|
//前台服务
|
||||||
|
try {
|
||||||
serviceIntent = new Intent(MainActivity.this, FrontService.class);
|
serviceIntent = new Intent(MainActivity.this, FrontService.class);
|
||||||
serviceIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
serviceIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
startService(serviceIntent);
|
startService(serviceIntent);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "onCreate:", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -147,6 +152,8 @@ public class MainActivity extends AppCompatActivity implements RefreshListView.I
|
|||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
MobclickAgent.onResume(this);
|
||||||
|
|
||||||
//第一次打开,未授权无法获取SIM信息,尝试在此重新获取
|
//第一次打开,未授权无法获取SIM信息,尝试在此重新获取
|
||||||
if (MyApplication.SimInfoList.isEmpty()) {
|
if (MyApplication.SimInfoList.isEmpty()) {
|
||||||
MyApplication.SimInfoList = PhoneUtils.getSimMultiInfo();
|
MyApplication.SimInfoList = PhoneUtils.getSimMultiInfo();
|
||||||
@ -156,7 +163,7 @@ public class MainActivity extends AppCompatActivity implements RefreshListView.I
|
|||||||
//省电优化设置为无限制
|
//省电优化设置为无限制
|
||||||
if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
||||||
if (!KeepAliveUtils.isIgnoreBatteryOptimization(this)) {
|
if (!KeepAliveUtils.isIgnoreBatteryOptimization(this)) {
|
||||||
Toast.makeText(this, "请将省电优化设置为无限制(不优化),有利于《短信转发器》保活!", Toast.LENGTH_LONG).show();
|
Toast.makeText(this, R.string.tips_battery_optimization, Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,22 +171,36 @@ public class MainActivity extends AppCompatActivity implements RefreshListView.I
|
|||||||
if (SettingUtil.getSwitchEnableAppNotify() && !CommonUtil.isNotificationListenerServiceEnabled(this)) {
|
if (SettingUtil.getSwitchEnableAppNotify() && !CommonUtil.isNotificationListenerServiceEnabled(this)) {
|
||||||
CommonUtil.toggleNotificationListenerService(this);
|
CommonUtil.toggleNotificationListenerService(this);
|
||||||
SettingUtil.switchEnableAppNotify(false);
|
SettingUtil.switchEnableAppNotify(false);
|
||||||
Toast.makeText(this, "请先授予《短信转发器》通知使用权,否则无法转发APP通知,已经自动关闭转发!", Toast.LENGTH_LONG).show();
|
Toast.makeText(this, R.string.tips_notification_listener, Toast.LENGTH_LONG).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
startService(serviceIntent);
|
|
||||||
|
try {
|
||||||
|
if (serviceIntent != null) startService(serviceIntent);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "onResume:", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
startService(serviceIntent);
|
try {
|
||||||
|
if (serviceIntent != null) startService(serviceIntent);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "onDestroy:", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
startService(serviceIntent);
|
MobclickAgent.onPause(this);
|
||||||
|
try {
|
||||||
|
if (serviceIntent != null) startService(serviceIntent);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "onPause:", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -187,10 +208,10 @@ public class MainActivity extends AppCompatActivity implements RefreshListView.I
|
|||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
if (requestCode == CommonUtil.NOTIFICATION_REQUEST_CODE) {
|
if (requestCode == CommonUtil.NOTIFICATION_REQUEST_CODE) {
|
||||||
if (CommonUtil.isNotificationListenerServiceEnabled(this)) {
|
if (CommonUtil.isNotificationListenerServiceEnabled(this)) {
|
||||||
Toast.makeText(this, "通知服务已开启", Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.notification_listener_service_enabled, Toast.LENGTH_SHORT).show();
|
||||||
CommonUtil.toggleNotificationListenerService(this);
|
CommonUtil.toggleNotificationListenerService(this);
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(this, "通知服务未开启", Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.notification_listener_service_disabled, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,6 +75,8 @@ public class MyApplication extends Application {
|
|||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
Log.d(TAG, "onCreate");
|
Log.d(TAG, "onCreate");
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
|
||||||
|
try {
|
||||||
//初始化组件化基础库, 所有友盟业务SDK都必须调用此初始化接口。
|
//初始化组件化基础库, 所有友盟业务SDK都必须调用此初始化接口。
|
||||||
//建议在宿主App的Application.onCreate函数中调用基础组件库初始化函数。
|
//建议在宿主App的Application.onCreate函数中调用基础组件库初始化函数。
|
||||||
UMConfigure.init(this, "60254fc7425ec25f10f4293e", getChannelName(this), UMConfigure.DEVICE_TYPE_PHONE, "");
|
UMConfigure.init(this, "60254fc7425ec25f10f4293e", getChannelName(this), UMConfigure.DEVICE_TYPE_PHONE, "");
|
||||||
@ -96,6 +98,8 @@ public class MyApplication extends Application {
|
|||||||
|
|
||||||
SharedPreferences sp = MyApplication.this.getSharedPreferences(Define.SP_CONFIG, Context.MODE_PRIVATE);
|
SharedPreferences sp = MyApplication.this.getSharedPreferences(Define.SP_CONFIG, Context.MODE_PRIVATE);
|
||||||
showHelpTip = sp.getBoolean(Define.SP_CONFIG_SWITCH_HELP_TIP, true);
|
showHelpTip = sp.getBoolean(Define.SP_CONFIG_SWITCH_HELP_TIP, true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "onCreate:", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -361,7 +361,7 @@ public class SettingActivity extends AppCompatActivity {
|
|||||||
if (!CommonUtil.isNotificationListenerServiceEnabled(this)) {
|
if (!CommonUtil.isNotificationListenerServiceEnabled(this)) {
|
||||||
CommonUtil.openNotificationAccess(this);
|
CommonUtil.openNotificationAccess(this);
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(this, "通知服务已开启", Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.notification_listener_service_enabled, Toast.LENGTH_SHORT).show();
|
||||||
CommonUtil.toggleNotificationListenerService(this);
|
CommonUtil.toggleNotificationListenerService(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -371,11 +371,16 @@ public class SettingActivity extends AppCompatActivity {
|
|||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
if (requestCode == CommonUtil.NOTIFICATION_REQUEST_CODE) {
|
if (requestCode == CommonUtil.NOTIFICATION_REQUEST_CODE) {
|
||||||
if (CommonUtil.isNotificationListenerServiceEnabled(this)) {
|
if (CommonUtil.isNotificationListenerServiceEnabled(this)) {
|
||||||
Toast.makeText(this, "通知服务已开启", Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.notification_listener_service_enabled, Toast.LENGTH_SHORT).show();
|
||||||
CommonUtil.toggleNotificationListenerService(this);
|
CommonUtil.toggleNotificationListenerService(this);
|
||||||
|
SettingUtil.switchEnableAppNotify(true);
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(this, "通知服务未开启", Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.notification_listener_service_disabled, Toast.LENGTH_SHORT).show();
|
||||||
|
SettingUtil.switchEnableAppNotify(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("UseSwitchCompatOrMaterialCode") Switch switch_enable_app_notify = findViewById(R.id.switch_enable_app_notify);
|
||||||
|
switch_enable_app_notify.setChecked(SettingUtil.getSwitchEnableAppNotify());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.idormy.sms.forwarder.adapter;
|
package com.idormy.sms.forwarder.adapter;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -40,6 +41,7 @@ public class AppAdapter extends ArrayAdapter<AppInfo> {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
AppInfo appInfo = getItem(position); //获取当前项的TLog实例
|
AppInfo appInfo = getItem(position); //获取当前项的TLog实例
|
||||||
|
@ -3,6 +3,8 @@ package com.idormy.sms.forwarder.model;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@ -34,6 +36,7 @@ public class AppInfo {
|
|||||||
this.verCode = verCode;
|
this.verCode = verCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "AppInfo{" +
|
return "AppInfo{" +
|
||||||
|
@ -41,10 +41,17 @@ public class NotifyService extends NotificationListenerService {
|
|||||||
//自身通知跳过
|
//自身通知跳过
|
||||||
if ("com.idormy.sms.forwarder".equals(packageName)) return;
|
if ("com.idormy.sms.forwarder".equals(packageName)) return;
|
||||||
|
|
||||||
|
try {
|
||||||
//通知标题
|
//通知标题
|
||||||
String title = sbn.getNotification().extras.get("android.title").toString();
|
String title = "";
|
||||||
|
if (sbn.getNotification().extras.get("android.title") != null) {
|
||||||
|
title = sbn.getNotification().extras.get("android.title").toString();
|
||||||
|
}
|
||||||
//通知内容
|
//通知内容
|
||||||
String text = sbn.getNotification().extras.get("android.text").toString();
|
String text = "";
|
||||||
|
if (sbn.getNotification().extras.get("android.text") != null) {
|
||||||
|
text = sbn.getNotification().extras.get("android.text").toString();
|
||||||
|
}
|
||||||
if (text.isEmpty() && sbn.getNotification().tickerText != null) {
|
if (text.isEmpty() && sbn.getNotification().tickerText != null) {
|
||||||
text = sbn.getNotification().tickerText.toString();
|
text = sbn.getNotification().tickerText.toString();
|
||||||
}
|
}
|
||||||
@ -72,7 +79,9 @@ public class NotifyService extends NotificationListenerService {
|
|||||||
SmsVo smsVo = new SmsVo(packageName, text, new Date(), title);
|
SmsVo smsVo = new SmsVo(packageName, text, new Date(), title);
|
||||||
Log.d(TAG, "send_msg" + smsVo.toString());
|
Log.d(TAG, "send_msg" + smsVo.toString());
|
||||||
SendUtil.send_msg(this, smsVo, 1, "app");
|
SendUtil.send_msg(this, smsVo, 1, "app");
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "onNotificationPosted:", e);
|
||||||
|
}
|
||||||
//NotifyHelper.getInstance().onReceive(sbn);
|
//NotifyHelper.getInstance().onReceive(sbn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@
|
|||||||
android:background="@color/colorPrimary"
|
android:background="@color/colorPrimary"
|
||||||
android:onClick="cleanLog"
|
android:onClick="cleanLog"
|
||||||
android:text="@string/bt_refresh_log"
|
android:text="@string/bt_refresh_log"
|
||||||
tools:ignore="ButtonStyle,NestedWeights" />
|
tools:ignore="ButtonStyle,NestedWeights,UsingOnClickInXml" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -86,7 +86,7 @@
|
|||||||
android:background="@color/colorPrimary"
|
android:background="@color/colorPrimary"
|
||||||
android:onClick="toRuleSetting"
|
android:onClick="toRuleSetting"
|
||||||
android:text="@string/rule_setting"
|
android:text="@string/rule_setting"
|
||||||
tools:ignore="ButtonStyle,NestedWeights" />
|
tools:ignore="ButtonStyle,NestedWeights,UsingOnClickInXml" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -99,7 +99,7 @@
|
|||||||
android:background="@color/colorPrimary"
|
android:background="@color/colorPrimary"
|
||||||
android:onClick="toSendSetting"
|
android:onClick="toSendSetting"
|
||||||
android:text="@string/sender_setting"
|
android:text="@string/sender_setting"
|
||||||
tools:ignore="ButtonStyle" />
|
tools:ignore="ButtonStyle,UsingOnClickInXml" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 321 B |
Before Width: | Height: | Size: 535 B |
Before Width: | Height: | Size: 253 B |
Before Width: | Height: | Size: 385 B |
Before Width: | Height: | Size: 466 B |
Before Width: | Height: | Size: 807 B |
Before Width: | Height: | Size: 603 B |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 837 B |
Before Width: | Height: | Size: 1.6 KiB |
@ -217,4 +217,8 @@
|
|||||||
<string name="appicon">App Icon</string>
|
<string name="appicon">App Icon</string>
|
||||||
<string name="user_app">User App</string>
|
<string name="user_app">User App</string>
|
||||||
<string name="system_app">System App</string>
|
<string name="system_app">System App</string>
|
||||||
|
<string name="tips_battery_optimization">请将省电优化设置为无限制(不优化),有利于《短信转发器》保活!</string>
|
||||||
|
<string name="tips_notification_listener">请先授予《短信转发器》通知使用权,否则无法转发APP通知,已经自动关闭转发!</string>
|
||||||
|
<string name="notification_listener_service_enabled">通知服务已开启</string>
|
||||||
|
<string name="notification_listener_service_disabled">通知服务未开启</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -216,4 +216,8 @@
|
|||||||
<string name="appicon">应用图标</string>
|
<string name="appicon">应用图标</string>
|
||||||
<string name="user_app">用户应用</string>
|
<string name="user_app">用户应用</string>
|
||||||
<string name="system_app">系统应用</string>
|
<string name="system_app">系统应用</string>
|
||||||
|
<string name="tips_battery_optimization">请将省电优化设置为无限制(不优化),有利于《短信转发器》保活!</string>
|
||||||
|
<string name="tips_notification_listener">请先授予《短信转发器》通知使用权,否则无法转发APP通知,已经自动关闭转发!</string>
|
||||||
|
<string name="notification_listener_service_enabled">通知服务已开启</string>
|
||||||
|
<string name="notification_listener_service_disabled">通知服务未开启</string>
|
||||||
</resources>
|
</resources>
|
||||||
|