Tag: xamarin.android

如何在Xamarin.Android中正确编写自定义UncaughtExceptionHandler

我想要实现的只是捕获我的应用程序上的exception,以便我可以将它们发送到服务器。 我想通过在StackOverflow中回答Java中的原生Android代码编写我的自定义UncaughtExceptionHandler ,我可以做到这一点。 这是我的CustomExceptionHandler类: public class CustomExceptionHandler : Thread.IUncaughtExceptionHandler { public IntPtr Handle { get; private set; } public CustomExceptionHandler(Thread.IUncaughtExceptionHandler exceptionHandler) { Handle = exceptionHandler.Handle; } public void UncaughtException(Thread t, Throwable e) { // Submit exception details to a server … // Display error message for local debugging purposes Debug.WriteLine(e); } public void Dispose() { […]

在Xamarin.Forms中编写设备平台特定代码

我有以下Xamarin.Forms.ContentPage类结构 public class MyPage : ContentPage { public MyPage() { //do work to initialize MyPage } public void LogIn(object sender, EventArgs eventArgs) { bool isAuthenticated = false; string accessToken = string.Empty; //do work to use authentication API to validate users if(isAuthenticated) { //I would to write device specific code to write to the access token […]

Xamarin AlarmManager Android

我已经创建了一个快速的xamarin android项目。 最后我想学习下面的学习并将它应用到android和ios之间共享的xamarin表单项目中。 现在我只关注Android方面的事情。 我一直在努力学习如何安排本地通知在将来的某个时间出现。 快速扔掉应用程序,下面是我编写的AlarmReceiver类,以及下面的MainActivity.cs。 class AlarmReceiver : BroadcastReceiver { public override void OnReceive(Context context, Intent intent) { var message = intent.GetStringExtra(“message”); var title = intent.GetStringExtra(“title”); var notIntent = new Intent(context, typeof(MainActivity)); var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent); var manager = NotificationManager.FromContext(context); //Generate a notification with just short text and small icon var […]

Xamarin Android Alarm Manager问题

我的Xamarin Android应用程序中有一个AlarmManager 。 我使用SetExact()以5分钟的时间配置它。 但它只在五秒后开始。 无论我何时配置它,它总是在5秒后触发。 我在Java中使用了完全相同的代码,它工作得很好。 代码: [BroadcastReceiver] public class AlarmReceiver : BroadcastReceiver { public override void OnReceive(Context context, Intent intent) { Log.Info(“AlarmReceiver”, “Triggered”); } public static void Start(Context context, long triggerAfterMilis) { var type = AlarmType.RtcWakeup; var alarmManager = (AlarmManager) context.GetSystemService(Context.AlarmService); var timerIntent = PendingIntent.GetBroadcast(context, 0, new Intent(context, typeof(AlarmReceiver)), PendingIntentFlags.CancelCurrent); alarmManager.Cancel(timerIntent); if (Build.VERSION.SdkInt […]