Android client to client messaging without my own

2019-05-21 09:45发布

I am doing a prototype that involves messaging between clients.

What I want to do - from MyApp on device1, able to send message to MyApp on device2. Device2 should receive this and show a notification.

I don't have my own application server to push notifications from GCM to GCM clients.Is this possible ? How to do it ?

What I investigated - PubNub, which has a trial license that seems to answer my need to send messages on a channel without needing a server.

This discussion at SO didn't help much.

sending client to client messages without server interaction

Can anyone suggest better ways ?

3条回答
Viruses.
2楼-- · 2019-05-21 10:22

PubNub Realtime Messaging and Push Notifications

(server not required)

With PubNub, you do not need your own server to do the realtime messaging or the mobile push notifications. You likely have your own server for your database (MySQL or similar, traditional RDBMS, a No SQL DB like MongoDB, or a realtime DB sync, like Firebase) to authenticate users and such.

For realtime DB or non-DB type change notifications and signaling (any type of realtime messaging), PubNub makes is super simple to receive messages in realtime with a mobile push notification fallback in one publish action. So the GCM message will be sent along with the realtime message. If the app is actively running, you get it in realtime (< 1/4 on average - typically faster) and the GCM message will be received if the app is not active (background or not started at all).

And PubNub's free plan is not a trial (anymore). It is free (including all add-ons) for as long as you stay within the free plan limits.

See the PubNub Android docs for more details and contact PubNub support if you have any further questions with getting started or getting answers to any questions you have as you progress with your app implementation.

查看更多
太酷不给撩
3楼-- · 2019-05-21 10:26

You basically have to use a server in one way or another. I think Firebase would be perfect for your purposes. It has an Android plugin you can use that will basically alert your app when something changes in the database. Here is the documentation for that feature. Take a look at this example for implementation. Before you can use the plugin, you need to create an account and whatnot (basic one is free). Here are the instructions.

查看更多
4楼-- · 2019-05-21 10:38

Another possibility is to use the SMS.

Android Send and Recieve Messages

"Send Binary (Data) SMS

We can send binary messages (as opposed to text based messages that we covered earlier) to specific application ports using sendDataMessage(). According to this Stack Exchange thread data sms is one which is sent over 2G/3G as well as GSM. I’ve tested it with mobile data turned off and it works fine charging me the same amount, so not very sure on whether it uses 2G/3G or not, but generally the term data is used in telephony when it’s related to network (tcp/ip). Anyway, SMS’s are generally sent to a specific port on the device (which is probably port 0 [zero]). But using sendDataMessage() we can send SMS’s to some other random port on which our app can listen for incoming SMSs and do something with that. In this case the default messaging app will not store the SMSs in their inbox for both the sender as well as the receiver. "

查看更多
登录 后发表回答