Commit 198d841e authored by Simon MacDonald's avatar Simon MacDonald
Browse files

Issue #61: Android: add property to vibrate phone on received notification

parent 85191ee7
Loading
Loading
Loading
Loading
+2 −0
Changes for README.md: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -57,6 +57,8 @@ Parameter | Description
`options.android.senderID` | `String` Maps to the project number in the Google Developer Console.
`options.android.icon` | `String` Optional. The name of a drawable resource to use as the small-icon.
`options.android.iconColor` | `String` Optional. Sets the background color of the small icon. [Supported Formats](http://developer.android.com/reference/android/graphics/Color.html#parseColor(java.lang.String))
`options.android.sound` | `Boolean` Optional. If `true` it plays the sound specified in the push data or the default system sound. Default is `true`.
`options.android.vibrate` | `Boolean` Optional. If `true` the device vibrates on receipt of notification. Default is `true`.
`options.ios` | `JSON Object` iOS specific initialization options.
`options.windows` | `JSON Object` Windows specific initialization options.

+16 −9
Changes for src/android/com/adobe/phonegap/push/GCMIntentService.java: 16 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -97,17 +97,8 @@ public class GCMIntentService extends GCMBaseIntentService {
        int requestCode = new Random().nextInt();
        PendingIntent contentIntent = PendingIntent.getActivity(this, requestCode, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        
        int defaults = Notification.DEFAULT_ALL;

        if (extras.getString("defaults") != null) {
            try {
                defaults = Integer.parseInt(extras.getString("defaults"));
            } catch (NumberFormatException e) {}
        }
        
        NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(context)
                //.setDefaults(defaults)
                .setWhen(System.currentTimeMillis())
                .setContentTitle(extras.getString("title"))
                .setTicker(extras.getString("title"))
@@ -117,8 +108,19 @@ public class GCMIntentService extends GCMBaseIntentService {
        SharedPreferences prefs = context.getSharedPreferences("com.adobe.phonegap.push", Context.MODE_PRIVATE);
        String localIcon = prefs.getString("icon", null);
        String localIconColor = prefs.getString("iconColor", null);
        boolean soundOption = prefs.getBoolean("sound", true);
        boolean vibrateOption = prefs.getBoolean("vibrate", true);
        Log.d(LOG_TAG, "stored icon=" + localIcon);
        Log.d(LOG_TAG, "stored iconColor=" + localIconColor);
        Log.d(LOG_TAG, "stored sound=" + soundOption);
        Log.d(LOG_TAG, "stored vibrate=" + vibrateOption);

        /*
         * Notification Vibration
         */
        if (vibrateOption) {
            mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
        }
        
        /*
         * Notification Icon Color
@@ -201,6 +203,10 @@ public class GCMIntentService extends GCMBaseIntentService {
            }
        }

        /*
         * Notification Sound
         */
        if (soundOption) {
            String soundname = extras.getString("soundname");
            if (soundname == null) {
                soundname = extras.getString("sound");
@@ -213,6 +219,7 @@ public class GCMIntentService extends GCMBaseIntentService {
            } else {
                mBuilder.setSound(android.provider.Settings.System.DEFAULT_NOTIFICATION_URI);
            }
        }
        
        String message = extras.getString("message");
        if (message != null) {
+2 −0
Changes for src/android/com/adobe/phonegap/push/PushPlugin.java: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -86,6 +86,8 @@ public class PushPlugin extends CordovaPlugin {
                } catch (JSONException e) {
                    Log.d(LOG_TAG, "no iconColor option");
                }
                editor.putBoolean("sound", jo.optBoolean("sound", true));
                editor.putBoolean("vibrate", jo.optBoolean("vibrate", true));
                editor.commit();
            }