2016-10-12 76 views
0

我在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); 
    } 
} 

}

+1

的可能的复制[分享文/通过蓝牙纯字符串数据转换成HTML(http://stackoverflow.com/questions/29907030/sharing-文本纯字符串通过蓝牙变频-数据到-HTML) –

+0

请告诉我们你收到了什么?我的意思是当你发送像“message”这样的纯文本时输入你的内容? –

+0

我recive文件的.html当我打开它,我发现,我送 – toomy

回答

0

有可能通过使用EXTRA_REPLACEMENT_EXTRAS以实现对 “蓝牙共享” 的应用程序异常

你可以看到this code of sample app或看到这个Question及其answes ...

+0

其实我不明白我应该如何改变..你可以帮助我的字符串? – toomy

+0

你在我的答案检查链接?尝试比较你的代码与他们 –

+0

是的,我检查了,但我不能在我的代码中应用它 – toomy