FireBots

A wrapper library for Firebase for Android.

License

License

Categories

Categories

MOA Business Logic Libraries Machine Learning
GroupId

GroupId

dev.moataz
ArtifactId

ArtifactId

firebots
Last Version

Last Version

0.0.5
Release Date

Release Date

Type

Type

aar
Description

Description

FireBots
A wrapper library for Firebase for Android.
Project URL

Project URL

https://github.com/mtzhisham/FireBots-Android
Source Code Management

Source Code Management

https://github.com/mtzhisham/FireBots-Android.git

Download firebots

How to add to project

<!-- https://jarcasting.com/artifacts/dev.moataz/firebots/ -->
<dependency>
    <groupId>dev.moataz</groupId>
    <artifactId>firebots</artifactId>
    <version>0.0.5</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/dev.moataz/firebots/
implementation 'dev.moataz:firebots:0.0.5'
// https://jarcasting.com/artifacts/dev.moataz/firebots/
implementation ("dev.moataz:firebots:0.0.5")
'dev.moataz:firebots:aar:0.0.5'
<dependency org="dev.moataz" name="firebots" rev="0.0.5">
  <artifact name="firebots" type="aar" />
</dependency>
@Grapes(
@Grab(group='dev.moataz', module='firebots', version='0.0.5')
)
libraryDependencies += "dev.moataz" % "firebots" % "0.0.5"
[dev.moataz/firebots "0.0.5"]

Dependencies

compile (2)

Group / Artifact Type Version
androidx.appcompat » appcompat jar 1.1.0
com.google.firebase » firebase-messaging jar 17.1.0

Project Modules

There are no modules declared in this project.

FireBots-Android

FireBots is a wrapper library for Firebase for Android.

Installation

  1. In build.gradle in project module add either jcenter() or mavenCentral()

    allprojects {
    	repositories {
    		...
    		jcenter() //or mavenCentral()
    		....
    	}
    }
  2. In build.gradle app module app module:

    dependencies {
    ...
    
    implementation 'dev.moataz:firebots:0.0.8'
    ...
    
    }
  3. This Library uses AndroidX adding this lines in gradle.properties is recommended:

      android.useAndroidX=true
      android.enableJetifier=true
  4. place your google-services.json in your project root directory

Usage

MyApplication.java

public class MyApplication  extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        //initialize the library
        FireBots.init(this, new FirebaseTokenAvailable() {
            @Override
            public void onFirebaseTokenAvilable(String token) {
                Log.d("MyApplication", "onFirebaseTokenAvilable: " + token);

            }
            @Override
            public void onFirebaseTokenUpdated(String token) {
                Log.d("MyApplication", "onFirebaseTokenUpdated: " + token);

            }
        }).setCanHandleNotifications(true);
    }
}

MainActivity.class

public class MainActivity extends AppCompatActivity implements FireBotsMessagingInterface
        , FireBotsNotificationClickListenerInterface {

    public final static String TAG = MainActivity.class.getCanonicalName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //register message listener
        FireBots.getInstance().setMessagingInterface(this);
        //register notification click listener
        FireBots.getInstance().setNotificationClickListener(this);

    }

    /**
     * Called when message received
     * @param message a (key,value) map object containing notification message data
     */
    @Override
    public void onMessageReceived(FireBotsDataObject message) {
        Map<String, String> data = message.getAll();
        for (String name : data.keySet()){
            Log.d(TAG, name + " : " + data.get(name));
        }
        //send notification manually through library helper method, library won't handel displaying notification if app in
        // foreground/not killed
        FireBotsNotificationManager.createNotification(message.get("body"),
                MainActivity.this, message.get("click_action"));
    }

    /**
     *
     * @param clickActionDestination if the notification body contains a "click_action"  you can
     *  catch it here and app is not killed/background
     *  if the value a of "click_action" valid full class name like
     *  "dev.moataz.firebots.sample.MainActivity"  this Activity will be started
     */
    @Override
    public void onNotificationClicked(String clickActionDestination) {
        Log.d(TAG,"ACTION: " +  clickActionDestination);
    }

}

Notification:

body could be:

{
  "to": "some_id",
 "data" : {
 "title" : "FireBots",
 "body" : "Awesome",
 "click_action":"com.example.MainActivity" 
 }
}

"click_action":"com.example.MainActivity" //activity to be opened if valid

Versions

Version
0.0.5
0.0.1