Android server request listener - android

I'm trying to find a solution to listening for a request from a server.
The server would send a String to the phone, based on the ip address of the phone and the android app would take action when it happens.
Has anybody here faced a simular problem and can direct me to an example on the web or something?
Thanks

You can use sockets for it. See here and here.

You can't really be sure of a mobile device's IP address. It can change as you switch between WiFi hotspots, or as you move to a different 3G area. For this to work, the mobile has to register somehow with the server. The usual way to implement it is to keep an open connection, where the server responds with data only when it wants to notify the client. It is possible to create your own implementation, but not trivial. Android has a standard way to do this called Cloud to Device Messaging (C2DM). It is used by GMail and other Google apps, so it's fairly reliable. There are other services that provide something similar, you might want to look into those if C2DM doesn't fit your needs (it requires a Google account, etc.)

Related

Best way to implement a connection between a smartphone and a webpage on a pc

I am looking for an existing library to establish a connection between any smartphone(android/ios/win phone) and a web page.
Sort of what whatsapp is using (https://web.whatsapp.com/), with authentication.
Once the connection is established, i will have to send real time data ( audio and text) from the phone to the pc.
I suppose that whatsApp use a server to relay the data. i dont mind doing the authentication with the help of a server but once the connection is ok,I prefer to do all the communication on wifi instead of sending data from the phone to a server and sending it back to the web page on the pc.
Thanks!
When you want to solve a particular problem which is already solved, You don't want to reinvent the wheel(especially in web) but use the existing solution.
What you are looking for is WebRTC. Fits exactly for your use case. But i am not sure about the development efforts required for this.
There are Client libraries in almost all languages. A quick search gave this for Android
And i am not sure about the device support you are expecting, check Caniuse?
Also have a look at WiFi-p2p for android.
UPDATE:
check this webrtc website for cross platform development support and examples.
There is no real "best" way of doing this, but you have to have a server of some type running on your computer. From there you can use normal network requests from Android to communicate with your computer as long as they are on the same network (WiFi). https://developer.android.com/training/basics/network-ops/connecting.html

Sending data from ASP.NET to android

I'm creating a viber-like application, i.e. android users can make instant messages in their android-powered devices. I've created client-to-server webservices using ASP.NET (ASMX service with JSON response) and it works like a charm, but the other side, i.e. server-to-client requests is just a little headache. Of course I can make my application so that there is no need to server-to-cliend requests (sending dummy requests from client to server in short periods) but in this way server will be overloaded specially when number of users increases. I've found some technologies regarding instant messaging, including GCM and XMPP. What are my other options? or let me ask what is my best option?
Should I use sockets? If so, how can I always have my clients IP (considering that clients are mobile users which may be using WiFi or GPRS/3G/4G internet). I'm thinking of a system in which my clients send their IP each n seconds (n can be around 30), so server always has a (nearly) up-to-date list of client IPs.
Is it possible or even logical to do so?
You should definitely consider using GCM (Google Cloud Messaging for Android)
You need to setup a few things in your server to be able to use it to send via GCM.
Its the built-in way to send data from a server to an android device, hope this can help
Implementing GCM Server
Using the good old strategy of long-polling is always possible, but there are much better ways to do it nowadays. That's perhaps the fastest to implement of the mentioned (not so if you want to implement it correctly and with min amount of load on your server/DB engine). I've seen some projects that start around that architecture with the idea to move to something better in the future .... and the moment to move never comes of course. If you start browsing your Android phone connected to a proxy like Charles you'll see what I mean :)
WebSockets are an option, but I don't see a reason why I'd use them for a Viber-like app, which is event-based (you've received a message) and not "real-time" (monitoring some stock graphics movements for example).
Your best choice here is a Google Cloud Messaging (GCM)! It's easy to implement it both on your backend and on the client, and it's built specifically with the problematic connectivity in mind (switching between wifi/poor 3g/4g/etc). It has some pretty nice features that other methods don't provide "out of the box" - message resending (the common scenario of a client loosing his connection - GCM it'll send the push notification later, when he comes online), automatic syncing between devices (smartphone, tablet, etc) and others.

How to identify that web requests are sent from the library that I've created

I have a backend server, and want to provide an SDK for connecting to that backend server. The sdk is going to be built for iOS and Android and will ship as a library separate for those platforms.
The problem is I want to make sure that the requests are sent only using the sdk that I provide. Basically everybody knows that it is possible to monitor WEB requests using proxy applications like Fiddler or Charles proxy. And it is possible to usurp the requests and send those requests manually as many times as one wants.
For my scenario should be made impossible. So I need a way to identify in the backend that the request that I've received is for sure sent from my sdk. How can I achieve this?
EDIT1:
I can guess something like digipasses may be used. For instance when I log into my bank account I get one time password and log in. But that is based on time, and I can not count on the time of device. May be we can reuse the concept.
Thanks for answers!

Use Android device as a simple server

I need a very simple server that listens for connections, retrieves a question and simply answers yes or no. Then the connection is broken.
As my Android device is the only device that is powered on and connected to the internet 24/7, I'm thinking of using it as the server.
Is this possible, and how could I achieve this? The biggest problems that I'm facing is the ip-address, as it could be changing a lot. I'm thinking of storing it in a public dropbox file, so the client can retrieve the address from that
There's a whole slew of reasons why you shouldn't use your android device as a server, but I won't go into those. I'll just assume you have a good reason for doing what you want to do.
Since your question is very general, the best I can do is give you a very general answer. You'd implement a server on android like you would any other server using java using sockets. For a simple java implementation of a socket based server, checkout this tutorial. The tricky part is going to be getting your IP address to share with clients so that they can connect to your device. As nick suggested, dyndns might be an option here, but I'm not sure if they have a mobile client.

Remote wipe data using Device Administrator Application+ android

I am working on android device policies, i am able to implement wipe data, force lock using sample given at below link
http://developer.android.com/guide/topics/admin/device-admin.html. I am not able understand how to wipe, force lock, change pwd Remotly from server. I spent lot of time in searching to get information but i am not suceed. Please give any information to implement policies Remotely.
Thanks in advance.
I've googled around a bit today as well, and I've come up with the following solution:
First, write a device administrator app, like the one referenced in the link you provided.
Then you will have to implement some technique so that you can push messages from a server to the android client. As of Android 2.2, you can use C2DM (Cloud to device messaging) provided by Google, I guess it isn't to hard to configure and get going. If you do not want to use this, there is the option to use some other kind of messaging framework, that allows you to push data, like XMPP or MQTT. The facebook messenger app for iOS uses MQTT, so that can't be all bad. It will however require more work setting up, than C2DM for example.
Finally you will have to push some kind of message from your server to the client via the method you chose and let your device administrator app listen to these messages and respond with the correct action, depending on message. So you can decide on your own what the messages will look like and contain.
There is also the option of using Exchange, but I do not know how that works.
So that is basically what I found out from my little research, I'd love to hear other ideas from someone else as well.

Categories

Resources