2015-02-10 64 views
4

我想在導航抽屜上製作分享按鈕,當用戶觸摸按鈕時,它將打開帶有所有應用程序列表的黑色抽屜,並且用戶可以共享Google Play鏈接的應用程序。有沒有任何通用的代碼模板?我發現的唯一答案就是在Facebook等應用程序上分享它,因爲不是每個人都使用Facebook,所以這似乎毫無用處。Android Studio Share按鈕

回答

0

您可以通過調用與ACTION_SEND隱含意圖發送內容。

要發送的圖像數據或二進制數據:

final Intent shareIntent = new Intent(Intent.ACTION_SEND); 
shareIntent.setType("image/jpg"); 
final File photoFile = new File(getFilesDir(), "foo.jpg"); 
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(photoFile)); 
startActivity(Intent.createChooser(shareIntent, "Share image using")); 

與文本一起發送的圖像。這是可以做到的:

Intent shareIntent = new Intent(Intent.ACTION_SEND_MULTIPLE); 
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris); 
shareIntent.setType("image/*"); 

String text = "Look at my awesome picture"; 
Uri pictureUri = Uri.parse("file://my_picture"); 
Intent shareIntent = new Intent(); 
shareIntent.setAction(Intent.ACTION_SEND); 
shareIntent.putExtra(Intent.EXTRA_TEXT, text); 
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri); 
shareIntent.setType("image/*"); 
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
startActivity(Intent.createChooser(shareIntent, "Share images...")); 

分享多個圖像是可以做到的