WebView and sort of private webserver - Android Software Development

Hi All.
I'm looking for some implementation advice. I hope you can help me
I'm planning to build an application working mostly inside a WebView and some javascript code running inside of it. I need also that the underlying native java code to provide, as a dedicated web server for this WebView, any kind of data (typically json strings) in response to ajax calls made by the javascript program.
A ContentProvider sounds a good idea, mainly because it allows me to addess it using an URL in the javascript code but it only lets me serve static files, so it isn't suitable. I need to generate run-time the answer string to ajax calls.
I hope I explained myself. How can build this kind of private web server?
thanks for all your help.

Related

Passing a WebView between activities?

Hi,
I'm a bit of a noob at all this. I've been experimenting with a test app that involves using a WebView to access a service via a website. The site as it is normally browsed is not very mobile friendly, and has no mobile equivalent. It doesn't use a simple authentication system and there are no APIs or nice friendly XML web services from which I can pull data. The service requires users to login and input random letters from their password in order to authenticate, along with an SSL handshake, the web browsers session ID forms a part of the authentication process. It is impossible to get a user logged in and pull data without using a web browser basically.
The test app I have built uses an invisible webview, and when a page finishes loading it injects javascript that enables XPath in the WebView so that the app can pass user inputs and data from the app's UI to input boxes in the invisible webview. So basically, what I want to do is load a page, analyse the contents of the page, and build a mobile-friendly UI for the user to interact with, and present the data from this service nice and easily on the move. It would probably run like ass over a standard GPRS connection, but in areas with 3G and HSDPA - I think it could be useful.
Now to achieve this - I can either have *one* activity, and program a loop whereby when a page has loaded the app dynamically rebuilds the layout(s) in that activity (I'm not entirely sure I know how to do that).... OR I can try and save the webview state and pass the webview between activities. That would be much easier, because I could build activities ready-made for certain eventualities.... Is passing a webview between activities possible?

Advice on the choice of querying a remote DB

Hello everyone,
I come to you for some advice about an application I'm developing for Android 1.6 and higher.
Specifically, this application must be able to query a remote MySQL database and display the retrieved data. It need also be able to UPDATE data on this databse and that is where things get complicated ...
For selection queries, I wrote a small PHP script on the remote server that retrieves the desired data in the database and encodes them in JSON. From my Android application, I have no problem to retrieve, process and display them.
Now I wonder about the solution (if there is one ...) to run UPDATE from my application on the remote database. For now, I see only two solutions:
- Develop a webService on the server with an update method. Several problems with that: it seems webServices on Android are not easy (not native, have to go through external libs). Moreover, as it's UPDATE query, I want to make sure nobody else can use this webService.
- Alternatively, write a PHP script that makes the UPDATE and call it via HTTP. Same problem as webService: I want to secure this call to be sure that only I can use this script. These scripts can be integrated into an application already present on my server and which is secured by login / password. So, if it is possible to manage PHP sessions from Android, it's won! but Ican't find anything about it ...
What do you think? Ideas?
Thx!

[SOLVED][Q] Android Login Application

Hello everyone !
I want to create an android app, that should take input username and password and then login to a website. Basically any website. Well, I am trying to create an app for a website with login page in .aspx form.
I googled regarding this but was unable to find some effective solution. Almost all websites I searched contained only login page design and a simple java code which equals username and password and then makes a toast text. I need some info regarding how to login into that particular page with active session.
Let login page be: 127.0.0.1/login.aspx
I am not a beginner and have developed few apps. This project is very important for me. So please help me regarding this.
Anykind of help is highly appreciated. Please do help.
Thanks
Come On Guys , Show some effort
Making apps "for website" in my opinion could be easily sorted turning the app "server side"... read my comment at this post.
By following my advice you have several advantages:
Users don't need to update their app when new version comes out
Harder to crack (unless they hack your server...)
Compatibility with different platforms/os
No disk-space needed on user device
If you really really need java code for that (as it's a school project requiring java or something ...) have you considered using raw sockets (probably not the best idea, but you asked for "Any kind of help" so... ) ? You said you have experience (I don't with java so can't help with the code, but I used similar technique in python, php, etc, ...) so it shouldn't be hard to find a simple code snippet for handling raw packet sending... Use your PC and fire up Wireshark or any other sniffer and debug the communication between client-server. Look at the header informations and data sent, and it will be easy to replicate those request-response via raw socket.

Commerce Application

Hello,
Early apologies if this is an incorrect forum but it's what i found about app development. If so can someone link me to something relevant?
I am going to preface this post by saying I have been using OOP languages for a long time now yet all localized self contained programs usually in python. I've gotten fairly used to some of the android API and parsing XML data to java and the reverse however I'm completely ignorant when it comes to php parsing.
I'm working on an android project for a client. I want to do an commerce application. Starting off I have already established XML UI's for a logging in, new user, main menu, and product search page. My main concern at this point is getting the remote data. Please correct me if I'm wrong but this was my plan for data handling.
Three different PHP scripts on a remote go-daddy server to access a database that holds a user data table as well as a product data table structure is as you'd expect user:{first_name, last_name, password, ect....} product:{SKU, UPC, Name, ect...}.
One of these PHP scripts pulls data from the products table for the products activity. One compares log-in credentials for the log-in activity so people can find purchase history ect... and one inserts rows to the user table for the new user activity.
Again if this isn't optimal some advice would be helpful. If this setup works however I already have a written PHP script(again held on the remote server) that parses the data into JSON format. My next step would be to write the java for the products activity to run the script and parse the JSON back into a usable format. Is there a specific java library to do this? Any UML depictions or tutorial links would be appreciated,
Secondly a big concern would be the new user script specifically how do i pass data from the java activity into the php "Insert script" i've read some on GET and it seems to be applicable to html but not java also this would be stupid for password security. again any help on any of these matters would be appreciated.
Have a look at Google's Gson library. It's great.

[Q] Problems with GCM

Hi guys, I have basically never touched android development before and still meddling around with some tutorials (and i really do not understand most as it is somewhat quite different from Java).
Now i have an project which i need to do basic to advanced development (i think its quite advanced).
I am planning to have an app that can receive a signal from the server that a order is done and it will vibrate or wake the phone screen up.
server would be running php, apache and mysql
1) i key in (or scan in) a string of numbers (tracking number etc)
2) In the server, an entry of this tracking id and its details should be already created in the mysql database with a column 'ready' with values [true/false]
3) when 'ready' turns true, I want it to contact the app. But i do not how to implement this part. I saw some articles talking about CGM but i am not sure.
4) it should be able to connect via wifi or mobile network or check connection to server
5) and how do i mark this order as done on the app-side,; if not it will keep polling the server for this tracking id
As you need both side communication.GCM CCS(Cloud Connection Server) is perfect for your needs.Check GCM CCS Docs.I hope it will help you.
mohitsinghs said:
As you need both side communication.GCM CCS(Cloud Connection Server) is perfect for your needs.Check GCM CCS Docs.I hope it will help you.
Click to expand...
Click to collapse
Which is better or easier?
Using CGM or set the application to poll the server if a tracking number exists?
For example is a PUSH or PULL recommended
sianzb0i said:
Which is better or easier?
Using CGM or set the application to poll the server if a tracking number exists?
For example is a PUSH or PULL recommended
Click to expand...
Click to collapse
I think GCM is easy to implement. If you are using android studio,you can add it easily. For examples you may see the sources of iosched and todo.txt backend example.
You should read the documentation and should go through the sources of iosched and todo.txt to see how easily it all happens.
mohitsinghs said:
I think GCM is easy to implement. If you are using android studio,you can add it easily. For examples you may see the sources of iosched and todo.txt backend example.
You should read the documentation and should go through the sources of iosched and todo.txt to see how easily it all happens.
Click to expand...
Click to collapse
I have helped a friend set up eclipse with Google App Engine, but when we were looking through, some of the features in the App Engine is not free (they have $300 worth though).
I will try and give it a shot first. Meanwhile I will also looking into polling the mysql DB via PHP
sianzb0i said:
I have helped a friend set up eclipse with Google App Engine, but when we were looking through, some of the features in the App Engine is not free (they have $300 worth though).
I will try and give it a shot first. Meanwhile I will also looking into polling the mysql DB via PHP
Click to expand...
Click to collapse
GCM HTTP: Downstream only: cloud-to-device.
GCM CCS: Upstream and downstream (device-to-cloud, cloud-to-device).
Thats why I suggested you CSS over HTTP. Note that Google AppEngine does not support connections to CCS so you need your own server implementation if you need both side communication.Otherwise you can try GCM HTTP with AppEngine.That all depends on your need and how you manage it. And If you are willing you may try Android Studio as it is almost stable now [1.0 RC2]. It is very helpful for Cloud Apps as it have builtin support of GCM over Eclipce. Its just my opinion. Happy coding.
mohitsinghs said:
GCM HTTP: Downstream only: cloud-to-device.
GCM CCS: Upstream and downstream (device-to-cloud, cloud-to-device).
Thats why I suggested you CSS over HTTP. Note that Google AppEngine does not support connections to CCS so you need your own server implementation if you need both side communication.Otherwise you can try GCM HTTP with AppEngine.That all depends on your need and how you manage it. And If you are willing you may try Android Studio as it is almost stable now [1.0 RC2]. It is very helpful for Cloud Apps as it have builtin support of GCM over Eclipce. Its just my opinion. Happy coding.
Click to expand...
Click to collapse
Does CGM always run in the background? like a service?
sianzb0i said:
Does CGM always run in the background? like a service?
Click to expand...
Click to collapse
An Android application on an Android device doesn't need to be running to receive messages. The system will wake up the Android application via Intent broadcast when the message arrives, as long as the application is set up with the proper broadcast receiver and permissions .
Click to expand...
Click to collapse
Thats what written in developer docs. I hope you got it.
I was trying to do a simple poll to the server via this simple example as shared in the forum
http://forum.xda-developers.com/showthread.php?t=2325799
I want to automatically poll the results, say every 5 seconds. Similar to setInterval() in Javascript.
Code:
ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor(1);
final DoPOST mDoPOST = new DoPOST(MainActivity.this, /*editTextSearchString.getText().toString()*/"John");
exec.scheduleAtFixedRate(new Runnable() {
public void run() {
// code to execute repeatedly
mDoPOST.execute("");
}
}, 0, 5, TimeUnit.SECONDS); // execute every 60 seconds
This is what i added to my onCreate method but it only pulls the data for the first time and it doesnt pull anymore. Can someone please enlighten me?
Currently i am following this example to implement the CCS Push service
http://www.androidhive.info/2012/10...ing-google-cloud-messaging-gcm-php-and-mysql/
However, i couldnt get pass to the MainActivity without crashing the app
are there anymore noob friendly tutorial i can follow?
sianzb0i said:
Currently i am following this example to implement the CCS Push service
http://www.androidhive.info/2012/10...ing-google-cloud-messaging-gcm-php-and-mysql/
However, i couldnt get pass to the MainActivity without crashing the app
are there anymore noob friendly tutorial i can follow?
Click to expand...
Click to collapse
Log? Stacktrace? Run the app with your phone connected to the pc and usually Android Studio (hopefully your using it) will display any crash logs, from there we can help you find which lines your code is failing on.
Jonny said:
Log? Stacktrace? Run the app with your phone connected to the pc and usually Android Studio (hopefully your using it) will display any crash logs, from there we can help you find which lines your code is failing on.
Click to expand...
Click to collapse
Hi, i am still very very new to this.
Do you mean the logcat at the bottom?
i am still using the old eclipse juno bundle
I just rectified the crashing. But there are still some issues.
What I can do now:
1) I am able to register onto server
2) Server can see my device
What I cannot do:
1) I cannot contact the device from the server (nothing appears on the client)
2) on exit, the entry is still on the server. Its best to have a "exit" like how AirDroid does it (afterall I need user to confirm termination)
There only errors I get from LogCat is
Code:
12-30 22:49:27.536: E/GCMRegistrar(2614): internal error: retry receiver class not set yet
12-30 22:51:41.276: E/UnRegister Receiver Error(2614): > Receiver not registered: [email protected]
my android manifest is exactly the same as provided in the website (which should include a receiver, I suppose?), except I changed the corresponding package names

Categories

Resources