Skip to content

Commit 8473084

Browse files
committed
use default prefs
1 parent a0726ba commit 8473084

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ Supported notification fields:
193193
* "sound" => "string" (e.g. "notification.mp3" will play /platform/android/res/raw/notification.mp3)
194194

195195
### Android: Note about custom sounds
196-
To use a custom sound > Android O you need to create a second channel. The default channel will always use the default notification sound on the device!
196+
To use a custom sound > Android O you need to create a second channel. The default channel will always use the default notification sound on the device!
197197

198198
### Android: Note for switching between v<=v2.0.2 and >=v2.0.3 if you use notification channels with custom sounds
199199
With versions prior to 2.0.3 of this module, FirebaseCloudMessaging.createNotificationChannel would create the notification sound uri using the resource id of the sound file in the `res/raw` directory. However, as described in this [android issue](https://issuetracker.google.com/issues/131303134), those resource ids can change to reference different files (or no file) between app versions, and that happens the notification channel may play a different or no sound than originally intended.
@@ -261,7 +261,7 @@ so receive the `gcm.message_id` key from the notification payload instead.
261261
`apnsToken` (String, set) (iOS only)
262262

263263
`lastData` (Object) (Android only)
264-
The propery `lastData` will contain the data part when you send a notification push message (so both nodes are visible inside the push payload).
264+
The propery `lastData` will contain the data part when you send a notification push message (so both nodes are visible inside the push payload). Read before calling `registerForPushNotifications()`.
265265

266266
#### Events
267267

@@ -331,10 +331,16 @@ if (OS_ANDROID) {
331331
showBadge: true
332332
});
333333
// if you use a custom id you have to set the same to the `channelId` in you php send script!
334-
334+
335335
fcm.notificationChannel = channel;
336336
}
337337

338+
339+
if (OS_ANDROID){
340+
// display last data:
341+
Ti.API.info("Last data: " + fcm.lastData);
342+
}
343+
338344
// Register the device with the FCM service.
339345
fcm.registerForPushNotifications();
340346

@@ -347,11 +353,6 @@ if (fcm.fcmToken) {
347353

348354
// Subscribe to a topic.
349355
fcm.subscribeToTopic('testTopic');
350-
351-
if (OS_ANDROID){
352-
// display last data:
353-
Ti.API.info("Last data: " + fcm.lastData);
354-
}
355356
```
356357

357358
## Send FCM messages with PHP

android/src/firebase/cloudmessaging/CloudMessagingModule.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ private KrollDict getLastData()
8585
}
8686

8787
if (data.get("message") == null) {
88-
SharedPreferences preferences = Utils.getApplicationContext().getSharedPreferences(
89-
"fcm_data", Utils.getApplicationContext().MODE_PRIVATE);
88+
SharedPreferences preferences =
89+
PreferenceManager.getDefaultSharedPreferences(Utils.getApplicationContext());
9090
String prefMessage = preferences.getString("titanium.firebase.cloudmessaging.message", null);
9191
if (prefMessage != null) {
9292
data.put("message", new KrollDict(new JSONObject(prefMessage)));
@@ -345,8 +345,7 @@ public void parseBootIntent()
345345
Log.e(LCAT, "parseBootIntent" + ex);
346346
}
347347

348-
SharedPreferences preferences = Utils.getApplicationContext().getSharedPreferences(
349-
"fcm_data", Utils.getApplicationContext().MODE_PRIVATE);
348+
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(Utils.getApplicationContext());
350349
preferences.edit().clear().commit();
351350
}
352351
}

android/src/firebase/cloudmessaging/TiFirebaseMessagingService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import android.media.RingtoneManager;
1212
import android.net.Uri;
1313
import android.os.Build;
14+
import android.preference.PreferenceManager;
1415
import android.support.v4.app.NotificationCompat;
1516
import android.util.Log;
1617
import com.google.firebase.messaging.FirebaseMessagingService;
@@ -151,7 +152,7 @@ private Boolean showNotification(RemoteMessage remoteMessage)
151152
builder_defaults |= Notification.DEFAULT_SOUND;
152153
}
153154

154-
SharedPreferences preferences = getSharedPreferences("fcm_data", getApplicationContext().MODE_PRIVATE);
155+
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
155156
SharedPreferences.Editor editor = preferences.edit();
156157
editor.putString("titanium.firebase.cloudmessaging.message", jsonData.toString());
157158
editor.commit();

0 commit comments

Comments
 (0)