0

I am using relativelayout. somehow I couldn't find sharing the TextView content .. even if I found it I couldn't. I want to share the TextView content with a button, can you help me with this?

I haven't written java code yet.

I need share code for this TextView. attention i am using relativelayout

Code main

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@drawable/k"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/tw2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_margin="16dp"
        android:shadowColor="#00ccff"
        android:shadowDx="1"
        android:shadowDy="1"
        android:shadowRadius="2"
        android:text=""
        android:textIsSelectable="true"
        android:textSize="30dp" />

</RelativeLayout>
Zain
  • 37,492
  • 7
  • 60
  • 84
Cebom25
  • 13
  • 4

1 Answers1

1

You can create an implicit ACTION_SEND intent to open the app chooser, and pick the suitable app that you want to share the text with.

Use this method in an activity:

public void shareText(String title, String content) {
    
    // Create an ACTION_SEND Intent
    Intent intent = new Intent(Intent.ACTION_SEND);
    
    // Set the type of the content to "text"
    intent.setType("text/plain");
    
    // Adding extras to the intent (title & content) 
    intent.putExtra(Intent.EXTRA_SUBJECT, title);
    intent.putExtra(Intent.EXTRA_TEXT, content);
    
    startActivity(Intent.createChooser(intent, title));
}
Zain
  • 37,492
  • 7
  • 60
  • 84