|
|
|
Android - Force Close เมื่อใช้คำสั่ง response = client.execute(httpPost); |
|
|
|
|
|
|
|
***ผมได้ขอ persmissionไว้แล้วนะครับ
<uses-permission android:name="android.permission.ACCESS_SUPERUSER" />
<uses-permission android:name="android.permission.INTERNET" />
Class เจ้าปัญหา
Code (Android-Java)
public class MainActivity extends Activity {
TextView DisplayDetail;
TextView Conserv;
String model,board,device,brand,manufacturer,builddes,buildfing;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DisplayDetail=(TextView)findViewById(R.id.displaydetail);
getDeviceInfo();
DisplayDetail.setText(getDeviceInfoAsText());
Conserv = (TextView)findViewById(R.id.conserv);
Conserv.setText(commitDevice());
}
private void getDeviceInfo(){
model=BuildProp.getProp("ro.product.model");
board=BuildProp.getProp("ro.product.board");
device=BuildProp.getProp("ro.product.device");
brand=BuildProp.getProp("ro.product.brand");
manufacturer=BuildProp.getProp("ro.product.manufacturer");
builddes=BuildProp.getProp("ro.build.description");
buildfing=BuildProp.getProp("ro.build.fingerprint");
}
private String getDeviceInfoAsText() {
// TODO Auto-generated method stub
String info = "";
info+="Model : "+model+"\n";
info+="Board : "+board+"\n";
info+="Device : "+device+"\n";
info+="Brand : "+brand+"\n";
info+="Manufacturer : "+manufacturer+"\n";
info+="Build Description : "+builddes+"\n";
info+="Build Fingerprint : "+buildfing+"\n";
return info;
}
public String commitDevice()
{
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("Model",model));
params.add(new BasicNameValuePair("Board",board));
params.add(new BasicNameValuePair("Device",device));
params.add(new BasicNameValuePair("Brand",brand));
params.add(new BasicNameValuePair("Manufacturer",manufacturer));
params.add(new BasicNameValuePair("BuildDescription",builddes));
params.add(new BasicNameValuePair("BuildFingerprint",buildfing));
return getHttpPost("http://exam-engine.urll.us/unknow_device/insert.php",params);
}
public String getHttpPost(String url,List<NameValuePair> params) {
StringBuilder str = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
try {
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse response = client.execute(httpPost); //เจ้าตัวปัญหา
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) { // Status OK
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null) {
str.append(line);
}
} else {
Log.e("Log", "Failed to download result..");
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return str.toString();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
LogCat
D/AndroidRuntime( 6770): >>>>>> AndroidRuntime START com.android.internal.os.Run
timeInit <<<<<<
D/AndroidRuntime( 6770): CheckJNI is OFF
D/dalvikvm( 6770): Trying to load lib libjavacore.so 0x0
D/dalvikvm( 6770): Added shared lib libjavacore.so 0x0
D/AndroidRuntime( 6690): Shutting down VM
D/dalvikvm( 6690): GC_CONCURRENT freed 97K, 17% free 516K/616K, paused 0ms+0ms,
total 2ms
D/jdwp ( 6690): Got wake-up signal, bailing out of select
D/dalvikvm( 6690): Debugger has detached; object registry had 1 entries
D/dalvikvm( 6770): Trying to load lib libnativehelper.so 0x0
D/dalvikvm( 6770): Added shared lib libnativehelper.so 0x0
D/su ( 6846): su invoked.
D/su ( 6850): db allowed
D/su ( 6852): 10091 org.pureexe.unknowdevice executing 0 /system/bin/sh usi
ng binary /system/bin/sh : sh
I/RootTools v3.1( 6113): [ro, relatime, data=ordered] AND ro
D/AndroidRuntime( 6113): Shutting down VM
W/dalvikvm( 6113): threadid=1: thread exiting with uncaught exception (group=0x4
0c09930)
E/AndroidRuntime( 6113): FATAL EXCEPTION: main
E/AndroidRuntime( 6113): java.lang.RuntimeException: Unable to start activity Co
mponentInfo{org.pureexe.unknowdevice/org.pureexe.unknowdevice.MainActivity}: and
roid.os.NetworkOnMainThreadException
E/AndroidRuntime( 6113): at android.app.ActivityThread.performLaunchActiv
ity(ActivityThread.java:2308)
E/AndroidRuntime( 6113): at android.app.ActivityThread.handleLaunchActivi
ty(ActivityThread.java:2358)
E/AndroidRuntime( 6113): at android.app.ActivityThread.access$600(Activit
yThread.java:153)
E/AndroidRuntime( 6113): at android.app.ActivityThread$H.handleMessage(Ac
tivityThread.java:1247)
E/AndroidRuntime( 6113): at android.os.Handler.dispatchMessage(Handler.ja
va:99)
E/AndroidRuntime( 6113): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 6113): at android.app.ActivityThread.main(ActivityThrea
d.java:5227)
E/AndroidRuntime( 6113): at java.lang.reflect.Method.invokeNative(Native
Method)
E/AndroidRuntime( 6113): at java.lang.reflect.Method.invoke(Method.java:5
11)
E/AndroidRuntime( 6113): at com.android.internal.os.ZygoteInit$MethodAndA
rgsCaller.run(ZygoteInit.java:795)
E/AndroidRuntime( 6113): at com.android.internal.os.ZygoteInit.main(Zygot
eInit.java:562)
E/AndroidRuntime( 6113): at de.robv.android.xposed.XposedBridge.main(Xpos
edBridge.java:110)
E/AndroidRuntime( 6113): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 6113): Caused by: android.os.NetworkOnMainThreadException
E/AndroidRuntime( 6113): at android.os.StrictMode$AndroidBlockGuardPolicy
.onNetwork(StrictMode.java:1117)
E/AndroidRuntime( 6113): at java.net.InetAddress.lookupHostByName(InetAdd
ress.java:385)
E/AndroidRuntime( 6113): at java.net.InetAddress.getAllByNameImpl(InetAdd
ress.java:236)
E/AndroidRuntime( 6113): at java.net.InetAddress.getAllByName(InetAddress
.java:214)
E/AndroidRuntime( 6113): at org.apache.http.impl.conn.DefaultClientConnec
tionOperator.openConnection(DefaultClientConnectionOperator.java:137)
E/AndroidRuntime( 6113): at org.apache.http.impl.conn.AbstractPoolEntry.o
pen(AbstractPoolEntry.java:164)
E/AndroidRuntime( 6113): at org.apache.http.impl.conn.AbstractPooledConnA
dapter.open(AbstractPooledConnAdapter.java:119)
E/AndroidRuntime( 6113): at org.apache.http.impl.client.DefaultRequestDir
ector.execute(DefaultRequestDirector.java:360)
E/AndroidRuntime( 6113): at org.apache.http.impl.client.AbstractHttpClien
t.execute(AbstractHttpClient.java:555)
E/AndroidRuntime( 6113): at org.apache.http.impl.client.AbstractHttpClien
t.execute(AbstractHttpClient.java:487)
E/AndroidRuntime( 6113): at org.apache.http.impl.client.AbstractHttpClien
t.execute(AbstractHttpClient.java:465)
E/AndroidRuntime( 6113): at org.pureexe.unknowdevice.MainActivity.getHttp
Post(MainActivity.java:92)
E/AndroidRuntime( 6113): at org.pureexe.unknowdevice.MainActivity.commitD
evice(MainActivity.java:82)
E/AndroidRuntime( 6113): at org.pureexe.unknowdevice.MainActivity.onCreat
e(MainActivity.java:44)
E/AndroidRuntime( 6113): at android.app.Activity.performCreate(Activity.j
ava:5104)
E/AndroidRuntime( 6113): at android.app.Instrumentation.callActivityOnCre
ate(Instrumentation.java:1080)
E/AndroidRuntime( 6113): at android.app.ActivityThread.performLaunchActiv
ity(ActivityThread.java:2262)
E/AndroidRuntime( 6113): ... 12 more
W/ActivityManager( 596): Force finishing activity org.pureexe.unknowdevice/.M
ainActivity
D/Xposed ( 6851): Starting Xposed binary version 34, compiled for SDK 17
D/Xposed ( 6851): Phone: Nexus 4 (LGE), Android version 4.2.2 (SDK 17)
D/Xposed ( 6851): ROM: cm_mako-userdebug 4.2.2 JDQ39E eng.jenkins.20130802.0313
05 test-keys
Tag : Mobile, Android, Mobile
|
ประวัติการแก้ไข 2013-08-03 16:18:21
|
|
|
|
|
Date :
2013-08-03 16:12:02 |
By :
pureexe |
View :
1354 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองดู
Code (Android-Java)
// Permission StrictMode
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
Android HttpGet and HttpPost
|
|
|
|
|
Date :
2013-08-05 06:16:42 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณครับ ใช้ได้ครับ ^^
|
|
|
|
|
Date :
2013-08-17 14:49:26 |
By :
pureexe |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|