Я хочу запустить сервис по включению/выключению Bluetooth. Но я столкнулся с некоторыми проблемами. Вот несколько вещей. Здесь нет манифеста:BroadcastReceiver не найден в манифесте
<application android:label="JustAnyLabel">
<receiver android:name=".MyBroadcastReceiver">
<intent-filter>
<action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
</intent-filter>
</receiver>
</application>
Вот BroadcastReceiver:
public class MyBroadcastReceiver : BroadcastReceiver
{
private Intent theServiceIntent;
public MyBroadcastReceiver() : base()
{}
public override void OnReceive (Context context, Intent intent)
{
string action = intent.Action;
if (action.Equals (BluetoothAdapter.ActionStateChanged))
{
int state = intent.GetIntExtra (BluetoothAdapter.ExtraState, BluetoothAdapter.Error);
bool bluetoothEnabled = BluetoothAdapter.DefaultAdapter.IsEnabled;
switch (bluetoothEnabled)
{
case false:
if(theServiceIntent != null)
{
context.StopService (theServiceIntent);
theServiceIntent = null;
}
break;
case true:
if(theServiceIntent == null)
{
theServiceIntent = new Intent (context, typeof(TheService));
context.StartService (theServiceIntent);
}
break;
}
}
}
}
А вот ошибка:
Так в основном, мой класс не был найден, и у меня нет идея почему. Любая помощь будет оценена по достоинству.
Спасибо.
MyBroadcastReceiver - это класс java? –
нет, я использую Xamarin Studio, поэтому все его C# :) –
, тогда вы не знаете, как объявить класс в андроиде? –