将数据从一个 xamarin.android 应用发送到另一个 xamarin.forms 应用 [英] Send data from one xamarin.android app to another xamarin.forms app

查看:26
本文介绍了将数据从一个 xamarin.android 应用发送到另一个 xamarin.forms 应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以将数据从一个 xamarin.forms 应用程序发送到另一个 xamarin.forms 应用程序.Android 应用程序的目标仅针对 android,而其他应用程序是 android 和 ios.android 应用程序必须在本地将数据发送到 android 应用程序/ios,但 android 应用程序正在接收它.在我的应用程序 android 中,我无法打开另一个应用程序并发送数据.但我无法在我的应用程序中接收数据.这是android应用程序中的代码:

is there any way to send data from one xamarin.forms app to another xamarin.forms app. Android application the goal is only for android, while the other application is android and ios. The android application has to send data locally to android application / ios but the android application is receiving it. in my aplication android i cant open another app and send data. but i cant receveing data in my aplication. this is the code in android aplication:

 Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.setComponent(new ComponentName("com.companyname.Opiniao","android.intent.action.B"));
        intent.putExtra(Intent.EXTRA_TEXT, editTextEmail.getText() + "\n " + editTextPassword.getText());
        intent.setType("text/plain");
        startActivity(intent);

推荐答案

我已经能够解决问题了.

I've already been able to solve the problem.

在我的 Android 应用程序中,我使用以下代码:

In my Android Aplication, i use this code:

    void enviar(){
    // Usa o nome do package que nos queremos encontrar
    boolean isAppInstalled = appInstalledOrNot("com.companyname.Opiniao");

    if(isAppInstalled) {
       Intent intent = new Intent(Intent.ACTION_MAIN);
       intent.setComponent(new ComponentName("com.companyname.Opiniao","android.intent.action.B"));
        intent.putExtra("Dados", editTextEmail.getText() + "\n" + editTextPassword.getText());
        startActivity(intent);


    } else {
        String url = "http://www.google.com";
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        startActivity(i);
    }
}

//Procura o package, se tiver instalado, envia um true, se não encontrar devolve um false
private boolean appInstalledOrNot(String uri) {
    PackageManager pm = getPackageManager();
    try {
        pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

在我的 xamarin.forms 中,在 android mainActivity 中,我把这个:

in my xamarin.forms, in android mainActivity, i put this:

        async void Receber()
    {
        text = Intent.GetStringExtra("Dados");
        string dados = "Dados";
        bool result;
        result = await dados.WriteTextAllAsync(text);
     }

这篇关于将数据从一个 xamarin.android 应用发送到另一个 xamarin.forms 应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆