손장민

FCM

...@@ -15,6 +15,14 @@ ...@@ -15,6 +15,14 @@
15 }, 15 },
16 "oauth_client": [ 16 "oauth_client": [
17 { 17 {
18 + "client_id": "650248608909-7h29mrdff01odes6il71t4n9lfmg22ar.apps.googleusercontent.com",
19 + "client_type": 1,
20 + "android_info": {
21 + "package_name": "com.example.user.firebaseauthdemo",
22 + "certificate_hash": "592e808ca47fb608c922b7c021568170cb429b85"
23 + }
24 + },
25 + {
18 "client_id": "650248608909-ec0lmm0sc6eta6bh0n352ked4hcsib83.apps.googleusercontent.com", 26 "client_id": "650248608909-ec0lmm0sc6eta6bh0n352ked4hcsib83.apps.googleusercontent.com",
19 "client_type": 1, 27 "client_type": 1,
20 "android_info": { 28 "android_info": {
......
...@@ -37,6 +37,18 @@ ...@@ -37,6 +37,18 @@
37 <meta-data 37 <meta-data
38 android:name="com.google.android.geo.API_KEY" 38 android:name="com.google.android.geo.API_KEY"
39 android:value="@string/google_maps_key"/> 39 android:value="@string/google_maps_key"/>
40 + <service
41 + android:name=".MyFirebaseInstanceIDService">
42 + <intent-filter>
43 + <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
44 + </intent-filter>
45 + </service>
46 + <service
47 + android:name=".MyFirebaseMessagingService">
48 + <intent-filter>
49 + <action android:name="com.google.firebase.MESSAGING_EVENT"/>
50 + </intent-filter>
51 + </service>
40 52
41 </application> 53 </application>
42 54
......
1 +package com.example.user.firebaseauthdemo;
2 +
3 +import android.util.Log;
4 +
5 +import com.google.firebase.iid.FirebaseInstanceId;
6 +import com.google.firebase.iid.FirebaseInstanceIdService;
7 +
8 +import static android.content.ContentValues.TAG;
9 +
10 +/**
11 + * Created by HANSUNG on 2017-10-12.
12 + */
13 +
14 +public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService
15 +{
16 + @Override
17 + public void onTokenRefresh() {
18 + // Get updated InstanceID token.
19 + String refreshedToken = FirebaseInstanceId.getInstance().getToken();
20 + Log.d(TAG, "Refreshed token: " + refreshedToken);
21 +
22 + // If you want to send messages to this application instance or
23 + // manage this apps subscriptions on the server side, send the
24 + // Instance ID token to your app server.
25 + sendRegistrationToServer(refreshedToken);
26 + }
27 +
28 + private void sendRegistrationToServer(String refreshedToken)
29 + {
30 + }
31 +}
...\ No newline at end of file ...\ No newline at end of file
1 +package com.example.user.firebaseauthdemo;
2 +
3 +import android.app.NotificationManager;
4 +import android.app.PendingIntent;
5 +import android.content.Context;
6 +import android.content.Intent;
7 +import android.graphics.BitmapFactory;
8 +import android.media.RingtoneManager;
9 +import android.net.Uri;
10 +import android.os.PowerManager;
11 +import android.support.v4.app.NotificationCompat;
12 +import android.util.Log;
13 +
14 +import com.google.firebase.messaging.FirebaseMessagingService;
15 +import com.google.firebase.messaging.RemoteMessage;
16 +
17 +/**
18 + * Created by HANSUNG on 2017-10-12.
19 + */
20 +
21 +public class MyFirebaseMessagingService extends FirebaseMessagingService
22 +{
23 + @Override
24 + public void onMessageReceived(RemoteMessage remoteMessage)
25 + {
26 +
27 + System.out.println("received message : ");
28 + Log.d("JM", "From : " + remoteMessage.getFrom());
29 + sendPushNotification(remoteMessage.getData().get("message"));
30 + }
31 +
32 + private void sendPushNotification(String message)
33 + {
34 + System.out.println("received message : " + message);
35 + Intent intent = new Intent(this, MainActivity.class);
36 + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
37 + PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT);
38 +
39 + Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
40 + NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.common_google_signin_btn_icon_dark).setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)).setContentTitle("Push Title ").setContentText(message).setAutoCancel(true).setSound(defaultSoundUri).setLights(000000255, 500, 2000).setContentIntent(pendingIntent);
41 +
42 + NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
43 +
44 + PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
45 + PowerManager.WakeLock wakelock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
46 + wakelock.acquire(5000);
47 +
48 + notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
49 + }
50 + // // ...
51 + //
52 + // // TODO(developer): Handle FCM messages here.
53 + // // Not getting messages here? See why this may be: https://goo.gl/39bRNJ
54 + // Log.d(TAG, "From: " + remoteMessage.getFrom());
55 + //
56 + // // Check if message contains a data payload.
57 + // if (remoteMessage.getData().size() > 0) {
58 + // Log.d(TAG, "Message data payload: " + remoteMessage.getData());
59 + //
60 + // if (/* Check if data needs to be processed by long running job */ true) {
61 + // // For long-running tasks (10 seconds or more) use Firebase Job Dispatcher.
62 + // scheduleJob();
63 + // } else {
64 + // // Handle message within 10 seconds
65 + // handleNow();
66 + // }
67 + //
68 + // }
69 + //
70 + // // Check if message contains a notification payload.
71 + // if (remoteMessage.getNotification() != null) {
72 + // Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
73 + // }
74 + //
75 + // // Also if you intend on generating your own notifications as a result of a received FCM
76 + // // message, here is where that should be initiated. See sendNotification method below.
77 +
78 + // private void handleNow()
79 + // {
80 + // }
81 + //
82 + // private void scheduleJob()
83 + // {
84 + // }
85 +}
...\ No newline at end of file ...\ No newline at end of file