Share Message using Installed App in Android   

In this article we will learn how to send and share message or other information from our application to installed application like whatsup,wechat etc.We are using Android Studio to build our application using java.

0 327 Technology | Android App
Sat Nov 10 , 2018

Step 1 : Create a new project name it ShareMessageExample

Step 2 : Select Empty Activity

Step 3 : Open main_activity.xml

Copy and paste code

                      
<EditText
android:id="@+id/edittext_sharecode
android:layout_width="wrap_content
android:layout_height="wrap_content
android:textColor="#CCCCCC
android:hint="Share Your Thoughts
android:textColorHint="#CCCCCC
/>
                        
    <Button
android:id="@+id/btn_sharecode
android:layout_width="wrap_content
android:layout_height="wrap_content
android:layout_marginTop="12dp
android:text="Share Code"/>
 

Step 4 : Now Open MainActivity.java

Copy and paste code

   
    Button btnCode;
    EditText sharecode;
    Intent intent;
                        
    @Override
    protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
                        
                        
                        
                        
btnCode=findViewById(R.id.btn_sharecode);

sharecode=findViewById(R.id.edittext_sharecode);

                        
                        
                        
btnCode.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        intent=new Intent(Intent.ACTION_SEND);
        intent.putExtra(Intent.EXTRA_TEXT,sharecode.getText().toString());
        intent.setType("text/plain");
        startActivity(intent);
    }
});
                        
}
}
  

Build the project

Run


Subscribe & Get Regular Updates On Your E-mail