我在Android的..我的世界大三想从应用程序的Android设备通过蓝牙发送字符串应用在其他设备.. 我写的下面的代码..但手机收到的HTML文件格式的字符串,而我希望得到它在应用 谁能帮助我,请???发送和通过蓝牙接收convets纯/文本字符串为HTML格式
发送代码..
public class MainActivity extends AppCompatActivity {
EditText txt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txt=(EditText) findViewById(R.id.txt);
}
public void sendMessage(View view) {
String message ;
message= txt.getText().toString();
Intent i = new Intent();
i.setAction(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_TEXT, message);
i.setType("text/plain");
startActivity(i);
}
}
接收代码
public class MainActivity extends AppCompatActivity {
TextView txt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txt= (TextView)findViewById(R.id.txt);
Intent intent= getIntent();
String action= intent.getAction();
String type= intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
// When tyoe is 'text/plain'
if ("text/plain".equals(type)) {
handleSendText(intent, txt); // Handle text being sent
}
}
}
private void handleSendText(Intent intent, TextView txt) {
// Get the text from intent
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
// When Text is not null
if (sharedText != null) {
// Show the text as Toast message
txt.setText(sharedText);
}
}
}
的可能的复制[分享文/通过蓝牙纯字符串数据转换成HTML(http://stackoverflow.com/questions/29907030/sharing-文本纯字符串通过蓝牙变频-数据到-HTML) –
请告诉我们你收到了什么?我的意思是当你发送像“message”这样的纯文本时输入你的内容? –
我recive文件的.html当我打开它,我发现,我送 – toomy