Android

Android SNS공유 ( 트위터)

Machine_웅 2021. 1. 19. 14:46
728x90
반응형
public class EO_Twitter extends Activity{
    private static String temp_content;

    public static void Twitter_share_T(Context context, String textBody) {
        Intent Sharing_intent = new Intent(Intent.ACTION_SEND);
        Sharing_intent.setType("text/plain");
        Sharing_intent.setPackage("com.twitter.android");

        String Test_Message = textBody;
        Sharing_intent.putExtra(Intent.EXTRA_TEXT, Test_Message);

        Intent Sharing = Intent.createChooser(Sharing_intent, "공유하기");
        context.startActivity(Sharing);
    }

    public static void Twitter_share_TI(Activity activity, String textBody) {
        temp_content = textBody;
        Intent intent = new Intent(Intent.ACTION_PICK);
        intent. setDataAndType(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
        activity.startActivityForResult(intent, 200);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 200 && resultCode == RESULT_OK && data != null && data.getData() != null) {
            // 이미지 첨부  Twitter_share_TI
            Uri selectedImageUri = data.getData();
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.setPackage("com.twitter.android");
            intent.putExtra(Intent.EXTRA_TEXT,temp_content);

            if (selectedImageUri != null) {
                intent.putExtra(Intent.EXTRA_STREAM, selectedImageUri);
                intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                intent.setType("image/*");
            }

            try {
                startActivity(intent);
            } catch (android.content.ActivityNotFoundException ex) {
                ex.printStackTrace();
            }
        }
    }

}
728x90
반응형