Skip to content

Easier Push Overrides #811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Parse/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ android {
}

ext {
okhttpVersion = '3.9.1'
okhttpVersion = '3.10.0'
}

dependencies {
Expand Down
10 changes: 5 additions & 5 deletions Parse/src/main/java/com/parse/ParsePushBroadcastReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
* {@link #onPushOpen(Context, Intent)}, or {@link #onPushDismiss(Context, Intent)}.
* To make minor changes to the appearance of a notification, override
* {@link #getSmallIconId(Context, Intent)} or {@link #getLargeIcon(Context, Intent)}. To completely
* change the Notification generated, override {@link #getNotification(Context, Intent)}. To
* change the Notification generated, override {@link #getNotificationBuilder(Context, Intent)}. To
* change the NotificationChannel generated, override {@link #getNotificationChannel(Context, Intent)}. To
* change how the NotificationChannel is created, override {@link #createNotificationChannel(Context, NotificationChannel)}.
* To change the Activity launched when a user opens a Notification, override
Expand Down Expand Up @@ -212,7 +212,7 @@ protected void onPushReceive(Context context, Intent intent) {
context.sendBroadcast(broadcastIntent);
}

Notification notification = getNotification(context, intent);
Notification notification = getNotificationBuilder(context, intent).build();

if (notification != null) {
ParseNotificationManager.getInstance().showNotification(context, notification);
Expand Down Expand Up @@ -392,7 +392,7 @@ private JSONObject getPushData(Intent intent) {
}
}
/**
* Creates a {@link Notification} with reasonable defaults. If "alert" and "title" are
* Creates a {@link NotificationCompat.Builder} with reasonable defaults. If "alert" and "title" are
* both missing from data, then returns {@code null}. If the text in the notification is longer
* than 38 characters long, the style of the notification will be set to
* {@link android.app.Notification.BigTextStyle}.
Expand All @@ -409,7 +409,7 @@ private JSONObject getPushData(Intent intent) {
*
* @see ParsePushBroadcastReceiver#onPushReceive(Context, Intent)
*/
protected Notification getNotification(Context context, Intent intent) {
protected NotificationCompat.Builder getNotificationBuilder(Context context, Intent intent) {
JSONObject pushData = getPushData(intent);
if (pushData == null || (!pushData.has("alert") && !pushData.has("title"))) {
return null;
Expand Down Expand Up @@ -468,6 +468,6 @@ protected Notification getNotification(Context context, Intent intent) {
&& alert.length() > ParsePushBroadcastReceiver.SMALL_NOTIFICATION_MAX_CHARACTER_LIMIT) {
parseBuilder.setStyle(new NotificationCompat.Builder.BigTextStyle().bigText(alert));
}
return parseBuilder.build();
return parseBuilder;
}
}
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ ext {

commonLibVersion = "1.17.0-SNAPSHOT"

supportLibVersion = '27.1.0'
googleLibVersion = '12.0.1'
supportLibVersion = '27.1.1'
googleLibVersion = '15.0.0'
firebaseJobdispatcherVersion = '0.8.5'

minSdkVersion = 14
Expand Down
59 changes: 1 addition & 58 deletions fcm/README.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,5 @@
# Parse SDK Android FCM
FCM support for Parse Android apps

## Setup

### Installation

Add dependency to the application level `build.gradle` file.

```groovy
dependencies {
implementation 'com.parse:parse-android:latest.version.here'
implementation 'com.parse:parse-android-fcm:latest.version.here'
}
```
Then, follow Google's docs for [setting up an Firebase app](https://firebase.google.com/docs/android/setup). Although the steps are different for setting up FCM with Parse, it is also a good idea to read over the [Firebase FCM Setup](https://firebase.google.com/docs/cloud-messaging/android/client).

You will then need to register some things in your manifest, specifically:
```xml
<service
android:name="com.parse.fcm.ParseFirebaseInstanceIdService"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
```
where `MyFirebaseInstanceIdService` is your own custom class which extends `ParseFirebaseInstanceIdService`.

Additional, you will register:

```xml
<service
android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
```
where `MyFirebaseMessagingService` extends `ParseFirebaseMessagingService`

After these services are registered in the Manifest, you then need to register your push broadcast receiver:
```xml
<receiver
android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
```

## Custom Notifications
If you need to customize the notification that is sent out from a push, you can do so easily by extending `ParsePushBroadcastReceiver` with your own class and registering it instead in the Manifest.

## Instance ID Service
If you need to store the FCM token elsewhere outside of Parse, you can create your own implementation of the `FirebaseInstanceIdService`, just make sure you are either extending `ParseFirebaseInstanceIdService` or are calling `ParseFCM.register(getApplicationContext());` in the `onTokenRefresh` method.
FCM support for Parse Android apps. Follow the [guide](http://docs.parseplatform.org/tutorials/android-push-notifications/) for setup

## License
Copyright (c) 2015-present, Parse, LLC.
Expand Down
1 change: 0 additions & 1 deletion gcm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Add dependency to the application level `build.gradle` file.

```groovy
dependencies {
implementation 'com.parse:parse-android:latest.version.here'
implementation 'com.parse:parse-android-gcm:latest.version.here'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
```
Expand Down