இதற்காக MyAndroidFirebaseMsgService எனும் பெயரில்ஒரு புதிய ஜாவா இனத்தை உருவாக்குக அதில் பின்வரும் குறிமுறைவரிகளை சேர்த்திடுக.இது FirebaseMessagingService ஐ நீட்டிக்கும் சேவையாகும். இது பின்புலத்தில் அனைத்து வகையான செய்தி கையாளுதல்களையும் செய்கிறது தொடர்ந்து அவை கிடைக்கும் போது புஷ் அறிவிப்பினை அனுப்புகிறது.
MyAndroidFirebaseMsgService
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
public class MyAndroidFirebaseMsgService extends FirebaseMessagingService {
private static final String TAG = “MyAndroidFCMService”;
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
//புகுபதிவு கேட்(Cat)டிற்கு தரவை பதிவு செய்க
Log.d(TAG, “From: ” + remoteMessage.getFrom());
Log.d(TAG, “Notification Message Body: ” + remoteMessage.getNotification().getBody());
//அறிவிப்பை உருவாக்குக
createNotification(remoteMessage.getNotification().getBody());
}
private void createNotification( String messageBody) {
Intent intent = new Intent( this , ResultActivity. class );
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent resultIntent = PendingIntent.getActivity( this , 0, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri notificationSoundURI =
RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder mNotificationBuilder = new NotificationCompat.Builder( this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(“Android Tutorial Point FCM Tutorial”)
.setContentText(messageBody)
.setAutoCancel( true )
.setSound(notificationSoundURI)
.setContentIntent(resultIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, mNotificationBuilder.build());
}
}
onMessageReceived()எனும் செயலியை நாம் அழைத்தால் உடன் செய்திஅறிவிப்பு ஒன்றினை கிடைக்கப்பெறுவோம் இந்த செயலிக்குள் LogCatஎனும் முகப்புதிரைக்கு பூட்டிடும் செய்தியை பெறுவோம் தொடர்ந்து உரைச்செய்தியுடன் createNotification() எனும் செயலியை அழைத்திடுகின்றது இந்த createNotification() எனும் வழிமுறை படத்தில்காண்பித்துள்ளவாறு ஒருபுஷ் செய்திஅறிவிப்பொன்றை ஆண்ட்ராய்டு செய்திபகுதியில் உருவாக்குகின்றது
நாம் NotificationCompat.Builderஎன்பதை பயன்படுத்தி ஒரு புதிய செய்திஅறிவிப்பை இயல்புநிலை ஒலிசெய்தி அறிவிப்புடன் உருவாக்கிடலாம் தொடர்ந்து இணையத்திற்கு ResultActivityஎன்பதை கடத்தலாம் .
2. MyAndroidFirebaseInstanceIdService எனும் ஒரு ஜாவா இனத்தை உருவாக்கிடுக அதில் பின்வரும் குறிமுறைவரிகளை சேர்த்திடுக இது ஃப்யர்பேஸின் தயார்நிலை சேவையாளரின் விரிவாக்க சேவையாக விளங்குகின்றது தொடர்ந்து இது நுழைவு அட்டையை உருவாக்குதல் பதிவுசெய்தல் சுழல்முறையில் மாற்றுதல் ஆகிய பணிகளை கைாளுகின்றது .மேலும் இது குறிப்பிட்ட செய்தியை குறிப்பிட்ட சாதனங்கள் / சாதன குழுக்களுக்கு அனுப்பியிருப்பதை உறுதி செய்கிறது.
import android.util.Log;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;
public class MyAndroidFirebaseInstanceIdService extends FirebaseInstanceIdService {
private static final String TAG = “MyAndroidFCMIIDService”;
@Override
public void onTokenRefresh() {
//நுழைவுஅட்டையை பெற்று வைத்திருக்கவும்
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
//நுழைவுஅட்டையை பதிவுசெய்திடுக
Log.d(TAG, “Refreshed token: ” + refreshedToken);
}
private void sendRegistrationToServer(String token) {
//நம்முடைய சேவையக கணினியில் நுழைவுஅட்டையை சேமித்து வைத்திட நாம் விரும்பினால் உடன் இந்த வழிமுறையை செயல்படுத்திடுக
}
}
இதன்பின்னர் onTokenRefreshcallback எனும் செயலியானது ஒருபுதிய நுழைவுஅட்டை உருவாக்கிடும் செயலை தூண்டிவிடுகின்றது onTokenRefresh() எனும் போட்டியில்getToken() எனும் செயலியை அழைத்து நடப்பில் தயாராக இருக்கும் நுழைவு அட்டைபதிவை அனுகுவதற்காக உறுதிபடுத்திடுகின்றது அதன்பின்னர் நாம் மிகசாதாரணமாக புத்தாக்கம் செய்து உள்நுழைவுஅட்டையை உள்நுழைவுசெய்திட பயன்படுத்தி கொள்ளமுடியும்
பின்னர் activity_main.xml எனும் கோப்பினை திறந்துஅதில் பின்வரும் குறிமுறைவரிகளை சேர்த்திடுக. தற்போது செயல்களின் பெயரைமட்டும் திரையில் காண்பிக்குமாறு ஒரேயொரு TextView ஐ மட்டும் நாம் கைவசம் வைத்துள்ளோம்
activity_main.xml
1. MainActivity.javaஎன்பதன் உள்ளடக்கங்கள் மட்டும் இயல்புநிலையில் முன்னிருப்பாக இருக்கும்
MainActivity.java
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
இதனை தொடர்ந்து ResultActivity.javaஎனும் ஒரு புதிய ஜாவாவின் செயலியை உருவாக்கிடுக அதில் பின்வரும் குறிமுறைவரிகளை சேர்த்திடுக
ResultActivity.java
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
public class ResultActivity extends AppCompatActivity {
private TextView textView ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView)findViewById(R.id.textView1);
textView.setText(“Welcome to the Result Activity”);
}
}
இதன் இறுதி விளைவாக செயல்பாட்டிற்கான activity_main.xml இன் தளவமைப்பை மீண்டும் பயன்படுத்துகின்றோம், மேலும் “Welcome to the Result Activity என உரையை மாற்றுவோம்
செய்தி அறிவிப்பினை பெறப்பட்ட வுடன் பயனாளர் ஒருவர் அதனை சொடுக்கும்போது இந்த செயல்பாடு அழைக்கப்படும்.
இப்போது பயன்பாடு அனைத்தும் முடிவடைந்துவிட்டது, அதனை தொடர்ந்து FirebaseNotifications எனும் குழுவிலிருந்து அறிவிப்பு ஒன்றினை அனுப்புவதன் மூலம் நம்முடைய பயன்பாட்டை பரிசோதித்து பார்த்திடுவோம்.
ஃபயர்பேஸின் முகப்புபக்கத்திற்குள் உள்நுழைவுசெய்தபின்னர் பின்வரும் படங்களில் உள்ள படிமுறைகளை பின்பற்றிடுக.
மேலே படங்களில் காண்பித்தவாறு செயற்படுத்தியவுடன் புதிய அறிவிப்பு செய்தியொன்று உடன் பின்வருமாறு உருவாகின்றது வாழ்த்துக்கள் !! தற்போது நாம் செய்தி மற்றும் புஷ் அறிவிப்புகளுக்காக நாம் Firebase Cloud Messaging ஐ ஆண்ட்ராய்டு பயன்பாட்டுடன் வெற்றிகரமாக ஒருங்கிணைத்து விட்டோம் . அதனை தொடர்ந்து ஃபயர்பேஸின்முகப்புத்திரையிலுள்ள அறிவிப்புகளின் பலகத்தில் அனைத்து செய்திகளையும் நாம் காணலாம்