我使用Xamarin Android进行开发我得到App Crashes错误电话或模拟器启动后。 网上的其他类似帖子对我没有帮助。
这是我的机器人清单:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<service android:name=".sobhanService" android:exported="true" />
<application android:icon="@drawable/Icon" android:label="donya">
<receiver android:enabled="true" android:exported="true" android-permission="android.permission.RECEIVE_BOOT_COMPLETED" android:name=".StartReceiver" android:label="StartReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
</manifest>
我的StartReceiver类:
[BroadcastReceiver(Enabled=true)]
[IntentFilter(new[] { Intent.ActionBootCompleted, Intent.ActionScreenOn })]
public class StartReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
Toast.MakeText(context, "Action Boot Completed!", ToastLength.Long).Show();
Intent serviceStart = new Intent(context, typeof(SobhanService));
serviceStart.AddFlags(ActivityFlags.NewTask);
context.StartService(serviceStart);
}
}
我的SobhanService:
[Service(Label = "SobhanService")]
[IntentFilter(new String[] { "com.yourname.SobhanService" })]
public class SobhanService : IntentService
{
IBinder binder;
protected override void OnHandleIntent(Intent intent)
{
Schedule_GPS();
Schedule_Notification();
}
private void Schedule_GPS()
{
try
{
AlarmManager am = (AlarmManager)GetSystemService(Context.AlarmService);
Intent intent = new Intent(this, typeof(Send_Username));
PendingIntent pi = PendingIntent.GetBroadcast(this, 0, intent, PendingIntentFlags.UpdateCurrent);
long interval = 30000;
long triggerTime = SystemClock.ElapsedRealtime() + interval;
am.SetInexactRepeating(AlarmType.RtcWakeup, triggerTime, interval, pi);
//
}
catch { }
}
private void Schedule_Notification()
{
try
{
AlarmManager am = (AlarmManager)GetSystemService(Context.AlarmService);
Intent intent1 = new Intent(this, typeof(Notification));
PendingIntent pi1 = PendingIntent.GetBroadcast(this, 0, intent1, PendingIntentFlags.UpdateCurrent);
long interval1 = 30000;
long triggerTime1 = SystemClock.ElapsedRealtime() + interval1;
am.SetInexactRepeating(AlarmType.RtcWakeup, triggerTime1, interval1, pi1);
}
catch { }
}
public override IBinder OnBind(Intent intent)
{
try
{
binder = new SobhanServiceBinder(this);
return binder;
}
catch { return binder; }
}
public class SobhanServiceBinder : Binder
{
readonly SobhanService service;
public SobhanServiceBinder(SobhanService service)
{
this.service = service;
}
public SobhanService GetSobhanService()
{
return service;
}
}
}
}
我已经安装了一个用于记录Android事件的logCat应用程序但它在模拟器中无法正常工作。 非常感谢你