【发布时间】:2020-11-05 11:09:14
【问题描述】:
尝试使用以下代码 sn-ps 发送 pdf、图像和文本。使用 ACTION_VIEW 时,特定的 whatsapp 聊天正在打开,正在发送文本,但无法发送 pdf 或图像。请为我面临的以下问题提供适当的代码 sn-p 帮助。
我尝试的方法如下:
PackageManager pm = bill_layout.this.getPackageManager();
try {
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("application/pdf");
String text = "YOUR TEXT HERE";
PackageInfo info = pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA);
waIntent.setPackage("com.whatsapp");
waIntent.putExtra(Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(waIntent, "Share with"));
} catch (PackageManager.NameNotFoundException e) {
Toast.makeText(bill_layout.this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
.show();
}
try {
String longUrl="https://firebasestorage.googleapis.com/v0/b/glossy-radio-280106.appspot.com/o/19c48c9d-3f83-4a8f-a296-fe0ea
Bitly bitly= Bit.ly("o_1gduh4caf3");
shorturl=bitly.shorten(longUrl);
String text= "shorturl";// Replace with your message.
String toNumber = "91xxxxxxxxxx"; // Replace with mobile phone number without +Sign or leading zeros, but with country code
//Suppose your country is India and your phone number is “xxxxxxxxxx”, then you need to send “91xxxxxxxxxx”.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("http://api.whatsapp.com/send?phone="+toNumber +"&text="+ URLEncoder.encode(text, "UTF-8"))
"text/plain");
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT,"okay");
intent.setPackage("com.whatsapp");
startActivity(intent); }
catch (Exception e){
e.printStackTrace();}
PackageManager pm1=getPackageManager();
try {
String toNumber = "91xxxxxxxxxx"; // Replace with mobile phone number without +Sign or leading zeros, but with country co
//Suppose your country is India and your phone number is “xxxxxxxxxx”, then you need to send “91xxxxxxxxxx”.
Intent sendIntent = new Intent(Intent.ACTION_SENDTO,Uri.parse("smsto:"+ toNumber));
sendIntent.setPackage("com.whatsapp");
sendIntent.putExtra(Intent.EXTRA_TEXT,"test1");
sendIntent.putExtra("chat",true);
startActivity(sendIntent);}
catch (Exception e){
e.printStackTrace();
Toast.makeText(bill_layout.this,"it may be you dont have whats app",Toast.LENGTH_LONG).show();
}
Intent sendIntent = new Intent("android.intent.action.SEND");
File f=new File("path to the file");
Uri uri = Uri.parse("gs://glossy-radio-280106.appspot.com/19c48c9d-3f83-4a8f-a296-fe0eaf4488c4.pdf");
sendIntent.setComponent(new ComponentName("com.whatsapp","com.whatsapp.ContactPicker"));
sendIntent.setType("application/pdf");
sendIntent.putExtra(Intent.EXTRA_STREAM,uri);
sendIntent.putExtra("jid","918824525121"+"@s.whatsapp.net");
sendIntent.putExtra(Intent.EXTRA_TEXT,"sample text you want to send along with the image");
startActivity(sendIntent);
PackageManager pm = bill_layout.this.getPackageManager();
String formattedNumber ="91xxxxxxxxxx";
try{
Intent sendIntent =new Intent("android.intent.action.MAIN");
sendIntent.setComponent(new ComponentName("com.whatsapp", "com.whatsapp.Conversation"));
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PackageInfo info = pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Card Set ");
sendIntent.putExtra(Intent.EXTRA_TEXT,formattedNumber);
sendIntent.setType("text/plain");
sendIntent.putExtra("jid", formattedNumber +"@s.whatsapp.net");
sendIntent.setPackage("com.whatsapp");
bill_layout.this.startActivity(sendIntent);
}
catch(Exception e)
{
Toast.makeText(bill_layout.this,"Error/n"+ e.toString(),Toast.LENGTH_SHORT).show();
【问题讨论】:
标签: java android pdf android-intent whatsapp