Commit c4dd53d3 authored by Varun Patil's avatar Varun Patil

Add FCM push notifications

parent 6c2fa89e
......@@ -38,6 +38,7 @@ ext {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.google.firebase:firebase-messaging:17.1.0'
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
......
{
"project_info": {
"project_number": "306601329049",
"firebase_url": "https://iitb-app-5c0aa.firebaseio.com",
"project_id": "iitb-app-5c0aa",
"storage_bucket": "iitb-app-5c0aa.appspot.com"
"project_number": "259853447628",
"firebase_url": "https://astral-theory-207617.firebaseio.com",
"project_id": "astral-theory-207617",
"storage_bucket": "astral-theory-207617.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:306601329049:android:950a72a311331b9c",
"mobilesdk_app_id": "1:259853447628:android:efaea50ea28ccfec",
"android_client_info": {
"package_name": "app.insti"
}
},
"oauth_client": [
{
"client_id": "306601329049-6v597vrdv0nbi15ehpehq8hiaek8unqp.apps.googleusercontent.com",
"client_id": "259853447628-be3teletcqtfpfddj9qnk0bqj221h2mo.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyC1oThCMZN3JMnK6MUTJRjkp47q1K_gnTA"
"current_key": "AIzaSyB8B7N-3hnW_u4jOXHLRUzbMl6To3aDyJo"
}
],
"services": {
......
......@@ -76,23 +76,11 @@
</receiver>
<service
android:name="app.insti.gcm.MyGcmListenerService"
android:exported="false">
android:name=".InstiAppFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service
android:name="app.insti.gcm.MyInstanceIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID" />
</intent-filter>
</service>
<service
android:name="app.insti.gcm.RegistrationIntentService"
android:exported="false"></service>
</application>
......
package app.insti;
import android.util.Log;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
public class InstiAppFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onNewToken(String s) {
/* For future functionality */
super.onNewToken(s);
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
/* For future functionality */
super.onMessageReceived(remoteMessage);
}
}
......@@ -20,6 +20,7 @@ import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.firebase.iid.FirebaseInstanceId;
import app.insti.api.RetrofitInterface;
import app.insti.api.ServiceGenerator;
......@@ -142,8 +143,19 @@ public class LoginActivity extends AppCompatActivity {
progressDialog.setIndeterminate(true);
progressDialog.show();
}
RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class);
retrofitInterface.passwordLogin(username, password).enqueue(new Callback<LoginResponse>() {
Call<LoginResponse> call;
/* This can be null if play services is hung */
if (FirebaseInstanceId.getInstance().getToken() == null) {
call = retrofitInterface.passwordLogin(username, password);
} else {
call = retrofitInterface.passwordLogin(username, password, FirebaseInstanceId.getInstance().getToken());
}
/* Log in the user */
call.enqueue(new Callback<LoginResponse>() {
@Override
public void onResponse(Call<LoginResponse> call, Response<LoginResponse> response) {
if (response.isSuccessful()) {
......
......@@ -29,6 +29,9 @@ public interface RetrofitInterface {
@GET("pass-login")
Call<LoginResponse> passwordLogin(@Query("username") String username, @Query("password") String password);
@GET("pass-login")
Call<LoginResponse> passwordLogin(@Query("username") String username, @Query("password") String password, @Query("fcm_id") String fcmId);
@POST("events")
Call<EventCreateResponse> createEvent(@Header("Cookie") String sessionId, @Body EventCreateRequest eventCreateRequest);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment