Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin.android 如何从android GcmService访问xamarin表单属性_Xamarin.android_Xamarin.forms - Fatal编程技术网

Xamarin.android 如何从android GcmService访问xamarin表单属性

Xamarin.android 如何从android GcmService访问xamarin表单属性,xamarin.android,xamarin.forms,Xamarin.android,Xamarin.forms,我可以使用Application.Current.Properties[key]存储数据 但是,当远程通知到达时,我如何从Android读取这些数据呢 如果应用程序已关闭且没有“当前”Xamarin表单应用程序,我如何读取/写入此数据 [Service] public class GcmService : GcmServiceBase { public static string RegistrationID { get; private set; } public GcmS

我可以使用Application.Current.Properties[key]存储数据

但是,当远程通知到达时,我如何从Android读取这些数据呢

如果应用程序已关闭且没有“当前”Xamarin表单应用程序,我如何读取/写入此数据

 [Service]
public class GcmService : GcmServiceBase
{
    public static string RegistrationID { get; private set; }

    public GcmService()
        : base(PushHandlerBroadcastReceiver.SENDER_IDS) { }

    protected override void OnRegistered(Context context, string registrationId)
    {
        Log.Verbose("PushHandlerBroadcastReceiver", "GCM Registered: " + registrationId);
        RegistrationID = registrationId;
    }

    protected override void OnMessage(Context context, Intent intent)
    {

        var msg = new StringBuilder();

        if (intent != null && intent.Extras != null)
        {
            foreach (var key in intent.Extras.KeySet())
                msg.AppendLine(key + "=" + intent.Extras.Get(key).ToString());
        }



        string textoNotificacion = intent.Extras.GetString("gcm.notification.body");
        var nombre = "Alumno - ";
        if (!string.IsNullOrEmpty(textoNotificacion))
        {
            //***************************************** //
            var idEstatus = "0";
            var textoEstatus = "Cambio de Estatus";

            if (textoNotificacion.Length > 2)
            {
                idEstatus = textoNotificacion.Substring(0, 1);
                textoEstatus = textoNotificacion.Substring(1);
            }


            try
            {

                var app = App.Current;                  

                if (app == null)
                {
                    Read and Save data in xamarin form properties here!!!

                }
                else
                {
                    var mp = (MainPage)app.MainPage;
                    nombre = mp.getNombre() + " - ";
                    mp.actualizarEstatus(idEstatus, textoEstatus);
                }





            }
            catch(Exception e)
            {

                createNotification("Aplication ",e.Message);
            }




            createNotification("Aplication ",   nombre +textoEstatus);
            return;
        }

        createNotification("Unknown message details", msg.ToString());
    }

当应用程序关闭时,您无法从
Application.Current.Properties[key]
读取数据,相反,您可以使用来存储数据
SharePreferences
是Android中的一种机制,用于存储一些简单的配置信息,使用地图数据结构来存储数据,以
键值
对存储,并以
XML
格式存储数据

创建的存储文件保存在
/data/data//shares\u prefs
文件夹下。因此,即使用户关闭应用程序,
SharedReferences
中的数据也将保持不变


是一个关于如何在Xamarin.Android中使用SharePreferences的文档。

顾名思义,这个GcmService是一个服务,无论应用程序的状态如何,OnMessage方法都将被执行。。。这样想这个问题毫无意义。。。你在考虑这种服务行为吗?不,我的问题很清楚。如何访问Xamarin表单属性中的数据。我说,目前还没有这样明显的应用程序,但事实并非如此。我的问题是关于你访问数据的另一种方式。可能是一个路径文件或另一个仅适用于andriod但不适用于IOS的库,具有xamarin表单如何访问xamarin表单属性?我不熟悉IOS,您可以打开一个新线程来问这个问题。:)