The problem that I am having is that the apk i made is working on Samsung galaxyS1 and SE XperiaPlay but not working on Samsung Galaxy S4. Mainly on the login screen when the user presses the button it should move the user to next screen if the details are correct or display an alert box. The button can be pressed but it doesn't trigger any actions, like a dummy button if you will. I have no idea what to do with that.
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.miniproject"
android:versionCode="8"
android:versionName="1.6" >
<compatible-screens>
<screen
android:screenDensity="480"
android:screenSize="normal" />
</compatible-screens>
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:icon="@drawable/domo"
android:allowBackup="true"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:label="@string/app_name"
android:name=".splashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.miniproject.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:label="@string/app_name"
android:name=".tableScreen">
</activity>
</application>
</manifest>
MainActivity.java
package com.example.miniproject;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener {
Button submit;
EditText username;
EditText password;
HttpPost httppost;
HttpResponse response;
HttpClient httpclient;
List<NameValuePair> nameValuePairs;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
username =(EditText) findViewById(R.id.editTextUsername);
password = (EditText) findViewById(R.id.editTextPassword);
submit = (Button) findViewById(R.id.buttonSubmit);
submit.setOnClickListener(this);
}
public void toast()
{
Context context = getApplicationContext();
CharSequence text = "Table loading...";
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
public void onClick(View v)
{
if(v.getId() == submit.getId())
{
login();
}
}
private void login()
{
try{
httpclient=new DefaultHttpClient();
httppost= new HttpPost("http://www.daydreamsoftware.com/connect.php");
nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("username",username.getText().toString().trim()));
nameValuePairs.add(new BasicNameValuePair("password",password.getText().toString().trim()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response=httpclient.execute(httppost);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
final String response = httpclient.execute(httppost, responseHandler);
//connect.php response User Found = true; No Such User Found = false
if(response.equalsIgnoreCase("User Found"))
{
toast();
startActivity(new Intent(MainActivity.this, tableScreen.class));
}
else
{
AlertDialog.Builder alertBox = new AlertDialog.Builder(this);
alertBox.setMessage("Wrong username or password");
alertBox.show();
}
}catch(Exception e)
{
e.printStackTrace();
}
}//end:login()
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="@drawable/sand"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<EditText
android:id="@+id/editTextUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/editTextPassword"
android:layout_alignLeft="@+id/editTextPassword"
android:layout_marginBottom="34dp"
android:ems="10" />
<EditText
android:id="@+id/editTextPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:ems="10"
android:inputType="textPassword" />
<Button
android:id="@+id/buttonSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editTextPassword"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:text="@string/stringLogIn" />
</RelativeLayout>
I have created a AVD for S4 using this s4AVD it has the same problem as the phone. I am attaching the logCat that appears after the button is clicked:
11-17 22:57:45.851: W/System.err(832): android.os.NetworkOnMainThreadException
11-17 22:57:45.851: W/System.err(832): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
11-17 22:57:45.851: W/System.err(832): at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
11-17 22:57:45.851: W/System.err(832): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
11-17 22:57:45.851: W/System.err(832): at java.net.InetAddress.getAllByName(InetAddress.java:214)
11-17 22:57:45.861: W/System.err(832): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
11-17 22:57:45.871: W/System.err(832): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
11-17 22:57:45.871: W/System.err(832): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
11-17 22:57:45.871: W/System.err(832): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
11-17 22:57:45.871: W/System.err(832): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
11-17 22:57:45.871: W/System.err(832): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
11-17 22:57:45.871: W/System.err(832): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
11-17 22:57:45.891: W/System.err(832): at com.example.miniproject.MainActivity.login(MainActivity.java:76)
11-17 22:57:45.891: W/System.err(832): at com.example.miniproject.MainActivity.onClick(MainActivity.java:60)
11-17 22:57:45.891: W/System.err(832): at android.view.View.performClick(View.java:4084)
11-17 22:57:45.902: W/System.err(832): at android.view.View$PerformClick.run(View.java:16966)
11-17 22:57:45.902: W/System.err(832): at android.os.Handler.handleCallback(Handler.java:615)
11-17 22:57:45.902: W/System.err(832): at android.os.Handler.dispatchMessage(Handler.java:92)
11-17 22:57:45.912: W/System.err(832): at android.os.Looper.loop(Looper.java:137)
11-17 22:57:45.922: W/System.err(832): at android.app.ActivityThread.main(ActivityThread.java:4745)
11-17 22:57:45.922: W/System.err(832): at java.lang.reflect.Method.invokeNative(Native Method)
11-17 22:57:45.931: W/System.err(832): at java.lang.reflect.Method.invoke(Method.java:511)
11-17 22:57:45.931: W/System.err(832): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-17 22:57:45.931: W/System.err(832): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-17 22:57:45.941: W/System.err(832): at dalvik.system.NativeStart.main(Native Method)