Send message from Android mobile app to Azure IoT Hub - java

For an IoT project, we need to send messages from mobile application (iOS and Android) to Azure IoT Hub. We were able to do it connecting as a device using MQTT library. However, the device simulator too connect as a device and since both uses same device ID, the existing connection is dropped when both connect to IoT Hub at the same time.
We realized we need to connect mobile apps as a service (not as a device) and for that some research shows we need to use following library.
https://github.com/Azure/azure-iot-sdk-java
https://github.com/Azure/azure-iot-sdk-java/blob/master/service/iot-service-samples/service-client-sample/src/main/java/samples/com/microsoft/azure/sdk/iot/ServiceClientSample.java
However, this java sample uses lot of java specific implementations and which are not supported by Android.
Has anyone faced the same problem?
Which library can we use to achieve above from Android mobile application?
Which library can we use to achieve above from iOS mobile application?
Please let me know if any alternate solution is available.

You can use a REST API for sending a D2C message to the Azure IoT Hub. The following screen snippet shows an example of this call. Note, that no library is required for this request.
another solution for your scenario is to use an Azure Function as a pre-processor to the Azure IoT Hub, see the following example:
Thanks
Roman

Just as additional content about another solution for your scenario. Based on my understanding and per my experience, I think you can try to create an App service, such as Mobile App for using Custom API at the side of client & backend, or WebApps, etc, to receive the payload which includes custom json properties from your Android App, and forward the payload message using Azure IoTHub SDK for NodeJS or Java to IoTHub.

Related

how to create nodejs xmpp server and android xmpp client

I want to add chat module to android app. Firstly I want to use XMPP using Nodejs. How nodejs xmpp server works with android client.
Can nodejs xmpp server can communicate with android app? if yes than, how can i create simple nodejs xmpp server and simple android app that both can communicate.
If you have any other solution please let me know.
I am tried socket.io but i dont want to use that. It is not worked stable on android client side. Some messages send some not send. I am used few solutions for solve this problem (ping pong, heartbeath, change java client libraries for socket io, ...). But nothing changed.
My aim is to create stable fast chat module to android and ios application using with nodejs server.
Please guide me, thank you in advance.
Have you tried checking other solutions like ConnectyCube, Firebase, Layer, etc.?
They provide a ready backend and all you need to care about is configuring your client-side app.
Some of them even have ready Android client-side libraries which can be integrated in your app and speed up the development.

How to send push-notifications from java-server?

I have apps on Android & iOS, & I need to send push-notifications to them from Java-server.
Please tell me, where can I find guides how to do this? I'm looking GCM & APN for Android.
https://firebase.google.com/
That is what I use for project and I am satisfied with it.
You have all needed tutorials and docs to start working with it.
Overview:
firebase provides You with Admin SDK wich helps You build Data and Notification messages and send it to firebase, firebase then sends it to either iOS or Android if You send it to specific client or to both if You send it to some created topic.
It also have easy to use Android, iOS, JavaScript libs to handle it on client-side.
ofc to get this work with Your server Client must generate notification token from provided google api and send it to Your server to store in DB.
there are some restriction though with push notifications 2kb if I remember correctly and 4kb for data messages keep it in mind when you create your communication architecture :)

Building 3rd party server app to connect GCM from Android over xmpp

I am building android app1 and app2, which will send data to each other based on this tutorial. The tutorial on GCM and xmpp is pretty straightforward. Google requires 3rd party server app with a backend to send upstream and downstream data to and from the android apps, which is something I couldn't understand. Should that app be an android app to? Or java app on a desktop(because it should run always nonstop)? I couldn't find a tutorial on building that server app. Can someone give me a hint or example?

Push Notification for iOS device

Can anyone help me in details how to send push notification for iOS device while I am using Java for server side program and I am using Google App Engine.
Thanks.
First you must have access to Sockets Java API, which requires you to enable billing.
Second, use the java-apns library. It needs some modifications to run on AppEngine.

How to implement push notifications on my android device

I have a very basic design of my entire application, where several users with my app on there android devices commits data to the server (I have used REST web services(java) + postgresql as my server) through HTTP post request from the android application. I am successful in achieving this and app runs absolutely fine. Now i want to implement a scenario where any change(CRUD operations) on my db on server should create a notification on my users android device. How should i achieve this with my server design unchanged? I have looked into Google Cloud Messaging, but could figure out the server implementation.
For now i have implemented db triggers on postgresql and able to get control back into java code using Notify/Listen feature of postgresql. From here i need to connect to android device. How can this be achieved. Is Google Cloud Messaging the only way? I have not seen any insert/update statements in there server implementation. Could anyone please guide me on this?
either you can use GCM or implement a Socket at server end and open a socket connection from mobile but this approach may add some additional processing overhead because it will create a daemon thread to listen socket port from mobile device.
You should use native library (NotificationManager etc.), here you can find a great tutorial.
My Advice is for you to use GCM. GCM normally takes a maximum of 4kb, so you could have your own defined "commands". You could use them to determine the requests on both ends, ie on android app and the server end. A php script on the server would help you in this.
I am working on an app where by the android app sends messages to the server via POST and the server forwards the message to the appropriate user via GCM. In my case I have very many things to share so in that case I am using commands, for example if it is a new incoming message I send a GCM to the app with one variable as the command and the rest as the data. On the android app I use the command variable to determine what to do with the data.
Kindly avoid that socket advice, it will have your app drain the battery to sustain the open socket , besides you don't have to re-invent the wheel while Google servers already has it

Categories