首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >将数据从一个应用程序发送到另一个应用程序中的特定活动

将数据从一个应用程序发送到另一个应用程序中的特定活动
EN

Stack Overflow用户
提问于 2019-04-08 13:23:38
回答 1查看 330关注 0票数 0

我想将数据从一个应用程序发送到另一个应用程序中的特定活动。

下面的代码将数据发送到另一个应用程序中的主要活动。但是我希望IntentReceiver中指定一个活动

IntentSender

代码语言:javascript
代码运行次数:0
运行
复制
Intent intent = this.ApplicationContext.PackageManager.GetLaunchIntentForPackage("com.IntentReceiver");
intent.PutExtra("Message", "Hello");
StartActivity(intent);

IntentReceiver

代码语言:javascript
代码运行次数:0
运行
复制
var message = Intent.GetStringExtra("Message");
Toast.MakeText(this, $"OnResume {message}", ToastLength.Long).Show();

下面是用于android的,但我在Xamarin Android中实现它时遇到了问题。

Android : Call activity of another application

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-09 08:12:14

在第一个应用程序中,您需要下面的代码来打开第二个应用程序中的特定活动。

代码语言:javascript
代码运行次数:0
运行
复制
            Intent intent = new Intent("android.intent.action.SEND");
            //this first parameter is pageckage name of secound app,the secound parameter is specific activiy name totally

            ComponentName componentName = new ComponentName("reciverApp.reciverApp", "reciverApp.reciverApp.Activity1");
            intent.SetComponent(componentName);
            intent.PutExtra("Message", "Hello");
            StartActivity(intent);

在第二个应用程序中,打开特定的活动。添加注释,您应该添加Exported = true Name = "reciverApp.reciverApp.Activity1" IntentFilter

代码语言:javascript
代码运行次数:0
运行
复制
    [Activity(Label = "Activity1",Exported = true,Name = "reciverApp.reciverApp.Activity1")   ]
[IntentFilter(new[] { Intent.ActionSend }, Categories = new[] { Intent.CategoryDefault })]
public class Activity1 : Activity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        SetContentView(Resource.Layout.layout1);


    }
    protected override void OnResume()
    {

        var message = Intent.GetStringExtra("Message");
        if (message != null)
        {

            Toast.MakeText(this, $"OnResume {message}", ToastLength.Long).Show();
        }
        base.OnResume();

    }

有一个GIF我的运行演示。

这是我的演示代码。您应该先运行reciverApp,然后运行sendApp https://github.com/851265601/OpenAnotherActvityDemo

如果你对这种情况有一些怀疑,有一篇关于向其他应用程序发送简单数据的简单文章。

https://developer.android.com/training/sharing/send

这个场景包含意图/内容过滤器,如果你想知道更多关于它的细节,这个链接是有帮助的。https://developer.android.com/guide/components/intents-filters#PendingIntent

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55574528

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档