我是Android新手。我创建了一个简单的食物应用。我想通过Whatsapp,消息等向我的朋友发送邀请,同时点击邀请按钮。我对此一无所知。你能指导我吗(显示一些例子意味着对我更有帮助)。
提前致谢!
答案 0 :(得分:2)
private void onShareClicked() {
String link = "https://play.google.com/store/apps/details?id=com.recharge2mePlay.recharge2me";
Uri uri = Uri.parse(link);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, link.toString());
intent.putExtra(Intent.EXTRA_TITLE, "Recharge2me");
startActivity(Intent.createChooser(intent, "Share Link"));
}
只需在 onClickListner 中调用此函数即可。
btn_tellAFreind.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onShareClicked();
}
});
答案 1 :(得分:1)
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);
答案 2 :(得分:1)
使用Firebase从谷歌尝试本教程,也许这可以帮助您: https://codelabs.developers.google.com/codelabs/firebase-android/#10
答案 3 :(得分:1)
Firebase邀请是通过电子邮件或短信进行应用推介和分享的开箱即用解决方案。
编译com.google.firebase:firebase-invites:10.0.1'
首先使用AppInviteInvitation.IntentBuilder
类构建一个Intent:
Intent intent = new AppInviteInvitation.IntentBuilder(getString(R.string.invitation_title))
.setMessage(getString(R.string.invitation_message))
.setDeepLink(Uri.parse(getString(R.string.invitation_deep_link)))
.setCustomImage(Uri.parse(getString(R.string.invitation_custom_image)))
.setCallToActionText(getString(R.string.invitation_cta))
.build();
startActivityForResult(intent, REQUEST_INVITE);
启动AppInviteInvitation
意图会打开联系人选择器,用户选择要邀请的联系人。邀请通过电子邮件或短信发送。用户选择联系人并发送邀请后,您的应用会收到onActivityResult
的回调:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "onActivityResult: requestCode=" + requestCode + ", resultCode=" + resultCode);
if (requestCode == REQUEST_INVITE) {
if (resultCode == RESULT_OK) {
// Get the invitation IDs of all sent messages
String[] ids = AppInviteInvitation.getInvitationIds(resultCode, data);
for (String id : ids) {
Log.d(TAG, "onActivityResult: sent invitation " + id);
}
} else {
// Sending failed or it was canceled, show failure message to the user
// ...
}
}
}
点击此处了解有关Send and Receive Firebase Invites from Your Android App
的更多详情<强>更新强>
使用Branch sdk支持WhatsApp,Facebook和其他社交媒体应用等其他平台的邀请功能。
点击此处了解How branch link works?
答案 4 :(得分:1)
您可以使用以下代码生成短链接:
DynamicLink dynamicLink = FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse("https://play.google.com/store/apps/details?id=com.example"))
.setDynamicLinkDomain("abc.app.goo.gl")
.setAndroidParameters(new DynamicLink.AndroidParameters.Builder().build())
.buildDynamicLink();
Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLongLink(dynamicLink.getUri())
.buildShortDynamicLink()
.addOnCompleteListener(ReferrerActivity.this, new OnCompleteListener<ShortDynamicLink>() {
@Override
public void onComplete(@NonNull Task<ShortDynamicLink> task) {
if (task.isSuccessful()) {
Uri shortLink = task.getResult().getShortLink();
Uri flowchartLink = task.getResult().getPreviewLink();
Log.i(TAG, "onComplete: SHORTLINK " + shortLink.toString());
Log.i(TAG, "onComplete: FLOW LINK " + flowchartLink.toString());
} else {
Log.i(TAG, "onComplete: ERROR " + task.isSuccessful() + " " + task.isComplete());
}
}
});
在onComplete方法中收到短链接后,请使用意图分享。
答案 5 :(得分:0)
如果我对问题的理解正确,那么您想在用户单击“共享”时使共享有区别,例如,如果他选择通过WhatsApp邀请,则它将仅显示Whatsapp作为共享邀请的中级选项。 / p>
如果这是您想要的,则应按照用于共享的意图来设置程序包,因此,如果我们在上述@Vishal答案中添加
sendIntent.setPackage("com.whatsapp");
对于任何需要的社交媒体,您都应该这样做
答案 6 :(得分:0)
您需要添加Firebase Dynamic链接。之前是Firebase邀请,但现在已贬值。 Firebase动态链接是在Firebase邀请之上构建的,因此您可以看到gradle文件上的邀请依赖项。
您可以按照本教程获取有关“ How to Create Refer a friend Link”的完整示例
有两种创建“推荐朋友链接”的方法
使用基于Firebase的动态对象
手动创建引用链接
1)选项:-
DynamicLink dynamicLink = FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse("https://www.example.com/"))
//.setDomainUriPrefix("https://example.page.link") // no longer in user please
.setDynamicLinkDomain("example.page.link") // use this code and don't use https:// here
// Open links with this app on Android
.setAndroidParameters(new DynamicLink.AndroidParameters.Builder().build())
// Open links with com.example.ios on iOS
.setIosParameters(new DynamicLink.IosParameters.Builder("com.example.ios").build())
.buildDynamicLink();
Uri dynamicLinkUri = dynamicLink.getUri();
2)选项:-
String sharelinktext = "https://referearnpro.page.link/?"+
"link=https://www.blueappsoftware.com/"+
"&apn="+ getPackageName()+
"&st="+"My Refer Link"+
"&sd="+"Reward Coins 20"+
"&si="+"https://www.blueappsoftware.com/logo-1.png";
然后调用 ShortDynamicLink 对象
引荐链接如下所示:
https://referearnpro.page.link?apn=blueappsoftware.referearnpro&link=https%3A%2F%2Fwww.blueappsoftware.com%2F
您可以检查完整的example here