我有一个已经生产了两年的系统。它是一个用于控制公司设备的EMM系统。
它使用
FireBase
将设备上执行的功能从服务器应用程序发送到设备。
您可以向设备发送大约400个可能的命令,所有这些命令最初都在一个类中处理,该类覆盖了
onMessageReceived()
从
FireBaseMessagingService
类。
旧版本的Android studio构建了现在正在生产的apk。大约一年后,我开始开发我的系统版本2。所以我将我的Android工作室更新到了最新版本(4)。
问题:
当我试图构建项目并推送到设备上时,我得到了
error: code too large public void onMessageReceived(RemoteMessage remoteMessage) {
如前所述
onMessageReceived
方法可以处理来自服务器应用程序的400种不同类型的推送通知,因此方法体中有很多if/else语句。
AS升级后,这不起作用,有什么原因吗?
我可以在AS中更改任何设置来克服这个问题吗?
我所尝试的:
我考虑将一半的if/else放在另一个服务类中,以减少方法代码。这将涉及通过
remoteMessageMap
到另一个类进行if/else处理。
远程消息地图
来自FireBase的是一个Map,而Map在扩展接口时是不可序列化的,因此无法传递它。
public class MyAndroidFirebaseMsgService extends FirebaseMessagingService {
private static final String TAG = "MyAndroidFCMService";
AppObj appObj;
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.e(TAG, "remoteMessage.getData() = " + remoteMessage.getData());
Map remoteMessageMap = remoteMessage.getData();
String message = (String)remoteMessageMap.get("message");
谢谢
[编辑1]
else if(message.trim().equalsIgnoreCase("CLEARCACHE_REMOVE_APP_WL")){
Log.e(TAG, "received CLEARCACHE_REMOVE_APP_WL");
String pushGuid = (String)remoteMessageMap.get("pushguid");
Log.e(TAG, "pushGuid = " + pushGuid);
String clearCacheRemoveWhitelist = (String)remoteMessageMap.get("clear_cache_app_names");
Intent intentExecutePushCommand = new Intent( getApplicationContext(), ExecutePushCommandIntentService.class);
intentExecutePushCommand.putExtra("compID", MenuActivity.companyID);
intentExecutePushCommand.putExtra("command", message);
intentExecutePushCommand.putExtra("pushguid", pushGuid);
intentExecutePushCommand.putExtra("clear_cache_app_names", clearCacheRemoveWhitelist);
startService(intentExecutePushCommand);
}else if(message.trim().equalsIgnoreCase("CLEARCACHE_GET_PACKAGENAMES_WL")){
Log.e(TAG, "received CLEARCACHE_GET_PACKAGENAMES_WL");
String pushGuid = (String)remoteMessageMap.get("pushguid");
Log.e(TAG, "pushGuid = " + pushGuid);
Intent intentExecutePushCommand = new Intent( getApplicationContext(), ExecutePushCommandIntentService.class);
intentExecutePushCommand.putExtra("compID", MenuActivity.companyID);
intentExecutePushCommand.putExtra("command", message);
intentExecutePushCommand.putExtra("pushguid", pushGuid);
startService(intentExecutePushCommand);
}else if(message.trim().equalsIgnoreCase("CLEARCACHE_ADD_PACKAGENAME_WL")){
Log.e(TAG, "received CLEARCACHE_ADD_PACKAGENAME_WL");
String pushGuid = (String)remoteMessageMap.get("pushguid");
Log.e(TAG, "pushGuid = " + pushGuid);
String packageName = (String)remoteMessageMap.get("package_name");
Intent intentExecutePushCommand = new Intent( getApplicationContext(), ExecutePushCommandIntentService.class);
intentExecutePushCommand.putExtra("compID", MenuActivity.companyID);
intentExecutePushCommand.putExtra("command", message);
intentExecutePushCommand.putExtra("pushguid", pushGuid);
intentExecutePushCommand.putExtra("package_name", packageName);
startService(intentExecutePushCommand);
}