应用邀请使用Firebase无效 [英] App invites using Firebase not working
问题描述
遵循的步骤
代码片段
InviteActivity
btnInvite.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Intent intent = new AppInviteInvitation.IntentBuilder(INVITATION_TITLE)
.setMessage(INVITAT ION_MESSAGE)
.setDeepLink(Uri.parse(https://ewyc6.app.goo.gl/eNh4))
.setCallToActionText(INVITATION_CALL_TO_ACTION)
.build();
startActivityForResult(intent,REQUEST_INVITE);
}
});
@Override
protected void onActivityResult(int requestCode,int resultCode,Intent data){
super.onActivityResult(requestCode,resultCode,data);
Log.d(TAG,onActivityResult:requestCode =+ requestCode +,resultCode =+ resultCode +result_ok =+ RESULT_OK);
$ b $ if(requestCode == REQUEST_INVITE){
if(resultCode == RESULT_OK){
//您已成功发送邀请,
//我们可以关闭按钮。
btnInvite.setVisibility(View.GONE);
String [] ids = AppInviteInvitation.getInvitationIds(resultCode,data);
StringBuilder sb = new StringBuilder();
sb.append(Sent).append(Integer.toString(ids.length))。append(invitations:);
for(String id:ids)sb.append([)。append(id).append(]);
Toast.makeText(getApplicationContext(),Invited !!!,Toast.LENGTH_SHORT).show();
$ b} else {
Toast.makeText(getApplicationContext(),对不起,无法发送邀请,Toast.LENGTH_SHORT).show();
$ b $ c
$ b $ result_code是3,RESULT_OK在调试时是-1
新的Firebase的东西,将不胜感激,如果指出我做错了什么。
经过数小时的努力找到了问题并修复了这个问题,在这里发布,因为这可能对其他人有帮助。
$ b $ b 最初的提示是创建邀请失败的错误代码:3有一个类似的问题在这里SO
获取建议被邀请者失败,因为错误代码:3
但是在我的情况下已经添加SHA1证书,但Firebase中的软件包名称竟然是一个区分大小写的问题。还有一点需要注意,从Firebase和Web Api Key下载的google-services.json中的api_key是不相关的。我试图复制和粘贴的Web API密钥到JSON文件手动从仪表板api_key的误解,可能是问题导致错误。
Developing an App which has Firebase as backend. Currently, was stuck while implementing Firebase App Invite . Just looking to send invites ( not currently trying to implement the clicking of the dynamic link by the installed new user) but the onActivityResult returns wrong result_code
Steps followed
- Integrated FireBase SDK and authenticating successfully.
- Enabled Firebase Dynamic link and referred in the app
- Clicking on the invite button shows the inbuilt Firebase Activity with option to select users to invite and sent ( SMS or Email Invites )
- the app returns back to the invite screen as expected.
Code Snippet
InviteActivity
btnInvite.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new AppInviteInvitation.IntentBuilder(INVITATION_TITLE)
.setMessage(INVITATION_MESSAGE)
.setDeepLink(Uri.parse("https://ewyc6.app.goo.gl/eNh4"))
.setCallToActionText(INVITATION_CALL_TO_ACTION)
.build();
startActivityForResult(intent, REQUEST_INVITE);
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "onActivityResult: requestCode=" + requestCode + ", resultCode=" + resultCode + "result_ok ="+RESULT_OK);
if (requestCode == REQUEST_INVITE) {
if (resultCode == RESULT_OK) {
// You successfully sent the invite,
// we can dismiss the button.
btnInvite.setVisibility(View.GONE);
String[] ids = AppInviteInvitation.getInvitationIds(resultCode, data);
StringBuilder sb = new StringBuilder();
sb.append("Sent ").append(Integer.toString(ids.length)).append(" invitations: ");
for (String id : ids) sb.append("[").append(id).append("]");
Toast.makeText(getApplicationContext(),"Invited!!!",Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(),"Sorry, unable to send invite.",Toast.LENGTH_SHORT).show();
}
}
}
//result_code is 3 and the RESULT_OK is -1 on debugging
New to Firebase stuff , would appreciate if point out what I m doing wrong.
解决方案 After hours of struggle found the issue and fixed it, posting it here since it might be helpful to others too.
The initial hint was "Create invitations failed to error code: 3" Had a similar issue here in SO
Get suggested invitees failed due to error code: 3
But in my case the SHA1 certificate was already added, but the package name in Firebase turned out to be a case sensitive issue.
One more point worth taking note of, "api_key" in google-services.json downloaded from Firebase and Web Api Key are not related. I tried to copy and paste the web api key to the json file manually from dashboard to api_key under the misconception that might be the issue lead to the error.
这篇关于应用邀请使用Firebase无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!