Skip to content

Commit d693fbe

Browse files
authored
Merge pull request zetavg#64 from sqli/bigStyleByUrl
Notification with big style image. Getting Bitmat from URL
2 parents 3345856 + e7bcd1e commit d693fbe

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ node_modules
22
build/
33
npm-debug.log
44
system-notification.iml
5+
react-native-system-notification.iml
56
.DS_Store

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ Set the text to be shown when the user expand the notification.
280280
**bigStyleImageBase64 (`string`)**
281281
Set the image in base64 to be shown when the user expand the notification. if bigText is not null, it have priority over bigStyleImageBase64.
282282

283+
**bigStyleUrlImgage (`string`)**
284+
Set URL of a image. Geting it by open a stream connection and it be shown when the user expand the notification.. if bigText is not null, it have priority over bigStyleUrlImgage
285+
283286
**subText (`string`)**
284287
Set the third line of text in the platform notification template. Note that it cannot be used with `progress`.
285288

android/src/main/java/io/neson/react/notification/Notification.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import android.net.Uri;
1515

1616
import java.lang.System;
17+
import java.net.URL;
1718
import java.util.HashMap;
1819
import java.util.Map;
1920

@@ -23,6 +24,7 @@
2324
import io.neson.react.notification.NotificationEventReceiver;
2425
import io.neson.react.notification.NotificationPublisher;
2526

27+
import android.util.Base64;
2628
import android.support.v7.app.NotificationCompat;
2729
import android.text.Html;
2830
import android.util.Base64;
@@ -126,6 +128,7 @@ public android.app.Notification build() {
126128
.setAutoCancel(attributes.autoClear)
127129
.setContentIntent(getContentIntent());
128130

131+
129132
if (attributes.priority != null) {
130133
notificationBuilder.setPriority(attributes.priority);
131134
}
@@ -183,6 +186,26 @@ public android.app.Notification build() {
183186
.setStyle(new android.support.v7.app.NotificationCompat.BigTextStyle()
184187
.bigText(attributes.bigText));
185188
}
189+
else if (attributes.bigStyleUrlImgage != null && attributes.bigStyleUrlImgage != "") {
190+
191+
Bitmap bigPicture = null;
192+
193+
try {
194+
195+
Log.i("ReactSystemNotification", "start to get image from URL : " + attributes.bigStyleUrlImgage);
196+
URL url = new URL(attributes.bigStyleUrlImgage);
197+
bigPicture = BitmapFactory.decodeStream(url.openStream());
198+
Log.i("ReactSystemNotification", "finishing to get image from URL");
199+
200+
} catch (Exception e) {
201+
Log.e("ReactSystemNotification", "Error when getting image from URL" + e.getStackTrace());
202+
}
203+
204+
if (bigPicture != null) {
205+
notificationBuilder
206+
.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(bigPicture));
207+
}
208+
}
186209
else if (attributes.bigStyleImageBase64 != null) {
187210

188211
Bitmap bigPicture = null;

android/src/main/java/io/neson/react/notification/NotificationAttributes.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class NotificationAttributes {
4848
public String tickerText;
4949
public Long when;
5050
public String bigText;
51+
public String bigStyleUrlImgage;
5152
public String bigStyleImageBase64;
5253
public String subText;
5354
public Integer progress;
@@ -131,6 +132,7 @@ public void loadFromReadableMap(ReadableMap readableMap) {
131132
if (readableMap.hasKey("tickerText")) tickerText = readableMap.getString("tickerText");
132133
if (readableMap.hasKey("when")) when = Long.parseLong(readableMap.getString("when"));
133134
if (readableMap.hasKey("bigText")) bigText = readableMap.getString("bigText");
135+
if (readableMap.hasKey("bigStyleUrlImgage")) bigStyleUrlImgage = readableMap.getString("bigStyleUrlImgage");
134136
if (readableMap.hasKey("bigStyleImageBase64")) bigStyleImageBase64 = readableMap.getString("bigStyleImageBase64");
135137
if (readableMap.hasKey("subText")) subText = readableMap.getString("subText");
136138
if (readableMap.hasKey("progress")) progress = readableMap.getInt("progress");
@@ -196,6 +198,7 @@ public ReadableMap asReadableMap() {
196198
if (when != null) writableMap.putString("when", Long.toString(when));
197199
if (bigText != null) writableMap.putString("bigText", bigText);
198200
if (bigStyleImageBase64 != null) writableMap.putString("bigStyleImageBase64", bigStyleImageBase64);
201+
if (bigStyleUrlImgage != null) writableMap.putString("bigStyleImageBase64", bigStyleUrlImgage);
199202
if (subText != null) writableMap.putString("subText", subText);
200203
if (progress != null) writableMap.putInt("progress", progress);
201204
if (color != null) writableMap.putString("color", color);

0 commit comments

Comments
 (0)