使用此代码只打开特殊号码的聊天但文本不是共享.我该怎么做?
public class MainActivity extends AppCompatActivity { Button Wa; String id = "+919000000000"; EditText txt; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); txt = (EditText)findViewById(R.id.editText); Wa = (Button)findViewById(R.id.btn_whatsapp); Wa.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Uri uri = Uri.parse("smsto:" + id); Intent waIntent = new Intent(Intent.ACTION_SENDTO,uri); String text = "testing message"; waIntent.setPackage("com.whatsapp"); if (waIntent != null) { waIntent.putExtra(Intent.EXTRA_TEXT,text); startActivity(Intent.createChooser(waIntent,text)); } else { Toast.makeText(getApplicationContext(),"WhatsApp not found",Toast.LENGTH_SHORT) .show(); } } }); }
解决方法
由于您尝试将其实现为“smsto:”,因此“text / plain”类型将帮助您.如果没有帮助,请尝试额外的“sms_body”.
Uri uri = Uri.parse("smsto:" + id); Intent waIntent = new Intent(Intent.ACTION_SENDTO,uri); String text = "testing message"; waIntent.setPackage("com.whatsapp"); if (waIntent != null) { waIntent.setType("text/plain"); //waIntent.putExtra(Intent.EXTRA_TEXT,text); waIntent.putExtra("sms_body",text); startActivity(Intent.createChooser(waIntent,text)); } else { Toast.makeText(getApplicationContext(),Toast.LENGTH_SHORT) .show(); }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。