【问题标题】:chrome ignores included header in intentchrome 忽略意图中包含的标头
【发布时间】:2018-05-24 04:07:18
【问题描述】:

我曾经将标题添加到意图如下:

        Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(baseUrl));
        myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        Bundle bundle = new Bundle();
        TokenManager manager = TokenManager.getTokenManager();
        bundle.putString("Authorization", manager.getAuthorization());
        bundle.putString("Content-Type","application/x-www-form-urlencoded");
        myIntent.putExtra(Browser.EXTRA_HEADERS, bundle);
        mContext.startActivity(myIntent);

但它似乎不适用于最新版本的谷歌浏览器。它忽略标题,因为没有标题,因此我遇到授权问题。 有谁能够帮我? (我需要使用意图而不是 webview)

【问题讨论】:

  • stackoverflow.com/questions/3750361/… 接受的答案应该有效
  • @Xirate 接受的答案是我目前使用的方法(正如您在问题描述中看到的那样),即使它是默认浏览器,它也不适用于最新的 google chrome 浏览器。跨度>

标签: android google-chrome


【解决方案1】:

试试这个解决方案

我有一个存储标头信息的 Map 对象。然后是:

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
Bundle bundle = new Bundle();
if(mExtraHeader!=null){
 for(String key: mExtraHeader.keySet()){
  bundle.putString(key, mExtraHeader.get(key));
 }
}
i.putExtra(Browser.EXTRA_HEADERS, bundle);
startActivity(i);

【讨论】:

  • 您的建议只是填充捆绑包的另一种方式,该捆绑包将使用 Browser.EXTRA_HEADERS 键值添加到意图中,chrome 不会读取此捆绑包,因此它不会设置我们指定的标题。因此我们遇到了我提到的问题。
  • 请检查此链接可能对您有帮助,developer.chrome.com/multidevice/android/intents#example
  • 相反,直接通过 Intent 发送您的字符串值。避免捆绑并检查会发生什么。或查看stackoverflow.com/questions/3750361/…
猜你喜欢
  • 1970-01-01
  • 2021-09-19
  • 2019-03-16
  • 1970-01-01
  • 2018-08-10
  • 2011-09-27
  • 2011-03-20
  • 1970-01-01
  • 2019-01-20
相关资源
最近更新 更多