【发布时间】:2019-08-28 13:34:20
【问题描述】:
我一直在尝试在 Android 中实现 Google 的 AppAuth 库,但我很难让它发挥作用。我一直在尝试遵循 guide from Google 并将其应用于我自己的代码库,但我被待定的意图所困扰。
更具体地说,当我调用performAuthorizationRequest() 方法时,模拟器可以按照重定向在其自定义选项卡中获取验证码(我可以看到它)。但是,没有调用任何处理程序。我尝试添加 onNewIntent()、onActivityResult() 和 onResume(),但没有一个被调用。
从 performAuthorizationRequest() 的 Javadocs 中,我看到了
"提供的 {@link PendingIntent 完成 PendingIntent} 将是 调用”。
这是什么意思?如何与已完成的 pendingIntent 对象进行交互?有没有什么方法可以在创建挂起意图时使用发送的请求代码检索该上下文?
下面是我的代码:
var authReq: AuthorizationRequest = AuthorizationRequest.Builder(
serverConfig,
clientId,
ResponseTypeValues.CODE,
redirectUri
).build()
val service: AuthorizationService = AuthorizationService(view.context)
val action = "com.google.codelabs.appauth.HANDLE_AUTHORIZATION_RESPONSE"
val authIntent = Intent(action)
val pendingIntent = PendingIntent.getActivity(this, authReq.hashCode(), authIntent, 0)
service.performAuthorizationRequest(authReq, pendingIntent)
在我的清单中,我添加了活动:
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.google.codelabs.appauth.HANDLE_AUTHORIZATION_RESPONSE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name="net.openid.appauth.RedirectUriReceiverActivity" >
<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.google.codelabs.appauth"/>
</intent-filter>
</activity>
【问题讨论】:
标签: android android-pendingintent appauth