如何通过消息共享应用程序共享应用程序链接

时间:2017-01-23 09:00:17

标签: android

对于我的申请,我想提供分享选项。

为此,我编辑了文本以提供电话号码和分享按钮。如果用户提供有效数字并单击共享按钮,则应列出所有可用消息发送应用程序的列表。如果用户从列表中选择应用程序,则带有应用程序链接的消息应使用所选应用程序发送其电话。

我该如何实现?请帮忙。

5 个答案:

答案 0 :(得分:1)

  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"));

答案 1 :(得分:1)

尝试以下代码,这正是您想要的,

       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"));

答案 2 :(得分:1)

试试这个

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"));

答案 3 :(得分:0)

试试这个:

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

答案 4 :(得分:0)

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"));
    }