You are here: Forum Home → ANT Developers Forums → ANT in Mobile Phones → Thread
public class BootReceiver extends BroadcastReceiver {
Context c;
/*
* (non-Javadoc)
*
* @see android.content.BroadcastReceiver#onReceive(android.content.Context,
* android.content.Intent)
*/
@Override
public void onReceive(final Context context, Intent intent) {
final String TAG = BootReceiver.class.getSimpleName();
Intent antService = new Intent();
antService.setAction("de.tum.lme.diamantum.ANTRadioService");
antService.putExtra("callerId", "BootReceiver");
if (Intent.ACTION_SHUTDOWN.equals(intent.getAction())) {
Log.d("Bootreceiver", "Shut down initiated");
context.stopService(antService);
Log.d(TAG, "Stopped Service");
}
if (Intent.ACTION_BOOT_COMPLETED.equals(i[code]
private AntInterface.ServiceListener listener = new AntInterface.ServiceListener() {
@Override
public void onServiceConnected() {
// Service ist verbunden
Log.d(TAG, "ServiceListener onServiceConnected()");
// boolean mServiceConnected = true;
try {
boolean mClaimedAntInterface = mAntAdapter
.hasClaimedInterface();
if (mClaimedAntInterface) {
// mAntMessageReceiver should be registered any time we have
// control of the ANT Interface
receiveAntRxMessages(true);
} else {
// Need to claim the ANT Interface if it is available, now
// the service is connected
mClaimedAntInterface = mAntAdapter.claimInterface();
}
} catch (Throwable e) {
// irgendwas ist total schief gelaufen
// wird aber auch angezeigt
error_message(e.toString());
}
Log.d(TAG, "ANT Service connected");
Log.d(TAG, "enabling ANT");
// try {
// mAntAdapter.ANTResetSystem();
// } catch (AntInterfaceException e) {
// // TODO Auto-generated catch block
// error_message(e.toString() + "RESET");
// }
// Aktiviere AntInterface
try {
mAntAdapter.enable();
} catch (AntInterfaceException e) {
// TODO Auto-generated catch block
error_message(e.toString() + "ENABLE");
}
}
@Override
public void onServiceDisconnected() {
// Service ist nicht verbunden
Log.d(TAG, "ServiceListener onServiceDisconnected()");
try {
receiveAntRxMessages(false);
} catch (IllegalArgumentException e) {
// Receiver wasn't registered, ignore as that's what we wanted
// anyway
}
}
};