Friday, May 22, 2009
Well, that was easy.
So I created a new Google AppEngine project in Python: a very simple one, which just takes a particular HTTP POST request, stores its values to the datastore, and displays them on-screen. Then I added a "upload" function to my Android's DbHelper class, and connected the latter to the former.
I expected the debugging to be messy and lengthy. But whaddaya know? All I had to do was add the INTERNET permission to my AndroidManifest.xml, and correct the URL that I was pointing to (I'm running the AppEngine app locally; the Android emulator has a special IP address, 10.0.2.2, to connect to its host machine) and poof, amazingly, It Just Worked.
Here's the Android code, in case anyone needs an example:
I'm not even going to bother posting the server code, as it's so simple; 70 lines of Python, and 30 lines of HTML.
You'll note at the moment I just upload a picture URL, rather than actual data, but I'm going to move to doing the latter eventually.
I expected the debugging to be messy and lengthy. But whaddaya know? All I had to do was add the INTERNET permission to my AndroidManifest.xml, and correct the URL that I was pointing to (I'm running the AppEngine app locally; the Android emulator has a special IP address, 10.0.2.2, to connect to its host machine) and poof, amazingly, It Just Worked.
Here's the Android code, in case anyone needs an example:
public boolean uploadNote(long rowId, String location, String title, String comments, String picturePath) {
try {
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter("http.useragent", Util.AppName);
HttpPost httpost = new HttpPost(Util.wtwSite); // temporarily 10.0.2.2:8080/sendUpdate
Log.i(""+this, "Preparing to post to "+Util.wtwSite);
ListparamList = new LinkedList ();
paramList.add(new BasicNameValuePair("email", Util.GetUserEmail()));
paramList.add(new BasicNameValuePair("title", title));
paramList.add(new BasicNameValuePair("location", location));
paramList.add(new BasicNameValuePair("comments", comments));
paramList.add(new BasicNameValuePair("image", picturePath));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList,
HTTP.DEFAULT_CONTENT_CHARSET);
httpost.setEntity(entity);
HttpResponse response = httpclient.execute(httpost);
Log.i(""+this, "Sent POST, got " + response.getStatusLine());
entity.consumeContent();
markUploaded(rowId);
return true;
}
catch (IOException ex)
{
Log.e(""+this, "Could not upload note with row "+rowId+ " due to "+ex, ex);
return false;
}
}
I'm not even going to bother posting the server code, as it's so simple; 70 lines of Python, and 30 lines of HTML.
You'll note at the moment I just upload a picture URL, rather than actual data, but I'm going to move to doing the latter eventually.
Labels: Android, AndroidManifest, AppEngine, Java, python, upload
Comments:
<< Home
There is a lot to tell you, for example, that there is a essayshark scam that do any writing and homework that can also be ordered, but overall very good, then you found me because this is good advice for an assistant
here is a lot to tell you, for example, that there is a Webdesigners LLC that do any thinks abots to make best web designs in All over Us, Florida.
I am glad to see nice post. It is very informative and valuable post. Your insights are truly inspired. Thanks for sharing. Prince William Traffic Lawyer
When facing financial challenges, locate bankruptcy lawyers near you for expert guidance. They provide legal assistance, assess your situation, and help navigate the complex process of filing for bankruptcy.
Bankrupsy lawyers near me
Bankrupsy lawyers near me
traffic lawyer loudoun va
For expert assistance with traffic violations in Loudoun, VA, search for skilled traffic lawyers nearby. Utilize online platforms or legal directories to find attorneys with experience in Loudoun County traffic cases. Consider reviews, ratings, and recommendations to gauge their effectiveness. Local bar associations and legal aid organizations can also provide valuable information. By seeking a qualified traffic lawyer in Loudoun, VA, you ensure competent representation to navigate the legal intricacies of your case and potentially mitigate the consequences associated with the traffic offense.
For expert assistance with traffic violations in Loudoun, VA, search for skilled traffic lawyers nearby. Utilize online platforms or legal directories to find attorneys with experience in Loudoun County traffic cases. Consider reviews, ratings, and recommendations to gauge their effectiveness. Local bar associations and legal aid organizations can also provide valuable information. By seeking a qualified traffic lawyer in Loudoun, VA, you ensure competent representation to navigate the legal intricacies of your case and potentially mitigate the consequences associated with the traffic offense.
It’s an interesting article..!! Thanks for sharing. Looks Useful. Keep Posting Top Divorce Lawyers in New York
New York State Divorce Process File in Supreme Court (county you live in). Agree on everything (uncontested) or disagree (contested). Serve papers, wait (no set timeframe), finalize settlement.
Request clarification on "Rezendi" to understand its reference to person, place, or other topic. I'm happy to assist and can provide more information if needed Domestic Violence Central Registry New Jersey.
The legal difficulties of dissolving a marriage, such as property division, child custody, and other important legal issues, are handled by divorce attorneys. They try to reach just settlements between spouses or, if needed, defend your rights in court. Having an experienced attorney at your side may be quite beneficial, especially considering the emotional and legal difficulties that come with divorce. Additionally, a divorce attorney can provide knowledgeable legal advice specific to your case if you're looking for Bankruptcy Chapter 7 Lawyers Near Me . Get in touch with us now to find out more.
In hostile cases, prosecution is many times undeniable, however in others, maryland sole custody intercession may be a superior decision to keep away from delayed struggle.
It’s refreshing when the trickiest part ends up being just an AndroidManifest permission and the 10.0.2.2 detail. Using App Engine as a lightweight endpoint for POSTs is a great pattern for quick prototypes or logging. Would love to see how you handle retries/backoff and offline queueing from the DbHelper—especially if the network drops. Also curious if you considered HTTPS locally with a self-signed cert. Reminds me of wiring up a simple Cookie Clicker stats sync.
That's awesome when things just click like that! It’s always a relief when a potentially tricky setup turns out to be straightforward. I've had similar experiences where a simple permission or URL fix makes all the difference. Reminds me of the unexpected rush when you're playing Agario, and you manage to split-kill a much bigger player against all odds! Such a satisfying feeling.
Wow, "It Just Worked" – that's a phrase developers only dream of hearing! Seriously though, that 10.0.2.2 emulator trick has saved me so many headaches. It's like finding a secret passage in a horror games when you're almost out of health. I remember trying to connect my own app to a local server once, pulling my hair out for hours before stumbling upon that IP. Glad your process was so smooth!
Dude, this is awesome! Seriously, the satisfaction of getting a tricky dev setup to just work without a massive headache is peak. I remember trying to get a local API talking to an emulator once, and the repo was just a tangled mess of permissions and wrong IPs. Getting everything aligned and then poof, it just works? That's the dream right there. What's the next big feature you're thinking of adding to this bad boy?
Subscribe to Post Comments [Atom]
<< Home
Subscribe to Posts [Atom]


Post a Comment