1

Is there any method to get data from an Android app to a website?

If it is from website to website, with "file_get_contents" it is possible. But then any idea on getting data from Android apps?

Thanks in advance!

V-T
  • 756
  • 2
  • 9
  • 22

2 Answers2

1

Using this simple php script you can get data from android:

<?php

$filename="datatest.html";
file_put_contents($filename,$_POST["fname"]."<br />",FILE_APPEND);
file_put_contents($filename,$_POST["fphone"]."<br />",FILE_APPEND);
file_put_contents($filename,$_POST["femail"]."<br />",FILE_APPEND);
file_put_contents($filename,$_POST["fcomment"]."<br />",FILE_APPEND);
$msg=file_get_contents($filename);
echo $msg; ?>

In android can use HttpPost to accomplish this by something like this:

HttpClient httpclient = new DefaultHttpClient();
   HttpPost httppost = new HttpPost("http://example.com/mypage.php");
     try {
   List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);

   nameValuePairs.add(new BasicNameValuePair("fname", "jake"));
   nameValuePairs.add(new BasicNameValuePair("fphone", "9999999"));
   nameValuePairs.add(new BasicNameValuePair("femail", "xyz@live.com"));
   nameValuePairs.add(new BasicNameValuePair("fcomment", "Help"));
   httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
   httpclient.execute(httppost);

 } catch (ClientProtocolException e) {
     // TODO Auto-generated catch block
 } catch (IOException e) {
     // TODO Auto-generated catch block
 }

Replace your data with the fields you want to set and send in the constructor of BasicNameValuePair.

Here is the actual Source

Community
  • 1
  • 1
Sharp Edge
  • 4,144
  • 2
  • 27
  • 41
  • what do you mean you may not have access to the source code of app ? you want to make a website which gets data from android system ? – Sharp Edge Aug 05 '15 at 08:23
  • Partially yes, getting or knowing latest news from the app. – V-T Aug 05 '15 at 08:29
0

You could execute post requests in android to your website. Although this has to executed from a different thread, since android doesn't allow network operations on the main thread.

Community
  • 1
  • 1
Meneer Venus
  • 1,039
  • 2
  • 12
  • 28
  • here android app in the sense, any android app. I may not have access to the source code of that app. Like I said, inside "file_get_contents" I can give any web address. Same way, any general method? – V-T Aug 05 '15 at 08:08