Android: インテントを使用してプレーンテキストを共有する (すべてのメッセージング アプリに) 質問する

Android: インテントを使用してプレーンテキストを共有する (すべてのメッセージング アプリに) 質問する

インテントを使用してテキストを共有しようとしています:

Intent i = new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/plain");  
i.putExtra(android.content.Intent.EXTRA_TEXT, "TEXT");

選択ツールでワープする:

startActivity(Intent.createChooser(sms, getResources().getString(R.string.share_using)));

動作します! ただし、電子メール アプリのみです。
必要なのは、すべてのメッセージング アプリ (電子メール、SMS、IM (Whatsapp、Viber、Gmail、SMS など)) の一般的なインテントです。何度も試してみましたandroid.content.Intent.ACTION_VIEWが、i.setType("vnd.android-dir/mms-sms");何も役に立ちませんでした...

( "vnd.android-dir/mms-sms"SMSのみを使用して共有されます!)

ベストアンサー1

コードは次のように使用します:

    /*Create an ACTION_SEND Intent*/
    Intent intent = new Intent(android.content.Intent.ACTION_SEND);
    /*This will be the actual content you wish you share.*/
    String shareBody = "Here is the share content body";
    /*The type of the content is text, obviously.*/
    intent.setType("text/plain");
    /*Applying information Subject and Body.*/
    intent.putExtra(android.content.Intent.EXTRA_SUBJECT, getString(R.string.share_subject));
    intent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
    /*Fire!*/
    startActivity(Intent.createChooser(intent, getString(R.string.share_using)));

おすすめ記事