Android Receive Text Intent From Other Apps

Aug 3, 2019

Edit AndroidManifest.xml and edit activity which shall handle the incoming text intent.

<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
    <application ...>
        <activity
            android:name=".view.QuoteMakerActivity"
            android:label="@string/title_activity_quote_maker"
            android:theme="@style/AppTheme.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>
    </application>
</manifest>

Edit the target activity.

class QuoteMakerActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {        super.onCreate(savedInstanceState)        setContentView(R.layout.quotemaker)        setSupportActionBar(toolbar)        if (intent?.action == Intent.ACTION_SEND) {            if ("text/plain" == intent.type) {                intent.getStringExtra(Intent.EXTRA_TEXT)?.let { content ->                    // do something                }            }        }    }}

References:

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.