Samsung S5300 (Android OS 2.3.3) では動作するがタブレット (Prestigio Multipad 2 Ultra Duo 8.0 3G) では動作しない、作成中のアプリに問題があります。実行中です(Android OS 4.1)
アプリは、タイムスタンプや ADC 値などの情報を IOIO ボードから取得し、サーバーに投稿します。これは、サムスンの携帯電話でうまく機能します。タブレットではデータの送信部分に爆撃。
これが爆撃する私のコードスニペットです:
public void postData()
{
String urlS = "https://posttestserver.com/post.php?dump&html&dir=oan";
//String urlS = "https://placidblue.no-ip.biz/cgi-bin/data_input.py";
//String urlS = "http://placidblue.no-ip.biz/cgi-bin/data_input.py";
HttpClient httpclient = new DefaultHttpClient(); // Create a new HttpClient and Post Header
HttpPost httppost = new HttpPost(urlS);
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("LAT", TransferLat));
nameValuePairs.add(new BasicNameValuePair("LON", TransferLon));
nameValuePairs.add(new BasicNameValuePair("TIM", TransferTim));
nameValuePairs.add(new BasicNameValuePair("POL", TransferPol));
nameValuePairs.add(new BasicNameValuePair("CON", TransferCon));
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
} catch (UnsupportedEncodingException e) {
Log.d("General","UnsupportedEncodingException.xxx");
e.printStackTrace();// writing error to Log
}
Log.d("General Log","Sending_data.xxx");
HttpResponse response = httpclient.execute(httppost); // Execute HTTP Post Request
Log.d("HttpResponse:", response.toString()+"xxx"); // writing response to log
Log.d("General","Data_send_complete.xxx");
}catch (IllegalStateException e) {
Log.d("General","Illegal_State1.xxx");
e.printStackTrace();
Log.d("General","Illegal_State2.xxx");
}
catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
// writing error to Log
e.printStackTrace();
}
}//end postData
私が得るログキャットエラーは次のとおりです:
08-13 19:02:50.797: D/General Log(6672): Sending_data.xxx
08-13 19:02:50.816: D/AndroidRuntime(6672): Shutting down VM
08-13 19:02:50.816: W/dalvikvm(6672): threadid=1: thread exiting with uncaught exception (group=0x40dce908)
08-13 19:02:50.824: E/AndroidRuntime(6672): FATAL EXCEPTION: main
08-13 19:02:50.824: E/AndroidRuntime(6672): java.lang.IllegalStateException: Could not execute method of the activity
08-13 19:02:50.824: E/AndroidRuntime(6672): at android.view.View$1.onClick(View.java:3598)
08-13 19:02:50.824: E/AndroidRuntime(6672): at android.view.View.performClick(View.java:4091)
08-13 19:02:50.824: E/AndroidRuntime(6672): at android.view.View$PerformClick.run(View.java:17072)
08-13 19:02:50.824: E/AndroidRuntime(6672): at android.os.Handler.handleCallback(Handler.java:615)
08-13 19:02:50.824: E/AndroidRuntime(6672): at android.os.Handler.dispatchMessage(Handler.java:92)
08-13 19:02:50.824: E/AndroidRuntime(6672): at android.os.Looper.loop(Looper.java:153)
08-13 19:02:50.824: E/AndroidRuntime(6672): at android.app.ActivityThread.main(ActivityThread.java:4987)
08-13 19:02:50.824: E/AndroidRuntime(6672): at java.lang.reflect.Method.invokeNative(Native Method)
08-13 19:02:50.824: E/AndroidRuntime(6672): at java.lang.reflect.Method.invoke(Method.java:511)
08-13 19:02:50.824: E/AndroidRuntime(6672): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
08-13 19:02:50.824: E/AndroidRuntime(6672): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
08-13 19:02:50.824: E/AndroidRuntime(6672): at dalvik.system.NativeStart.main(Native Method)
08-13 19:02:50.824: E/AndroidRuntime(6672): Caused by: java.lang.reflect.InvocationTargetException
08-13 19:02:50.824: E/AndroidRuntime(6672): at java.lang.reflect.Method.invokeNative(Native Method)
08-13 19:02:50.824: E/AndroidRuntime(6672): at java.lang.reflect.Method.invoke(Method.java:511)
08-13 19:02:50.824: E/AndroidRuntime(6672): at android.view.View$1.onClick(View.java:3593)
08-13 19:02:50.824: E/AndroidRuntime(6672): ... 11 more
08-13 19:02:50.824: E/AndroidRuntime(6672): Caused by: android.os.NetworkOnMainThreadException
08-13 19:02:50.824: E/AndroidRuntime(6672): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1125)
08-13 19:02:50.824: E/AndroidRuntime(6672): at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
08-13 19:02:50.824: E/AndroidRuntime(6672): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
08-13 19:02:50.824: E/AndroidRuntime(6672): at java.net.InetAddress.getAllByName(InetAddress.java:214)
08-13 19:02:50.824: E/AndroidRuntime(6672): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
08-13 19:02:50.824: E/AndroidRuntime(6672): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
08-13 19:02:50.824: E/AndroidRuntime(6672): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
08-13 19:02:50.824: E/AndroidRuntime(6672): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:365)
08-13 19:02:50.824: E/AndroidRuntime(6672): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
08-13 19:02:50.824: E/AndroidRuntime(6672): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
08-13 19:02:50.824: E/AndroidRuntime(6672): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
08-13 19:02:50.824: E/AndroidRuntime(6672): at com.example.airsensor1.MainActivity.postData(MainActivity.java:194)
08-13 19:02:50.824: E/AndroidRuntime(6672): at com.example.airsensor1.MainActivity.sendData(MainActivity.java:158)
08-13 19:02:50.824: E/AndroidRuntime(6672): ... 14 more
新しいOSのアクセス許可に関するセキュリティ上の問題でさえあるのではないかと思いますか? マニフェストに適切なインターネット アクセス許可を設定しました。
アドバイスをいただければ幸いです。よろしく