Browse Source

Added Android specific property `smallImage`

Sebastián Katzer 12 years ago
parent
commit
b03bdf0801
4 changed files with 28 additions and 5 deletions
  1. 4 3
      README.md
  2. 17 1
      src/android/Options.java
  3. 6 1
      src/android/Receiver.java
  4. 1 0
      www/local-notification.js

+ 4 - 3
README.md

@@ -58,6 +58,7 @@ More informations can be found [here](https://build.phonegap.com/plugins/356).
 - [enhancement:] The background callback on Android is called, even the app is not running when the notification is tapped.
 - [enhancement:] The background callback on Android is called, even the app is not running when the notification is tapped.
 - [enhancement:] Notifications are repeated more precisely.
 - [enhancement:] Notifications are repeated more precisely.
 - [feature:] Added `json` property to pass custom data through the notification.
 - [feature:] Added `json` property to pass custom data through the notification.
+- [enhancement:] Added Android specific property `smallImage`.
 
 
 #### Version 0.6.3 (12.12.2013)
 #### Version 0.6.3 (12.12.2013)
 - [bugfix:] Black screen on Android.
 - [bugfix:] Black screen on Android.
@@ -186,8 +187,8 @@ function foreground (id, json) {
 
 
 
 
 ## Platform specifics
 ## Platform specifics
-### Notification icon on Android
-By default all notifications will display the app icon. But an specific icon can be defined through the `icon` property.
+### Small and large icons on Android
+By default all notifications will display the app icon. But an specific icon can be defined through the `icon` and `smallIcon` properties.
 ```javascript
 ```javascript
 /**
 /**
  * Displays the <package.name>.R.drawable.ic_launcher icon
  * Displays the <package.name>.R.drawable.ic_launcher icon
@@ -197,7 +198,7 @@ window.plugin.notification.local.add({ icon: 'ic_launcher' });
 /**
 /**
  * Displays the android.R.drawable.ic_dialog_email icon
  * Displays the android.R.drawable.ic_dialog_email icon
  */
  */
-window.plugin.notification.local.add({ icon: 'ic_dialog_email' });
+window.plugin.notification.local.add({ smallIcon: 'ic_dialog_email' });
 ```
 ```
 
 
 ### Notification sound on Android
 ### Notification sound on Android

+ 17 - 1
src/android/Options.java

@@ -147,7 +147,7 @@ public class Options {
     }
     }
 
 
     /**
     /**
-     * Gibt den Pfad zum Icon der Notification an.
+     * Gibt den ID Code des Bildes an.
      */
      */
     public int getIcon () {
     public int getIcon () {
         int icon        = 0;
         int icon        = 0;
@@ -166,6 +166,22 @@ public class Options {
         return options.optInt("icon", icon);
         return options.optInt("icon", icon);
     }
     }
 
 
+    /**
+     * Gibt den ID Code des kleinen Bildes an.
+     */
+    public int getSmallIcon () {
+        int resId       = 0;
+        String iconName = options.optString("smallIcon", "");
+
+        resId = getIconValue(packageName, iconName);
+
+        if (resId == 0) {
+            resId = getIconValue("android", iconName);
+        }
+
+        return options.optInt("smallIcon", resId);
+    }
+
     /**
     /**
      * Gibt den Pfad zur Callback-Funktion der Notification an.
      * Gibt den Pfad zur Callback-Funktion der Notification an.
      */
      */

+ 6 - 1
src/android/Receiver.java

@@ -36,6 +36,8 @@ import android.app.PendingIntent;
 import android.content.BroadcastReceiver;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Context;
 import android.content.Intent;
 import android.content.Intent;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
 import android.os.Build;
 import android.os.Build;
 import android.os.Bundle;
 import android.os.Bundle;
 import android.text.TextUtils;
 import android.text.TextUtils;
@@ -118,12 +120,15 @@ public class Receiver extends BroadcastReceiver {
      * Erstellt die Notification.
      * Erstellt die Notification.
      */
      */
     private Builder buildNotification () {
     private Builder buildNotification () {
+        Bitmap icon = BitmapFactory.decodeResource(context.getResources(), options.getIcon());
+
         Builder notification = new Notification.Builder(context)
         Builder notification = new Notification.Builder(context)
         .setContentTitle(options.getTitle())
         .setContentTitle(options.getTitle())
         .setContentText(options.getMessage())
         .setContentText(options.getMessage())
         .setNumber(options.getBadge())
         .setNumber(options.getBadge())
         .setTicker(options.getTitle())
         .setTicker(options.getTitle())
-        .setSmallIcon(options.getIcon())
+        .setSmallIcon(options.getSmallIcon())
+        .setLargeIcon(icon)
         .setSound(options.getSound())
         .setSound(options.getSound())
         .setAutoCancel(options.getAutoCancel());
         .setAutoCancel(options.getAutoCancel());
 
 

+ 1 - 0
www/local-notification.js

@@ -47,6 +47,7 @@ LocalNotification.prototype = {
         switch (device.platform) {
         switch (device.platform) {
             case 'Android':
             case 'Android':
                 defaults.icon = 'icon';
                 defaults.icon = 'icon';
+                defaults.smallIcon = null;
                 defaults.sound = 'TYPE_NOTIFICATION'; break;
                 defaults.sound = 'TYPE_NOTIFICATION'; break;
             case 'iOS':
             case 'iOS':
                 defaults.sound = ''; break;
                 defaults.sound = ''; break;