简体   繁体   English

如何从我的应用程序发送应用程序邀请(通过 whatsapp、远足、消息)

[英]How to send app invites from my application (via whatsapp,hike,message)

I am new for Android. I created a simple food app.我是 Android 的新人。我创建了一个简单的食物应用程序。 I want to send invitation to my friends from my app via Whatsapp, message etc. while clicking the invite button.我想在单击邀请按钮时通过 Whatsapp、消息等从我的应用程序向我的朋友发送邀请。 I don't have any idea about that.我对此一无所知。 Can you anyone guide me (Show some examples means more helpful to me).你能指导我吗(展示一些例子对我更有帮助)。

Thanks in advance!提前致谢!

Refer this link参考这个链接

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);
    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"));
}

And simply call this function in onClickListner.只需在 onClickListner 中调用此函数即可。

btn_tellAFreind.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            onShareClicked();
        }
    });

使用 Firebase 从 google 尝试本教程,也许这可以帮助您: https : //codelabs.developers.google.com/codelabs/firebase-android/#10

Firebase Invites are an out-of-the-box solution for app referrals and sharing via email or SMS. Firebase 邀请是一种开箱即用的解决方案,用于通过电子邮件或短信进行应用推荐和共享。

  1. Connect your app to your Firebase project from Firebase consoleFirebase 控制台将您的应用连接到您的 Firebase 项目
  2. Enabled Firebase Dynamic Links from the Firebase console by opening the Dynamic Links section and accepting the terms of service if prompted.通过打开动态链接部分并在出现提示时接受服务条款,从 Firebase 控制台启用 Firebase 动态链接。
  3. Add Firebase to your Android project将 Firebase 添加到您的 Android 项目
  4. Add the dependency for Firebase Invites to your app-level build.gradle file:将 Firebase Invites 的依赖项添加到您的应用级 build.gradle 文件:

compile 'com.google.firebase:firebase-invites:10.0.1'编译 'com.google.firebase:firebase-invites:10.0.1'

Send invitations:发送邀请:

Start by building an Intent using the AppInviteInvitation.IntentBuilder class:首先使用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);

Launching the AppInviteInvitation intent opens the contact chooser where the user selects the contacts to invite.启动AppInviteInvitation意图会打开联系人选择器,用户可以在其中选择要邀请的联系人。 Invites are sent via email or SMS .邀请通过电子邮件或短信发送 After the user chooses contacts and sends the invite, your app receives a callback to onActivityResult :在用户选择联系人并发送邀请后,您的应用会收到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
            // ...
        }
    }
}

Check out here for more details about Send and Receive Firebase Invites from Your Android App在此处查看有关从您的 Android 应用发送和接收 Firebase 邀请的更多详细信息

Update:更新:

Use Branch sdk to support invite feature on another platform like WhatsApp, Facebook and other social media apps.使用Branch sdk 支持另一个平台上的邀请功能,如 WhatsApp、Facebook 和其他社交媒体应用程序。

Check out here to know How branch link works?查看此处了解分支链接的工作原理?

Checkout here for Install guide & code example在此处结帐以获取安装指南和代码示例

You can generate short link by using the following codes:您可以使用以下代码生成短链接:

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());
                                }
                            }
                        });

Once you received the short link in onComplete method, share it using intent.在 onComplete 方法中收到短链接后,使用 Intent 共享它。

If I understand the question correctly, you want to make the share differentiate when the user clicks share and if he selects to invite via WhatsApp, for example, it will show only Whatsapp as a medium option to share the invite through.如果我正确理解了这个问题,您希望在用户单击共享时区分共享,并且如果他选择通过 WhatsApp 邀请,例如,它将仅显示 Whatsapp 作为共享邀请的媒介选项。

If that is what you want, you should to set the package in the intent you will use for sharing, so if we add to @Vishal answer above如果这是你想要的,你应该在你将用于共享的意图中设置包,所以如果我们添加到上面的@Vishal 答案

sendIntent.setPackage("com.whatsapp");

You should do the same for any needed social media你应该对任何需要的社交媒体做同样的事情

You need to add Firebase Dynamic link.您需要添加 Firebase 动态链接。 Earlier it was Firebase Invites but it is depreciated now.早些时候它是 Firebase Invites,但现在已经贬值了。 Firebase Dymanic Link is build over Firebase Invites So you can see the invites dependency on gradle file. Firebase Dymanic Link 是基于 Firebase Invites 构建的,因此您可以看到邀请对 gradle 文件的依赖关系。

You can follow this tutorial for complete example about " How to Create Refer a friend Link "您可以按照本教程获取有关“ 如何创建推荐朋友链接”的完整示例

There is Two ways to create "Refer a Friend Link"有两种方法可以创建“推荐朋友链接”

  1. Using Firebase base Dynamic Object使用 Firebase 基础动态对象

  2. Manually Create Refer a Link手动创建引用链接

1) Option :- 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) Option:- 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";

Then Call ShortDynamicLink Object然后调用ShortDynamicLink对象

Refer Link will be look like this :参考链接将如下所示:

https://referearnpro.page.link?apn=blueappsoftware.referearnpro&link=https%3A%2F%2Fwww.blueappsoftware.com%2F

You can check complete example here您可以在此处查看完整示例

a custom method to send invites, also according to the best practice in Android Developers发送邀请的自定义方法,也是根据 Android 开发人员中的最佳实践

fun inviteToDownloadApp(context: Context) {
    val intent = Intent(Intent.ACTION_SEND)
    intent.type = "text/plain"
    intent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.app_name))
    intent.putExtra(Intent.EXTRA_TEXT, context.getString(R.string.invite_to_download_app))
    context.startActivity(Intent.createChooser(intent, context.getString(R.string.invite_to_download_app)))
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM