浏览器回调和Android的活动栈疯狂回调、浏览器、疯狂、Android

2023-09-06 04:41:18 作者:薄凉小伙

我挣扎利用无处不在的回调定制计划─> intent_filter技术来获取OAuth的授权特定的行为。

我的应用程序寄存器发送动作,被调用时启动,反过来,检查用户已经授权的服务,如果没有,会生成一个活动(OAuthActivity)请登录。

请记住,正确的在此之前的前台活动发生可能是任何东西。活动然后开始一个VIEW意图打开浏览器中的身份验证页面;后者调用制作的回调(在清单中定义自定义方案),并唤醒OAuthActivity。

OAuthActivity了,目前, launchMode =singleTask但是这并没有使从堆栈的角度(它会在上面的时候叫回来)的​​差异。

有没有一种方法,我可以清除活性堆栈并取回什么用户在做什么,而不是强迫他按后退在浏览器上的活动? (我会再展的通知时已成功提交的背景内容)

有没有人有任何指针?感谢您通过

阅读 解决方案   

活动,然后开始一个VIEW意图在浏览器中打开AUTH页

这就是问题所在。这个工作对我来说:渲染OAuth的网页在一个web视图可以控制,而不是启动了浏览器的应用程序

OAuth的网页,当它所谓的回调,实际上是代替自己在web视图,在这里你WebViewClient能赶上预期的URL,处理结果,并完成()的web视图(从活动堆栈中取出) 。

UC浏览器疯狂夺金怎么提现 UC浏览器疯狂夺金提现方法一览

I'm struggling to get a specific behavior for OAuth authorization using the ubiquitous callback with custom scheme->intent_filter technique.

My app registers for SEND actions and, when called, starts a service which, in turn, checks if the user is already authorized and, if not, spawns an activity (OAuthActivity) to request login.

Keep in mind that the foreground activity right before this happens may be anything. The activity then starts a VIEW intent to open the auth page in the browser; the latter invokes the crafted callback (with custom scheme defined in manifest) and wakes the OAuthActivity.

OAuthActivity has, currently, launchMode="singleTask" but this doesn't make a difference from stack perspective (it gets on top when called back).

Is there a way I can clear the activity stack and get back to what the user was doing and not force him push 'back' on the browser activity? (I'll then show a notification when the content was successfully submitted in the background)

Does anyone have any pointers? Thanks for reading through

解决方案

The activity then starts a VIEW intent to open the auth page in the browser

That's the problem. This works for me: render the oauth web page in a webview you control rather than launching out to the browser app.

The oauth web page, when it calls its callback, will actually be replacing itself in the webview, where your WebViewClient can catch that expected URL, process the results, and finish() the webview (removing it from the activity stack).