不能让startActivity()与选配要求只是每一次应用 [英] Cannot make startActivity() with Chooser asking just once per app

查看:167
本文介绍了不能让startActivity()与选配要求只是每一次应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当你这样做 startActivity()与选择器,机器人会列出有权处理所有应用程序的意图随选项​​来设置此分配永久或一次时间(ICS上的始终和仅此一次动作按钮,在2.X它的复选框)。然而,对于这种code:

When you do startActivity() with chooser, Android would list all apps entitled to handle your Intent along with options to set this assignment permanent or once-time (on ICS its "Always" and "Just once" action button, on 2.x it's checkbox). However for this code:

public class Redirector {
    public static void showActivityWithChooser( Context context, int chooserLabelTitleId, Intent intent ) {
      try {
        context.startActivity( Intent.createChooser( intent, 
                     context.getResources().getString( chooserLabelTitleId )) );
      } catch( Exception e ) {
        e.printStackTrace();
      }
    }

    public static void viewInExternalApplication( Context context, String url ) {
      Intent intent = new Intent(   Intent.ACTION_VIEW );
      intent.setData( Uri.parse( url ) );
      intent.addFlags( Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET );
      showActivityWithChooser( context, R.string.open_chooser_title, intent );
    }
}

我看不出有什么永远|就一次按钮,无法让我选择永久性的(我只列出了应用程序,并可以通过点击它火的话)。什么小学我忽略,使得机器人无法做出用户选择的执着?

I see no "Always|Just once" buttons and cannot make my selection permanent (I got apps listed only and can fire any by tapping it). What elementary I overlooked that made Android unable to make user choice persistent?

查看图片:左对话是我想看到的,但正确的是我现在得到(不同数量的两个对话框应用程序无关):

See the pics: left dialog is what I'd like to see, but right is what I get now (different number of applications in both dialogs is irrelevant):

推荐答案

有关的纪录 - 这是过跨pretation(矿)错误的类型。我以前用的是选择器正是可以看到正确的图像。并且它显示了所有的时间,因为......我在呼唤它所有的时间。我错误地假定选择器提供始终|就一次的功能,不会显示出来,如果​​用户点击总是(将显示如果他/她用就一次)。但是,这是错误的。选择器将总是显示,因为这是它的作用 - 让用户选择。 总是|就一次的功能是不同的东西 - 它是 startActivity Android框架()的功能 startActivityForResult()要求,并在需要时会自动显示出来 - 如果有一个以上的应用程序,可以处理某些意图,也不会显示出来,如果​​你有只是一个或抽头总是最后一次。您作为开发商并不需要关心。

For a record - it was over-interpretation type of bug (of mine). The chooser I used was using is exactly what can be seen on the right image. 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 feature of the Android framework for startActivity()and startActivityForResult() calls, and will show up automatically when needed - if there's more than one app that can handle certain Intent and it will not show up if you got just one or tapped "Always" last time. You, as developer do not need to care.

因此​​,要解决这个问题我只是改变了我的 viewInExternalApplication() code使用 startActivity()而不是

So to fix this I just changed my viewInExternalApplication() code to use startActivity() instead:

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

和让框架做休息。

这篇关于不能让startActivity()与选配要求只是每一次应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆