I want to execute the php file which copies the file to different folder from android . I am running the simple code to just execute the path which has the php file but it is giving and not getting executing
Php file when i execute is working but i want to execute from android. This is my java/android code which i have posted below
Compile.java
package com.coded.sandeep;
import java.net.URL;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
public class Compile extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Sending the php file path
String php_send="http://localhost/Android/App/copy.php?Coords=allahwariya.mp3";
// want to execute the above path using Http client but it is not working
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(php_send);
try
{
HttpResponse resp = client.execute(httpGet);
System.out.println(resp);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
And in my logcat there are no errors also at the same time php code is not being executed
LOGCAT
07-11 01:30:25.930: W/System.err(1359): android.os.NetworkOnMainThreadException
07-11 01:30:25.970: W/System.err(1359): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1145)
07-11 01:30:25.990: W/System.err(1359): at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
07-11 01:30:25.990: W/System.err(1359): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
07-11 01:30:26.000: W/System.err(1359): at java.net.InetAddress.getAllByName(InetAddress.java:214)
07-11 01:30:26.030: W/System.err(1359): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
07-11 01:30:26.040: W/System.err(1359): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
07-11 01:30:26.040: W/System.err(1359): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
07-11 01:30:26.050: W/System.err(1359): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
07-11 01:30:26.080: W/System.err(1359): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
07-11 01:30:26.090: W/System.err(1359): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
07-11 01:30:26.100: W/System.err(1359): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
07-11 01:30:26.110: W/System.err(1359): at com.prgguru.example.AsyncTaskExample.onCreate(AsyncTaskExample.java:73)
07-11 01:30:26.130: W/System.err(1359): at android.app.Activity.performCreate(Activity.java:5231)
07-11 01:30:26.140: W/System.err(1359): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-11 01:30:26.150: W/System.err(1359): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
07-11 01:30:26.160: W/System.err(1359): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
07-11 01:30:26.180: W/System.err(1359): at android.app.ActivityThread.access$800(ActivityThread.java:135)
07-11 01:30:26.190: W/System.err(1359): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
07-11 01:30:26.200: W/System.err(1359): at android.os.Handler.dispatchMessage(Handler.java:102)
07-11 01:30:26.200: W/System.err(1359): at android.os.Looper.loop(Looper.java:136)
07-11 01:30:26.220: W/System.err(1359): at android.app.ActivityThread.main(ActivityThread.java:5017)
07-11 01:30:26.230: W/System.err(1359): at java.lang.reflect.Method.invokeNative(Native Method)
07-11 01:30:26.230: W/System.err(1359): at java.lang.reflect.Method.invoke(Method.java:515)
07-11 01:30:26.250: W/System.err(1359): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-11 01:30:26.260: W/System.err(1359): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-11 01:30:26.270: W/System.err(1359): at dalvik.system.NativeStart.main(Native Method)
07-11 01:30:27.060: D/dalvikvm(1359): GC_FOR_ALLOC freed 246K, 10% free 3032K/3360K, paused 60ms, total 70ms
07-11 01:30:27.240: D/gralloc_goldfish(1359): Emulator without GPU emulation detected.
can anyone pls tell me how to execute the php file from java