Домой United States USA — software Reliable and Fast Messaging and Notification Services for Android

Reliable and Fast Messaging and Notification Services for Android

297
0
ПОДЕЛИТЬСЯ

In this tutorial, we learn about Alibaba Cloud Message Service for messaging and notification services (MNS) for Android, implemented with Android Studio 3.
Let’s be friends:
Comment ( 0)
Join the DZone community and get the full member experience.
This is a sample project created to demonstrate the use of Alibaba Cloud Message Service on Android. This application shows the capability of the Message Service for messaging and notification services (MNS). You can find the repo of this project on my GitHub page.
Activate the Alibaba Cloud Message Service and get the access keys from your Alibaba Cloud Console. You can find more information about this step on the documentation center.
Create Queue and get the endpoint. Follow this link for an illustrative guide.
Create a new Android project with Android Studio 3.0.0.
Select your required values. I am targeting API 19 and above.
Select the appropriate activity. I am choosing an empty activity
Create the class, give an appropriate class name, and create the appropriate activity.xml too. I am using MainActivity.
Fill the XML details in below and copy it in the strings.xml.
Then, switch your project view to Project in your Android Studio as shown below:
Go to the libs subfolder located under app folder, and copy the two libraries – aliyun-sdk-mns-1.1.18.jar & Jaxb-api.2.2.12.jar. Right-click the libs folder and you will see the option «Add to Library.»
Go to your app build.gradle file then copy the code below.
Enable multidex in your custom application class. Then, add this application class to AndroidManifest.xml
Then enable the application to access the internet by adding «uses-permission» outside application tag but inside manifest.
and then copy paste the below after your activity tag
Now, we have to create the service for our application, which receives notification, broadcast receiver, UI, and logic for sending, receiving, and sending notifications. 13. Let’s create the UI copy the below code to your activity_main.xml.
Copy the below code and add it to your MainActivity.java
Then Create a class named «ReceiveService» and cope the below code.
Then, create a class named MessageReceiverand copy the below code
Create a package asynctasks package, and under that create a class called RcvNtfcnTask and copy this code.
Then, create one more XML named inputdialog under res > layout, and copy the below code
That’s it! If everything is done correctly, all your compilation issues will go away and the application starts installing by clicking the small play (run) button in the status bar of Android Studio.
Please take a look at my GitHub page for the final code repo and let me know if you face any issues, or raise any pull requests for improvements!
Free DZone Refcard
Comment ( 0)
Published at DZone with permission
of
Sai Sarath Chandra
, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.

Continue reading...