2017-01-23 221 views
1

對於我的應用程序,我想提供共享選項。如何通過消息共享應用程序共享應用程序鏈接

爲此,我編輯文本以提供電話號碼和分享按鈕。如果用戶給出一個有效的號碼並點擊共享按鈕,則應列出所有可用的消息發送應用程序的列表。如果用戶從列表中選擇一個應用程序,則帶有應用程序鏈接的消息應該使用所選應用程序發送他的電話。

我該如何執行此操作?請幫忙。

回答

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

嘗試下面的代碼,這正是你想要的,

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

+0

@EKN你解決了你的問題嗎? –

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")); 
    } 
相關問題