Popularity
1.7
Stable
Activity
0.0
Stable
48
2
6

Programming language: Kotlin
License: MIT License
Tags: Messaging     Animations     Android-library     FCM    
Latest version: v1.2.2

Pushmanager alternatives and similar packages

Based on the "Animations" category.
Alternatively, view Pushmanager alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of Pushmanager or a related project?

Add another 'Animations' Package

README

Pushmanager

minSDK 16 targetSDK 28

Pushmanager is a small wrapper for FCM (Firebase Cloud Messageing) and your app needs just a few methods to interact with it.

Installation

Add google-services as dependency to your project build.gradle

buildscript {
    ...
    dependencies {
        ...
        classpath "com.google.gms:google-services:4.2.0"
        ...
    }
}

and add jitpackto your repositories

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
    ...
}

Add this dependency to your app build.gradle and apply the plugin at the bottom:

implementation 'com.github.grumpyshoe:android-module-pushmanager:1.2.2'
...
apply plugin: 'com.google.gms.google-services'

Usage

Get instance of PushManager:

val pushmanager: PushManager = PushManagerImpl  

Put your google-services.json to the app-root folder.

Create a class extending PushmanagerMessagingService and implement handleNotificationPayload.

class MyService : PushmanagerMessagingService() {

    override fun handleNotificationPayload(context:Context, remoteMessageData: RemoteMessageData): NotificationData? {

      Log.d("PushManager", "handlePayload - ${remoteMessageData.title} - ${remoteMessageData.body}" )

      // create pending intent (example)
      val notificationIntent = Intent(context, SomeActivity::class.java)
      notificationIntent.putExtra("info", "Some information for pending intent")
      notificationIntent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
      val contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT)

      // create notification (example)
      return NotificationData(
            context = context,
            title = remoteMessageData.title ?: "Default Title",
            message = remoteMessageData.body ?: "Default Message",
            channelId = "channel_global_notifications",             // needed SDK >= Android O
            autoCancel = true,
            pendingIntent = contentIntent)
    }
}

Add your implementation to you Manifest.xml

<application ... >

       <service
           android:name=".MyService">
           <intent-filter>
               <action android:name="com.google.firebase.MESSAGING_EVENT"/>
           </intent-filter>
       </service>
       ...

</application>

Register to FCM

Call the method register in your onCreate to register to FCM.

pushmanager.register(
      context = this,
      onTokenReceived = { token ->
          Log.d("PushManager", "token received: $token")
      },
      onFailure = { exception ->
          Log.d("PushManager", " error during registration: ${exception?.message}")
      })

Unregister from FCM

To unregister from FCM you need to register first. By using the token you received, you are able to unregister.

pushmanager.unregister(context, token)

Topics

Subscribe to Topic

To subscribe to a topic just call subscriptToTopic:

pushmanager.subscriptToTopic(
      topic = "wurst",
      onSuccess = {
          Log.d("PushManager", "successfully subscribed")
      },
      onFailure = { exception ->
          Log.d("PushManager", " error while subscribing: ${exception?.message}")
      })

Unsubscribe from Topic

To unsubscribe from a topic call unsubscriptFromTopic:

pushmanager.unsubscriptFromTopic(
      topic = "wurst",
      onSuccess = {
          Log.d("PushManager", "successfully unsubscribed")
      },
      onFailure = { exception ->
          Log.d("PushManager", "error while unsubscribing: ${exception?.message}")
      })

Dependencies

Package Version
com.google.firebase:firebase-core 17.2.0
com.google.firebase:firebase-iid 20.0.0
com.google.firebase:firebase-messaging 20.0.0

Sample App

To run the sample App, just replace the application_id at the project build.gradle with someone according to your firebase project and add your google-services.json to to app root folder.

Troubleshooting

See Troubleshooting at github wiki.

Need Help or something missing?

Please submit an issue on GitHub.

License

This project is licensed under the terms of the MIT license. See the [LICENSE](LICENSE) file.

Other information

Changelog

1.1.0

  • Change PendingIntent handling and move it's logic to NotificationData.

1.2.0

  • Change structure of how to implement payload handling

1.2.1

  • Make return value for handleNotificationPayload nullable. If this method returns null no notification will be generated.

1.2.2

  • Bump dependencies to latest version.

Build Environment

Android Studio 3.5
Build #AI-191.8026.42.35.5791312, built on August 9, 2019
JRE: 1.8.0_202-release-1483-b49-5587405 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.14.4


*Note that all licence references and agreements mentioned in the Pushmanager README section above are relevant to that project's source code only.