7
7
import android .content .Context ;
8
8
import android .content .Intent ;
9
9
import android .graphics .Bitmap ;
10
+ import android .graphics .drawable .Drawable ;
10
11
import android .media .Ringtone ;
11
12
import android .media .RingtoneManager ;
12
13
import android .net .Uri ;
@@ -92,6 +93,12 @@ protected void onPostExecute(String aVoid) {
92
93
public void onResourceReady (@ NonNull Bitmap resource , @ Nullable Transition <? super Bitmap > transition ) {
93
94
sendNotification (context , activity , model , resource , icon );
94
95
}
96
+
97
+ @ Override
98
+ public void onLoadFailed (@ Nullable Drawable errorDrawable ) {
99
+ super .onLoadFailed (errorDrawable );
100
+ sendNotification (context , activity , model , null , icon );
101
+ }
95
102
});
96
103
}
97
104
}.execute ();
@@ -100,51 +107,58 @@ public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? sup
100
107
}
101
108
102
109
public static void sendNotification (Context context , Class activity , NotificationModel data , Bitmap myBitmap , int icon ) {
103
-
104
- Intent intent = new Intent (context , NotificationOpenActivity .class );
105
- intent .addFlags (Intent .FLAG_ACTIVITY_CLEAR_TOP );
106
- intent .putExtra (Constant .NOTIFICATION , true );
107
- intent .putExtra (Constant .ACTIVITY , activity );
108
- intent .putExtra (Constant .MODEL , data );
109
- PendingIntent pendingIntent = PendingIntent .getActivity (context , 0 /* Request code */ , intent ,
110
- PendingIntent .FLAG_ONE_SHOT );
111
-
112
- OneFeedSdk .getInstance ().getJobManager ().addJobInBackground (
113
- new PostUserTrackingJob (Constant .NOTIFICATION_RECEIVED , Constant .NOTIFICATION , data .getStoryId (), data .getNoId ()));
114
-
115
- String channelId = "DEFAULT" ;
116
- NotificationCompat .Builder notificationBuilder =
117
- new NotificationCompat .Builder (context , channelId )
118
- .setSmallIcon (icon )
119
- .setContentTitle (data .getTitle ())
120
- .setContentText (data .getBody ())
121
- .setLargeIcon (myBitmap )
122
- .setStyle (new NotificationCompat .BigPictureStyle ()
123
- .bigPicture (myBitmap ))
124
- .setAutoCancel (true )
125
- .setDefaults (Notification .DEFAULT_SOUND )
126
- .setContentIntent (pendingIntent );
127
-
128
- // Since android Oreo notification channel is needed.
129
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
130
- NotificationChannel channel = new NotificationChannel (channelId ,
131
- "Channel human readable title" ,
132
- NotificationManager .IMPORTANCE_DEFAULT );
133
- notificationManager .createNotificationChannel (channel );
134
- }
135
110
try {
136
- Uri notification = RingtoneManager .getDefaultUri (RingtoneManager .TYPE_NOTIFICATION );
137
- Ringtone r = RingtoneManager .getRingtone (context , notification );
138
- r .play ();
139
- } catch (Exception e ) {
140
- e .printStackTrace ();
141
- }
142
- int noId = 0 ;
143
- try {
144
- noId = Integer .parseInt (data .getNoId ());
111
+ Intent intent = new Intent (context , NotificationOpenActivity .class );
112
+ intent .addFlags (Intent .FLAG_ACTIVITY_CLEAR_TOP );
113
+ intent .putExtra (Constant .NOTIFICATION , true );
114
+ intent .putExtra (Constant .ACTIVITY , activity );
115
+ intent .putExtra (Constant .MODEL , data );
116
+ PendingIntent pendingIntent = PendingIntent .getActivity (context , 0 /* Request code */ , intent ,
117
+ PendingIntent .FLAG_ONE_SHOT );
118
+
119
+ OneFeedSdk .getInstance ().getJobManager ().addJobInBackground (
120
+ new PostUserTrackingJob (Constant .NOTIFICATION_RECEIVED , Constant .NOTIFICATION , data .getStoryId (), data .getNoId ()));
121
+
122
+ String channelId = "DEFAULT" ;
123
+ NotificationCompat .Builder notificationBuilder =
124
+ new NotificationCompat .Builder (context , channelId )
125
+ .setSmallIcon (icon )
126
+ .setContentTitle (data .getTitle ())
127
+ .setContentText (data .getBody ())
128
+ .setAutoCancel (true )
129
+ .setDefaults (Notification .DEFAULT_SOUND )
130
+ .setContentIntent (pendingIntent );
131
+
132
+ if (myBitmap != null ) {
133
+ notificationBuilder .setLargeIcon (myBitmap );
134
+ notificationBuilder .setStyle (new NotificationCompat .BigPictureStyle ()
135
+ .bigPicture (myBitmap ));
136
+ }
137
+
138
+
139
+ // Since android Oreo notification channel is needed.
140
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
141
+ NotificationChannel channel = new NotificationChannel (channelId ,
142
+ "Channel human readable title" ,
143
+ NotificationManager .IMPORTANCE_DEFAULT );
144
+ notificationManager .createNotificationChannel (channel );
145
+ }
146
+ try {
147
+ Uri notification = RingtoneManager .getDefaultUri (RingtoneManager .TYPE_NOTIFICATION );
148
+ Ringtone r = RingtoneManager .getRingtone (context , notification );
149
+ r .play ();
150
+ } catch (Exception e ) {
151
+ e .printStackTrace ();
152
+ }
153
+ int noId = 0 ;
154
+ try {
155
+ noId = Integer .parseInt (data .getNoId ());
156
+ } catch (Exception e ) {
157
+ noId = (int ) SystemClock .currentThreadTimeMillis ();
158
+ }
159
+ notificationManager .notify (noId /* ID of notification */ , notificationBuilder .build ());
145
160
}catch (Exception e ){
146
- noId = ( int ) SystemClock . currentThreadTimeMillis ();
161
+
147
162
}
148
- notificationManager .notify (noId /* ID of notification */ , notificationBuilder .build ());
149
163
}
150
164
}
0 commit comments