Es wird bei einer Benachrichtigung geprüft, ob der Link zum Avatar ein Leerstring oder null ist und dementsprechend eine URL malformed Exception vermieden.

This commit is contained in:
Lyndon
2018-10-01 16:06:31 +02:00
parent a452ed99cb
commit 88b05af91a
3 changed files with 12 additions and 29 deletions

View File

@@ -33,8 +33,8 @@ android {
applicationId "de.beyondsoft.ownchat"
minSdkVersion 19
targetSdkVersion 27
versionCode 23
versionName "1.23"
versionCode 24
versionName "1.24"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}

View File

@@ -46,7 +46,6 @@ import android.support.v4.app.NotificationCompat;
import android.support.v4.app.RemoteInput;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.util.Log;
import java.io.IOException;
import java.net.HttpURLConnection;
@@ -76,23 +75,10 @@ public class HandleMessagesService extends FirebaseMessagingService {
@Named(AppPrefsConstants.USER_ID)
LongPreference mUserIdReference;
@Override
public void onDeletedMessages() {
Utils.makeFirebaseLogEntry("onDeletedMessages. Possible reasons:\n" +
" Too many messages stored on the FCM server. This can occur when an app's servers send a bunch of non-collapsible messages to FCM servers while the device is offline.\n" +
" The device hasn't connected in a long time and the app server has recently (within the last 4 weeks) sent a message to the app on that device.");
super.onDeletedMessages();
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.i("FIREBASE_RECEIVER", "onMessageReceived called");
Map<String, String> dataMap = remoteMessage.getData();
Utils.makeFirebaseLogEntry("onMessageReceived: " + dataMap.get(Constants.MESSAGE_ID));
InjectionHelper.getMessagingComponent(this).inject(HandleMessagesService.this);
customizeNotification(dataMap);
@@ -101,8 +87,6 @@ public class HandleMessagesService extends FirebaseMessagingService {
private void customizeNotification(Map<String, String> dataMap) {
String messageId = dataMap.get(Constants.MESSAGE_ID);
Utils.makeFirebaseLogEntry("customizeNotification for message " + messageId);
mChatService.getMessage(messageId)
.compose(RxUtils.provideDefaultTransformer())
.flatMap(new ErrorHandlingResponseConverter<>())
@@ -112,9 +96,6 @@ public class HandleMessagesService extends FirebaseMessagingService {
@SuppressLint("StaticFieldLeak")
private void getMessageSuccess(Message message) {
Log.i("FIREBASE_RECEIVER", "Message received");
Utils.makeFirebaseLogEntry("getMessageSuccess called for message " + message.id);
Bundle bundle = new Bundle();
bundle.putString(Constants.MESSAGE_ID, message.id);
@@ -141,7 +122,7 @@ public class HandleMessagesService extends FirebaseMessagingService {
public void onReceive(Context context, Intent intent) {
Bundle results = getResultExtras(true);
if (!results.getBoolean(CHAT_IS_ALREADY_OPEN, false)) {
if(!results.getBoolean(CHAT_IS_ALREADY_OPEN, false)) {
int groupId = (int) bundle.getLong(Constants.GROUP_ID);
int numberOfUsers = message.numberOfGroupUsers;
intent = MainActivity.createIntent(context, bundle, numberOfUsers, groupId);
@@ -149,7 +130,7 @@ public class HandleMessagesService extends FirebaseMessagingService {
PendingIntent pendingIntent = PendingIntent.getActivity(context, groupId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Bitmap bitmapToDisplay = bitmap;
if (bitmapToDisplay == null) {
if(bitmapToDisplay == null) {
bitmapToDisplay = BitmapFactory.decodeResource(context.getResources(), R.drawable.avatar);
}
@@ -227,15 +208,13 @@ public class HandleMessagesService extends FirebaseMessagingService {
}
}, null, Activity.RESULT_OK, null, null);
}
}.execute(new URL(message.senderAvatar));
}.execute((Utils.isNullOrEmpty(message.senderAvatar) ? null : new URL(message.senderAvatar)));
} catch(MalformedURLException e) {
Utils.makeFirebaseLogEntry("Exception in getMessageSuccess (" + message.id + ")" + e.toString());
e.printStackTrace();
}
}
private void getMessageError(Throwable throwable) {
Utils.makeFirebaseLogEntry("getMessageError " + throwable.getMessage());
throwable.printStackTrace();
}
@@ -275,7 +254,7 @@ public class HandleMessagesService extends FirebaseMessagingService {
}
private String setNotificationTitle(Message message, int numberOfUsers) {
if (numberOfUsers > 2) {
if(numberOfUsers > 2) {
return message.senderName + " @ " + message.groupName;
} else {
return message.senderName;
@@ -283,7 +262,7 @@ public class HandleMessagesService extends FirebaseMessagingService {
}
private NotificationCompat.Action createAction(Context context, int noOfUsers, int groupId, Bundle bundle) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
return null;
}
@@ -353,7 +332,7 @@ public class HandleMessagesService extends FirebaseMessagingService {
private static class DownloadAvatarTask extends AsyncTask<URL, Void, Bitmap> {
@Override
protected Bitmap doInBackground(URL... urls) {
if(urls == null || urls.length == 0) {
if(urls == null || urls.length == 0 || urls[0] == null) {
return null;
}

View File

@@ -231,4 +231,8 @@ public class Utils {
return calendar1.before(calendar2);
}
public static boolean isNullOrEmpty(String string) {
return string == null || string.length() == 0;
}
}