【发布时间】:2017-06-12 16:12:01
【问题描述】:
我可以使用 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());
}
【问题讨论】:
-
这个GcmService,顾名思义,是一个服务,不管应用状态如何,都会执行OnMessage方法……这样想问题没有意义……你在考虑这种服务行为?
-
不,我的问题很清楚。如何访问 Xamarin 表单属性中的数据。我说没有当前的应用程序,所以显然不是这样。我的问题是关于访问该数据的另一种方式。可能是路径文件或其他库
标签: xamarin.android xamarin.forms