What library do I use to send notifications?

Asked

Viewed 82 times

4

Hello, I’m developing an app where patients have left it in the background or even open, and when the patient’s turn arrives, the office sends a notification saying it’s his turn. Do you have a specific library for that? I am very beginner in android.

  • This is it: https://developers.google.com/cloud-messaging/ and this http://stackoverflow.com/questions/19866623/getting-an-api-key-to-use-with-google-cloud-messaging

  • One option is Firebase, you can check this link https://firebase.google.com/docs/cloud-messaging/? hl=en

1 answer

3


As you are beginner I advise you to give a look on the firebase, as other colleagues have indicated. I have made an app recently and can tell you that you will need to create an account on firebase console. In this access you will find the information how to proceed with the configuration file to be inserted in your app.

In your app’s Gradle, you should add the sdk:

in the archive build.Gradle root folder, configure similar to:

    buildscript {
    // ...
    dependencies {
    // ...
    classpath 'com.google.gms:google-services:3.0.0'
        }
    }

already in the archive /build.Gradle sub-folder /app

apply plugin: 'com.android.application'

    android {
      // ...
    }

    dependencies {
      // ...
      compile 'com.google.firebase:firebase-core:9.6.1'
    }

    apply plugin: 'com.google.gms.google-services'

With everything set up, your app should connect to firebase and search for updates of the logs, the code looks like:

    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference myRef = database.getReference("message");

    myRef.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            String value = dataSnapshot.getValue(String.class);
            Log.d(TAG, "Value is: " + value);
        }

        @Override
        public void onCancelled(DatabaseError error) {
            // Failed to read value
            Log.w(TAG, "Failed to read value.", error.toException());
        }
    });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.