public class WiFiLibrary {
public Socket client = null;
public FileInputStream fileInputStream = null;
public BufferedInputStream bufferedInputStream = null;
public OutputStream outputStream = null;
public void Connect()
{
try
{
client = new Socket("169.254.84.140",9999);
}
catch (IOException e)
{
e.printStackTrace();
}
}
public void SendFile()
{
try
{
File file = new File("/sdcard/TEST/TEST.xml");
byte[] mybytearray = new byte[(int) file.length()];
fileInputStream = new FileInputStream(file);
bufferedInputStream = new BufferedInputStream(fileInputStream);
/**reads the file */
bufferedInputStream.read(mybytearray, 0, mybytearray.length);
outputStream = client.getOutputStream();
/** writes file to the output stream byte by byte */
outputStream.write(mybytearray, 0, mybytearray.length);
outputStream.flush();
bufferedInputStream.close();
outputStream.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
public void Disconnect()
{
try
{
client.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Here is my client class code for android. But when i said connect it crashes and closes. I add permissions my Manifest (There is no problem on the manifest). I used some part of code s in the past with a different tablet. But I try it Nexus 7 and it just crashed.
Here is my manifest permissions also:
android:minSdkVersion="16"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
Could anyone an idea what is the problem about my nexus 7 ?? I opened nexus 7 as developer also but nothing was changed. Samely it crashed.