You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android应用集成Strava授权:包名作为Redirect URI无法跳转

Strava OAuth重定向回Android应用失败问题解决

问题背景

已获取Strava API的Client ID与Client Secret,将应用包名设置为Redirect URI时无法重定向回应用;但使用普通HTTPS URL作为Redirect URI时,重定向正常,可正常获取client code、state等信息。

关键错误分析

  1. 直接将应用包名作为Redirect URI不符合URI格式规范,Strava无法发起合法的重定向请求
  2. 当前Manifest中重定向用的intent-filter错误使用了android.intent.action.MAIN,浏览器重定向唤起应用需要的是android.intent.action.VIEW

解决方案

方案1:自定义URL Scheme(快速实现,无需域名验证)

这是最简便的实现方式,无需依赖外部域名:

  1. 在Strava API设置页面,将Redirect URI设置为符合格式的自定义Scheme,例如:com.your.package.name://oauth/redirect(替换为你的实际包名)
  2. 修改Manifest中的intent-filter,匹配该自定义Scheme:
<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />

    <data
        android:scheme="com.your.package.name" <!-- 替换为你的应用包名 -->
        android:host="oauth"
        android:path="/redirect" />
</intent-filter>
  1. 在Kotlin代码中,确保redirectUri参数与Strava后台设置完全一致:
val redirectUri = "com.your.package.name://oauth/redirect" // 和Strava后台配置匹配

方案2:Android App Links(HTTPS域名,需验证)

如果需要使用HTTPS格式的Redirect URI,需完成域名验证:

  1. 确保你的目标域名(如careplix.com)可正常访问,并在域名根目录下的.well-known/assetlinks.json文件中配置应用包名与签名指纹,完成Android系统的域名归属验证
  2. 修改Manifest中的intent-filter,修正action并开启自动验证:
<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />

    <data
        android:host="careplix.com"
        android:pathPrefix="/token-exchange"
        android:scheme="https" />
</intent-filter>
  1. 在Strava后台设置对应的HTTPS Redirect URI,确保与Manifest配置完全匹配

内容的提问来源于stack exchange,提问作者Subham Kumar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 21:50:13