Understanding selectors in an intent

Viewed 18

I have code:

@Override
public void onClick(View v) {
    Intent i = new Intent(Intent.ACTION_MAIN);
    i.addCategory(Intent.CATEGORY_LAUNCHER);

    startActivity(i);
}

This listener lists all apps that have an icon in the launcher. As far as i can gather via setSelector(Intent) i can make a сhoice programmatically. So i want to choose the app that can send a plain text. I add the next lines:

@Override
public void onClick(View v) {
    Intent i = new Intent(Intent.ACTION_MAIN);
    i.addCategory(Intent.CATEGORY_LAUNCHER);

    Intent ii = new Intent(Intent.ACTION_SEND);
    ii.setType("text/plain");
    i.setSelector(ii);

    startActivity(i);
}

But i get an exception:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] sel=act=android.intent.action.SEND typ=text/plain} }
        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2117)
...

Do i understand correctly the gist of setSelector(Intent)? If it so what i did wrong?

0 Answers
Related