我想使用 ACTION_SEND 共用圖片+文字,我運行了下面的代碼,暫時只能共用圖片,無法共用文字,我如何才能共用?
| 代碼如下 |
複製代碼 |
private Uri imageUri; private Intent intent; imageUri = Uri.parse("android.resource://" + getPackageName() + "/drawable/" + "ic_launcher"); intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_TEXT, "Hello"); intent.putExtra(Intent.EXTRA_STREAM, imageUri); intent.setType("image/*"); startActivity(intent); |
//如何才能共用圖片?
處理方法
你可以共用下面的代碼:
| 代碼如下 |
複製代碼 |
String shareBody = "Here is the share content body"; Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); sharingIntent.setType("text/plain"); sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here"); sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody); startActivity(Intent.createChooser(sharingIntent, getResources().getString(R.string.share_using))); |
所以你的全部代碼(圖片+文本)需要變成
| 代碼如下 |
複製代碼 |
private Uri imageUri; private Intent intent; imageUri = Uri.parse("android.resource://" + getPackageName() + "/drawable/" + "ic_launcher"); intent = new Intent(Intent.ACTION_SEND); //text intent.putExtra(Intent.EXTRA_TEXT, "Hello"); //image intent.putExtra(Intent.EXTRA_STREAM, imageUri); //type of things intent.setType("*/*"); //sending startActivity(intent); |