我正在使用本教程
http://developer.android.com/resources/samples/BluetoothChat/index.html。
我想通过一部安卓手机访问互联网,然后通过蓝牙将其发送到另一部手机。虽然网页显示很慢,网页显示不正确。我尝试逐行发送它并逐行将其加载到webview中,然后使用StringBuilder将其作为整个块加载到webview,尝试将其作为一个整体发送并由StringBuilder作为一个块加载。我还提供了所有权限。
uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
uses-permission android:name="android.permission.BLUETOOTH" />
uses-permission android:name="android.permission.INTERNET" />
我正在通过
HttpClient client = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.sheldonbrown.com/web_sample1.html");
HttpResponse response = client.execute(httppost);
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = "";
String NL = System.getProperty("line.separator");
while (( line = in.readLine())!= null) {
line = in.readLine();
sendMessage(line);
然后在另一端检索它并加载它的webview。
case MESSAGE_READ:
byte[] readBuf = (byte[]) msg.obj;
// construct a string from the valid bytes in the buffer
String readMessage = new String(readBuf, 0, msg.arg1);
add = readMessage + add;
try {
mWebView.loadData(URLEncoder.encode(add,"utf-8").replaceAll("\\+"," "),
"text/html", "utf-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
其中 add 是 String add="";