piko agusta
piko agusta

Reputation: 33

How to prevent other app open my app inside their app when sharing image in android?

MyApp use intent-filter to receive image from other App, but when I share image from Telegram, Telegram open new instance of MyApp inside telegram app instead of reopen current instance of MyApp. So 2 instance of MyApp open at the same time. It's different when I share image from WhatsApp to MyApp. Quora App can prevent that. So how to prevent telegram to do that like Quora App? I used single activity with jetpack navigation. Thanks.

        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="image/*" />
        </intent-filter>

enter image description here

Upvotes: 1

Views: 295

Answers (2)

Arkady Gamza
Arkady Gamza

Reputation: 191

I had the same issue. In my case Telegram created Intents with flags set to 0x13000001. Resetting these to just Intent.FLAG_ACTIVITY_NEW_TASK helped.

To do so I created a proxy Activity, registered intent-filter to this proxy Activity and reset Intent flags in its onCreate method:

class IntentProxyActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val newIntent = Intent(intent)

        //telegram sends intent with flags 0x13000001
        newIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK

        newIntent.component = ComponentName(this, MainActivity::class.java)
        startActivity(newIntent)

        finish()
    }
}

Upvotes: 0

Ivo
Ivo

Reputation: 23257

I'm not sure but maybe it helps to put this in your manifest in the activity

android:launchMode="singleInstance"

Upvotes: 0

Related Questions