How to access directly internet on WearOS app - java

I am looking for My data on wear OS app to send to my external apache server with php and mysql.
Ultimately I need watch sensor data in MySQL database, So i created a POST request page using php. How do I send POST request?
Note: I am not using mobile phone between WearOS app and My server. WearOS is connected to internet via WiFI
Please if you know any solution help me
FYI: I tried basic things given at https://developer.android.com/training/wearables
Using Smart Watch with API level 23
Regards

Unfortunately your watch system version is too old. I strongly recommend you to buy a new watch or try update to Wear OS 2.x (API25) if your device is still under maintain.
If you insist on using current device the only way to access the Internet is via mobile phone. You can not send HTTP requests directly.
But the old version system should not be able to connect the WiFi. Please confirm your version at first. If your API level equal or larger than 25, you can access the Internet as same as phone using OkHttp or others you like.

Related

Host database using Android phone

Here is the current scenario:
I have two(2) Android phones.
Android Phone 1 as the server phone.
Android Phone 2 as the client phone.
Here is what I want to do:
I want to create an Android-based app (E.g. Student Information app) where it will have basically two (2) modes:
Server - for adding, editing and deleting data on a local database.
Client - for viewing data from the database of the server.
The app will be installed to Android Phone 1 and set to Server mode.
The app will be installed to Android Phone 2 and set to Client mode.
I want to ask these questions:
I want to locally host the database of the Server app, so that Client app will be able to view the data. Is this possible?
If yes, how can I do it?
Note:
I am currently a web developer so I know that connected on the same network is a requirement.
I have implemented the same concept on a medium business where the web-based system is locally hosted so that computers on the same network can access it.
Suggest everything that you want to suggest, except the disadvantage of doing this concept. I am aware of some obvious disadvantages based from my research and willing to face the disadvantages provided that I will be able to implement the concept.
Rooting the phones is an option.
I want to accommodate small-sized business that is why I want to use Android phones rather than using Desktop Computers/Laptop.
I have read similar suggested questions here based on my title.
We have done the exact same thing in my company. The way we solved this is that the server exposes a service using the Android NSD API, so the clients (using the same API) can find it on the network. And after a client has connected to the server, the server sends its database file (yes, the .db file in /data/data/...) to the client via OutputStream. When the client receives the entire database and checks for its integrity, it copies it to its own /data/data/... and restarts part of the app.
Android NSD

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

What is the established way to request data from an android device

I currently have an small application that I have been using to learn java/android programming. Right now I have a setup were the app on one phone sends a request (via sms) to another phone running the same app. The remote phone receives the request and sends back some info. Next I would like to try this from the web. Is there an established "best" way to to this?
I was thinking I would have a web server send requests to the device via google cloud messaging and then have the device return the data directly to the web server. (Not that I really know how to do any of that just yet).
I see that there is a google cloud messaging return path (send messages from the device to the google cloud server, but it seems very new, do I need something like that? The main thing I want is to be able to ask the phone to do something when I want, not have it poll to see if there is a request, or just periodically update some status.
UPDATE:
Thanks to the answers below for confirming to me that I was on the right track.
I now have some basic functionality.
I started out using this gcm android demo code
https://code.google.com/p/gcm/source/browse/#git%2Fgcm-client%2Fsrc%2Fcom%2Fgoogle%2Fandroid%2Fgcm%2Fdemo%2Fapp%253Fstate%253Dclosed
and this ruby gem
https://github.com/spacialdb/gcm/blob/master/README.md
between the above two I was able to send a message to my phone pretty easily.
To get the round trip working, I setup a very simple rails app on heroku.
I included a modified version of the sample code in the gcm gem in a controller and then used
HttpPatch (needed for rails 4) to send a post/patch from my phone to my web app, the controller then echoes the message back to my phone.
I guess it would be nice to get the two way gcm stuff to work, but I am not sure there are any gems that handle that, and I am not qualified to handle a task like that :)
I would say it's the right call: Google Cloud Messaging for Android
From the site Android Developer:
This could be a lightweight message telling your app there is new data
to be fetched from the server (for instance, a movie uploaded by a
friend), or it could be a message containing up to 4kb of payload data
(so apps like instant messaging can consume the message directly).
In this case you don't want to fetch data from the server but you want to send them.
You can send them in different ways. I would suggest, since you are learning, to try a RESTful solution using one of the implementation of JAX-RS.
As a short and direct answer for beginner : GCM (Google Cloud Messaging) would solve your issue. However, if your app turned out to be something bigger, other more technical and complicated solutions are present too.
see this link.

Using Android license verification serverside

I've been thinking about implementing of Google Play licence check on my Java server. Is that even possible? I haven't been able to find anything on this matter. I know Android LVL is written in Java, but I'm not sure if it can run outside of dalvik machine. Is there a posibillty of checking Google account name or some kind of device ID against Google Play to check whether an app has been bought in a Java server application?
The answer above is simply verifying response data (returned by google LVL on android device) on app server.
I think the question is asking if it's possible to call some google web API to do Google Play license check on its app server. But it seems like google doesn't open the web API interface to its licensing server, all LVL calls need to be done using its google play service framework on android device.
Yes it's possible, the java sources are out there and could be downloaded (and afaik, the jar is not dexed until you compile your application) - see some kind of manual over there at developers.android.com to read about how to get the sources
I've heard about a PHP project trying to attempt it, but using java should be no problem at all - you do the same things on the server, the manuals state for the client - and let the client sends the encrypted response from the market directly to the server via SSL (e.g. byte[] post)
You should get a UID from ResponseData.userId
Read some more in this blog post and more info and links in another SO answer

Mobile to Mobile Remote Access using Android

i am developing an APP in Android which share screen to all android mobile phone connected in a session.
i want to know that android provides any sdk which provides same service like desktop to dektop access as in team View ?
or any Idea, which SDK i have to used?
Thank you.
Smartphones can't directly connect to each others since they are running in different networks. The common way to solve this is an additional server component. All phones need to connect to the server and send their data. The server is pushing this data to other connected clients, probably by using push notifications. In Android Push Notifications are known as C2DM.
Android developers blog:
http://android-developers.blogspot.com/2010/05/android-cloud-to-device-messaging.html
Here's another tutorial on the topic:
http://www.zylinc.com/blog-reader/items/c2dm-a-simple-introduction-using-a-java-server.html
I like 2X RDP a lot. It works very well on phone and tablet and connects to the regular Windows RDP server, so don’t have to install anything else on the server machine.

Categories