Firebase是否可以从android应用程序的html页面注销?
使用Firebase auth,当用户通过身份验证时,他们将被带到Firebase是否可以从android应用程序的html页面注销?,android,html,firebase,firebase-authentication,Android,Html,Firebase,Firebase Authentication,使用Firebase auth,当用户通过身份验证时,他们将被带到htmlPages活动,在这里,我从WebView中的android_资产加载Url。我有两个html页面index.html和profile.html。是否有任何方法可以在profile.html页面中向经过身份验证的用户配置文件显示,并在该html页面上设置注销按钮 工作流程如下: 从登录活动中,成功验证后,htmlpage活动开始 htmlpage活动在其WebView组件内打开profile.html页面 在profile
htmlPages
活动,在这里,我从WebView中的android_资产
加载Url。我有两个html页面index.html
和profile.html
。是否有任何方法可以在profile.html
页面中向经过身份验证的用户配置文件显示,并在该html页面上设置注销
按钮
工作流程如下:
登录
活动中,成功验证后,htmlpage
活动开始htmlpage
活动在其WebView组件内打开profile.html
页面profile.html
页面中,有一个注销
按钮和一个显示登录用户电子邮件地址的字段profile.html
页面的Sign Out
按钮中单击时,用户将注销,htmlpage
活动完成,Sign
活动开始htmlpage
活动:
public class htmlPages extends Activity implements AdvancedWebView.Listener {
private AdvancedWebView mWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.html_pages);
mWebView = (AdvancedWebView) findViewById(R.id.webview);
mWebView.setListener(this, this);
mWebView.setGeolocationEnabled(false);
mWebView.setMixedContentAllowed(true);
mWebView.setCookiesEnabled(true);
mWebView.setThirdPartyCookiesEnabled(true);
mWebView.loadUrl("file:///android_asset/home.html");
}
}
这是我的profile.html
:
<!DOCTYPE html>
<head>
<title>Profile</title>
</head>
<body>
Your email address is: <!-- User email address-->
<button type="button">Sign Out</button>
</body>
</html>
轮廓
您的电子邮件地址是:
退出
是的,我们可以做到,非常简单,我们必须为web视图编写自己的javascript接口,如下所示,并将其放在包含web视图的activity类下
inner class JSInterface(context: Context) {
@JavascriptInterface
fun performLogoutButtonClick() {
Log.d("SSB Log", "Logout button clicked")
// Perform logout action here
}
}
然后我们向web视图添加属性,如下所示,并加载html页面
fun loadWebViewWithButtonClick() {
val htmlString = "<html><body><button type=\"button\", onClick=\"JSInterface.performLogoutButtonClick()\">Logout</button></body></html>"
wvTest.apply {
settings.javaScriptEnabled = true
addJavascriptInterface(JSInterface(context), "JSInterface")
loadData(htmlString, "text/html", "UTF-8")
}
}
}
而profile.html
是:
<!DOCTYPE html>
<head>
<title>Profile</title>
</head>
<body>
Your email address is: <!-- User email address-->
<button type="button", onClick="JSInterface.performLogoutButtonClick()">Sign Out</button>
</body>
</html>
轮廓
您的电子邮件地址是:
退出
我想不可能!您只向profile.html
发送消息,您的firebase尚未连接到该网页,除非您想对该网页使用web身份验证。哇!这似乎很有希望。非常感谢你的努力。请根据我在给定的htmlPages
活动和更新我的问题时应该如何实现答案解释或更新答案?您只需添加onClick=“JSInterface.performLogoutButtonClick()”在profile.html的注销按钮中,您可以这样设置您的个人资料。您的电子邮件地址是:注销。您可以看看您的答案的更新情况吗?我是否正确?谢谢,但它不会注销。我创建了这个私有类JSInterface{JSInterface(Context Context){}@JavascriptInterface public void performLogoutButtonClick(){Log.d(“SSB日志”,“注销按钮单击”);FirebaseAuth.getInstance().signOut();finish();startActivity(新意图(this,MainActivity.class));}}}是的,您可以这样做,您必须使用postrl()方法并将电子邮件作为post参数传递,并在html文件中使用它而不是loadUrl(),有关更多信息,请参考此链接,希望我回答了您的问题:)
<!DOCTYPE html>
<head>
<title>Profile</title>
</head>
<body>
Your email address is: <!-- User email address-->
<button type="button", onClick="JSInterface.performLogoutButtonClick()">Sign Out</button>
</body>
</html>