|
How to send data from android app to a php page?
|
|
|
|
|
Wouldn't it be by using either an HTTP POST or GET command?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
It is very important for a mobile application too talk to web based applications. There are various scenarios where we need to fetch data from web pages .
The code below will enable your android app to talk to a webpage.
Note : You also need to enable uses permission for internet in the android.manifest file.
<uses-permission
android:name="android.permission.INTERNET" />
Code for android app
public void postData(String toPost) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.URL.com/yourpage.php");
String MyName = 'adil';
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("action", MyName));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = httpclient.execute(httppost, responseHandler);
String reverseString = response;
Toast.makeText(this, "response" + reverseString, Toast.LENGTH_LONG).show();
} catch (ClientProtocolException e) {
Toast.makeText(this, "CPE response " + e.toString(), Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(this, "IOE response " + e.toString(), Toast.LENGTH_LONG).show();
}
}
php code
<?php
$reversed = strrev($_POST["action"]);
echo $reversed;
?>
modified 29-Dec-18 2:08am.
|
|
|
|
|
Android – sending and receiving data from a php page
29
JAN
It is very important for a mobile application to talk to web based applications. There are various scenarios where we need to fetch data from web pages .
The code below will enable your android app to talk to a webpage.
Note : You also need to enable uses permission for internet in the android.manifest file.
<uses-permission
android:name="android.permission.INTERNET" />
Code for android app
public void postData(String toPost) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.URL.com/yourpage.php");
String MyName = 'adil';
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("action", MyName));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = httpclient.execute(httppost, responseHandler);
String reverseString = response;
Toast.makeText(this, "response" + reverseString, Toast.LENGTH_LONG).show();
} catch (ClientProtocolException e) {
Toast.makeText(this, "CPE response " + e.toString(), Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(this, "IOE response " + e.toString(), Toast.LENGTH_LONG).show();
}
}
php code
<?php
$reversed = strrev($_POST["action"]);
echo $reversed;
?>
|
|
|
|
|
I'm working on an Android app that we only want to allow to run if the user has VPN'd into the network.
The question is, how do I determine if the user has VPN'd in?
I have tried the following:
var address = Dns.GetHostAddresses("www.mycompany.com").FirstOrDefault();
var hostName = Dns.GetHostName();
var domainName = System.Environment.UserDomainName;
UserDialogs.Instance.Alert(domainName, "Domain Name", "OK");
UserDialogs.Instance.Alert(hostName, "Host Name", "OK");
UserDialogs.Instance.Alert(address.ToString(), "Address", "OK");
The results are always the same, even if I'm NOT VPN'd in.
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
|
So what are you saying, that there's no way to determine if I'm VPN'd in?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I don't know for sure, but none of the properties you referred to will tell you. They are all related to the real network that you finally connect to. Information about the VPN would be external to them. Probably more important to explain what problem you are actually trying to solve.
|
|
|
|
|
Richard MacCutchan wrote: Probably more important to explain what problem you are actually trying to solve.
I did in my post
"I'm working on an Android app that we only want to allow to run if the user has VPN'd into the network."
The app generates a daily barcode for logging into an instrument we have. We only want internal users to run the app.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Just to clarify, this is for Android devices connected to your internal network via VPN, and not WiFi?
Are you using a VPN app on the Android device?
Could the barcode that the Android device is generating be uploaded to a secure web site? I'm not trying to change your mind, rather just trying to see if there are any other ways to skin that cat.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
David Crow wrote: Just to clarify, this is for Android devices connected to your internal network via VPN, and not WiFi?
Are you using a VPN app on the Android device
That's correct
David Crow wrote: Could the barcode that the Android device is generating be uploaded to a secure web site? I'm not trying to change your mind, rather just trying to see if there are any other ways to skin that cat
Not an option
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Would you be able to detect if the VPN app itself was up & running? I don't use VPN for anything so I don't know if they're considered "up & running" if no one is logged in to it. In other words, you may get a false positive.
Would you be able to create a web site (it doesn't need to do anything other than exist) that is only available from your internal network (i.e., from inside your firewall)?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Yes, that I could do
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
In your Android code, try to connect to that site's IP address. If the site truly is not visible to the outside world, and your app can connect to it while using VPN, then you're one step closer to a solution.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Good idea. I'll give that a try.
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Cat skinned or possibly drowned in milk.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Kevin Marois wrote: We only want internal users to run the app. Internal users are any users that are on your company network. Whether they come in via VPN or direct they are seen as the same at the network level. The only suggestion I can find about this is comparing the IP address before and after connection; but it sounds as if that is unlikely to be possible in your case.
|
|
|
|
|
This may be one of those issues where the OSI model comes in to play. Depending on which layer your VPN is operating under, you may not be able to acquire such information.
What exactly are you trying to keep from happening?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
David Crow wrote: What exactly are you trying to keep from happening?
See my reply to Richard
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I have an ExpandableListView is using an adapter that inherits from the BaseExpandableListAdapter base class. On the childview I have a button, in this case with an id of HelloWorld.
When I click on the HelloWorld button and the Click event is fired, the Click event is also fired for other HelloWorld buttons not on this childview, the Toast is displaying more than one group when I expect only one to be displayed.
What I am expecting is for only one Click event to be fired and that event to be associated with the button I click on the childview the button is on.
So there is obviously something I am not understanding here.
I have spent an hour googling but cannot find anything that points to what I am getting wrong.
Any pointers or help much appreciated
public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent)
{
if (convertView == null)
{
convertView = _context.LayoutInflater.Inflate(Resource.Layout.ListItemCustomLayout, null);
}
var button = (Button)convertView.FindViewById(Resource.Id.HelloWorld);
button.SetFocusable(ViewFocusability.NotFocusable);
button.Click += (sender, e) =>
{
var groupName = ((Models.Timer)(((JavaObjectWrapper<Models.Timer>)GetChild(groupPosition, childPosition)).Obj)).GroupName;
Toast.MakeText(_context, groupName, ToastLength.Long).Show();
};
return convertView;
}
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
I found some RoundCube apps on Google Play Store.
If anyone has personal experience (good or bad are equally valuable) with any such app on your own Android, please share it with me.
Thank you
|
|
|
|
|
This, and your other question below, would be more appropriate in the Lounge. They have nothing to do with programming.
|
|
|
|
|
Just found some cPanel apps on google play store.
Ratings go from two stars up to four stars.
Four stars costs five bucks, I think.
Anybody got this on their Android ?
Tell me good. Tell me Bad.
|
|
|
|
|
hi friends
problem with volley in android studio
///*********************************
public void getPerson(final OnPersonRecived onPersonRecived) {
String url = "http://192.168.1.105:8080/serveydevice/getperson.php";
// String url="http://api.openweathermap.org/data/2.5/weather?q=London&apikey=e44e3fad935f5d47c7f99d2511478fe3";
JsonArrayRequest request = new JsonArrayRequest(url, new Response.Listener() {
@Override
public void onResponse(JSONArray response) {
Log.i(TAG, "onResponse: " + response.toString());
List persons = new ArrayList<>();
for (int i = 0; i persons);
}
/****************************
after running this show belew message:
request={jsonarrayrequest@831721332616} "[ ] http://192.168.1.105:8080/serveydevice/getperson.php" 0x85bc0dda NORMAL null
///**************
url is correct
please help me
|
|
|
|
|
wrote: please help me With what? All you've shown is code (which has not been tagged correctly so makes it appear pieces are missing), but have said nothing about what is happening, what is supposed to happen, any exceptions that are being thrown, whether you've used the debugger and what it showed, etc.
To borrow a phrase, help us to help you.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|