Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android intent sometimes "handled" instead of ACTION_SEND

My app is supposed to handle shared texts. For example URLs from the amazon app. So I added the following intent-filter to my main activity:

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

In my onCreate function of my activity, I'm processing the intent like so:

        intent = getIntent();
        if(intent.getAction() != null) {
            if (intent.getAction().equals(Intent.ACTION_SEND)) {
                if (intent.getType().equals("text/plain")) {
                    onNavigationDrawerItemSelected(1);
                }
            }
        }

The problem is, that sometimes the onCreate function isn't called following a sharing action. I checked the onResume method, and indeed that's what is called. The problem is that the intents action isn't "ACTION_SEND", but is packagename.handled and doesn't contain the needed information.

Why is that?

like image 314
Joshude Avatar asked Nov 15 '16 16:11

Joshude


People also ask

Is Intent deprecated?

The Intent is not deprecated the problem is with your itemClickable. class because it is not recognized. Either you have somehow enabled extra warnings that identify Intent as deprecated or something is really stack at your machine.

What triggers an Intent in android?

Android Intent is the message that is passed between components such as activities, content providers, broadcast receivers, services etc. It is generally used with startActivity() method to invoke activity, broadcast receivers etc. The dictionary meaning of intent is intention or purpose.

What is the difference between Intent and IntentFilter?

An intent is an object that can hold the os or other app activity and its data in uri form.It is started using startActivity(intent-obj).. \n whereas IntentFilter can fetch activity information on os or other app activities.


1 Answers

If your activity already exists, depending on Intent flags and <activity> attributes, that existing activity instance may be reused. Override onNewIntent() to get the Intent being delivered to an existing activity instance that is causing it to be brought back to the foreground. Look in there for your ACTION_SEND values.

like image 73
CommonsWare Avatar answered Oct 02 '22 02:10

CommonsWare