如何通过消息共享应用程序共享应用程序链接
问题描述:
对于我的应用程序,我想提供共享选项。如何通过消息共享应用程序共享应用程序链接
为此,我编辑文本以提供电话号码和分享按钮。如果用户给出一个有效的号码并点击共享按钮,则应列出所有可用的消息发送应用程序的列表。如果用户从列表中选择一个应用程序,则带有应用程序链接的消息应该使用所选应用程序发送他的电话。
我该如何执行此操作?请帮忙。
答
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "message link");
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, "Chooser title text"));
答
尝试下面的代码,这正是你想要的,
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, Your_EditText_object.getText().toString());
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, "Your Title"));
答
试试这个
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT,"your application link"));
startActivity(Intent.createChooser(sharingIntent,"Share using"));
答
试试这个:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));
参考链接: https://developer.android.com/training/sharing/send.html
答
public static void callShare(Context theCtx, String theImagePath, String theText)
{
// Pass the message and Image path that you want to share
File myImageFile = new File(theImagePath);
String shareBody = theText; //"Here is the share content body " ;
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
if (myImageFile.exists()) {
// email address is required to be filled.
sharingIntent.setType("image/jpeg");
// "file://" and .getAbsolutePath is very important for Extra_Stream.
sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + myImageFile.getAbsolutePath()));
} else if (!theText.isEmpty()) {
sharingIntent.setType("text/*");
}
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, ""); //"Subject here"
sharingIntent.putExtra(Intent.EXTRA_TEXT, shareBody);
sharingIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
theCtx.startActivity(Intent.createChooser(sharingIntent, "Share via"));
}
@EKN你解决了你的问题吗? –