Cannot make startActivity() with Chooser ask just once per app

后端 未结 1 1296
星月不相逢
星月不相逢 2021-01-04 10:56

When you do startActivity() with chooser, Android would list all apps entitled to handle your Intent along with options to set this assignment perm

相关标签:
1条回答
  • 2021-01-04 11:51

    For a record - it was over-interpretation type of bug (of mine). The chooser I was using is exactly what can be seen on the image on the right side. And it was showing up all the time because... I was calling it all the time. I incorrectly assumed that chooser offers Always | Just once functionality and would not show up if user tapped "Always" (and will show up if s/he used Just once). But it is wrong. Chooser will always show up because that's its role - to let user choose.

    The Always | Just once functionality is different thing -> it is a feature of the Android framework for startActivity() (and startActivityForResult() etc) and it would show up automatically when needed (when there's more than one app, or precisely, more than one matching intent-filter declared in app manifest, that matches certain Intent). It would not show up if you got just one (or if user already choose Always).

    So you, as developer do not need to care nor handle the case in any special way. To fix the issue I simply changed my viewInExternalApplication() code to just call startActivity():

    try {
      context.startActivity( intent );
    } catch (.... )
    

    and let the framework do the rest.

    0 讨论(0)
提交回复
热议问题