1

コードは次のように記述されています。

        final Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("*/*");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(Intent.EXTRA_SUBJECT, subject.toString());
        intent.putExtra(Intent.EXTRA_TEXT, text.toString());
        intent.putExtra(Intent.EXTRA_STREAM, "file://" + path);

         startActivityForResult(
                Intent.createChooser(intent, title.toString()), REQUEST_CODE);

結果は以下のとおりです。

  1. API 10:動作
  2. API 14:エラー
4

2 に答える 2

2

この方法を使用して、写真とテキストを共有します。このメソッドを呼び出し、引数nameofappとimagepathを渡します。アプリの名前は、Gmail、Facebook、Twitterなどの共有したいアプリの名前を意味します。

private void share(String nameApp, String imagePath) {
    try
    {
        List<Intent> targetedShareIntents = new ArrayList<Intent>();
        Intent share = new Intent(android.content.Intent.ACTION_SEND);
        share.setType("image/jpeg");
        List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(share, 0);
        if (!resInfo.isEmpty()){
            for (ResolveInfo info : resInfo) {
                    Intent targetedShare = new Intent(android.content.Intent.ACTION_SEND);
                    targetedShare.setType("image/jpeg"); // put here your mime type
                    if (info.activityInfo.packageName.toLowerCase().contains(nameApp) || info.activityInfo.name.toLowerCase().contains(nameApp)) {
                        targetedShare.putExtra(Intent.EXTRA_SUBJECT, "Text");
                        targetedShare.putExtra(Intent.EXTRA_TEXT,"This photo is created by APP");
                        targetedShare.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(imagePath)) );
                        targetedShare.setPackage(info.activityInfo.packageName);
                        targetedShareIntents.add(targetedShare);
                    }
                }
                Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Select app to share");
                chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{}));
                startActivity(chooserIntent);
        }
    }
    catch(Exception e){
    }
 }

これを次のように使用します:-

try {
    File filePath = "/mnt/sdcard/vmphoto.jpg"; //This is imagefile path in your change it acc. to your requirement.
    share("facebook",filePath.toString());

}
catch(Exception e) {
           //exception occur might your app like gmail , facebook etc not installed or not working correctly.
}
于 2012-12-16T08:14:47.040 に答える
1
final Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("*/*");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(Intent.EXTRA_SUBJECT, subject.toString());
    intent.putExtra(Intent.EXTRA_TEXT, text.toString());
    intent.putExtra(Intent.EXTRA_STREAM,
            Uri.fromFile(new File("/" + path)));
于 2012-12-16T08:27:11.610 に答える