0

I want my app to be apear on email intent when I want to share something by email. I mean when any app use intent share by email only I want my app to apear on there. I want what to add in android manifest.xml.

Here is my Code:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/html");
intent.putExtra(Intent.EXTRA_EMAIL, "emailaddress@emailaddress.com");
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intent.putExtra(Intent.EXTRA_TEXT, "I'm email body.");

startActivity(Intent.createChooser(intent, "Send Email"));
Fruchtzwerg
  • 10,999
  • 12
  • 40
  • 49
Moudou
  • 33
  • 10

2 Answers2

0

Specify ACTION_SEND and ACTION_SENDTO in your activity declaration in AndroidManifest file.

   <activity
        android:name=".MainActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <action android:name="android.intent.action.SEND"/> 
            <action android:name="android.intent.action.SENDTO"/>

            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
Samuel Robert
  • 10,106
  • 7
  • 39
  • 60
0

You need to implement logic for receive data from external app, following is the simple example for handle that,

In your manifest, you need to define internet filter in which activity you want to handle a data like following way,

<activity
            android:name=".view.ActivityHandleShare"
            android:theme="@style/Theme.AppCompat.Light.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="text/plain" />
            </intent-filter>
        </activity>

And after that, you can handle data in activity like following,

 private void handleSharingData() {
        // Get intent, action and MIME type
        Intent intent = getIntent();
        String action = intent.getAction();
        String type = intent.getType();
        if (Intent.ACTION_SEND.equals(action) && type != null) {
            if ("text/plain".equals(type)) {
                handleSendText(intent); // Handle text being sent
            }
        } 
    }

Now finally when you share data with your given format you will able to open your application when share using intent(Note: I have explained example only for text/plain for image or multiple image you can take help from following url https://developer.android.com/training/sharing/receive.html)

Dhaval Solanki
  • 4,589
  • 1
  • 23
  • 39