private class ConnectThread extends Thread {
private final BluetoothSocket mmSocket;
private final BluetoothDevice mmDevice;
public ConnectThread(BluetoothDevice device) {
BluetoothSocket tmp = null;
mmDevice = device;
//从BluetoothDevice中获取Socket
try {
// MY_UUID为UUID串,必须与服务端一致
tmp = device.createRfcommSocketToServiceRecord(MY_UUID);
} catch (IOException e) { }
mmSocket = tmp;
}
public void run() {
// //取消发现远程设备,这样会降低系统性能
mAdapter.cancelDiscovery();
try {
// 建立连接
mmSocket.connect();
} catch (IOException connectException) {
// 无法连接或连接出错
try {
mmSocket.close();
} catch (IOException closeException) { }
return;
}
// 在单独的线程中处理事件,如数据传输
manageConnectedSocket(mmSocket);
}
/** 取消连接,关闭Socket */
public void cancel() {
try {
mmSocket.close();
} catch (IOException e) { }
}
}
TextView TV = (TextView)findViewById(R.id.mytextview01);
TV.setText("I know just how to whisper, And I know just how to cry,I know just where to find the answers", TV.BufferType.SPANNABLE);
Spannable WordtoSpan = (Spannable) myTextView.getText();
WordtoSpan.setSpan(new ForegroundColorSpan(Color.BLUE), 15, 30, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
TV.setText(WordtoSpan);
BitmapDrawable bd = (BitmapDrawable)imageView.getDrawable();
intent.putExtra("img", bd);
Bitmap b = (Bitmap) intent.getParcelable("img");
imageView.setImageBitmap(b);
Intent mIntent = new Intent(Intent.ACTION_MAIN, null);
mIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> mApps =
getPackageManager().queryIntentActivities(mIntent, 0);
for(int i=0;i<mApps.size();i++){
ResolveInfo info=mApps.get(i);
info.activityInfo.name.toString();//名称
info.loadIcon(getPackageManager());//图标
}