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();
}
}
这是我的 android 客户端类代码。但是当我说连接时它崩溃并关闭。我在清单上添加了权限(清单上没有问题)。我过去在不同的平板电脑上使用了 code 的一部分。但我尝试了 Nexus 7,它就崩溃了。
这也是我的清单权限:
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" />
谁能知道我的nexus 7有什么问题?我也以开发人员的身份打开了nexus 7,但没有任何改变。同样它崩溃了。