You are here: Forum Home → ANT Developers Forums → ANT in Mobile Phones → Thread
public class ANTsend extends Activity {
/** Called when the activity is first created. */
String TAG = "ANTsend";
AntInterface mAntReceiver;
AntInterface.ServiceListener mAntServiceListener;
byte channelNumber = 1;
short deviceNumber = 33;
byte deviceType = 1;
byte TransmissionType = 1; // Set to 0 for wild card search
byte network = 1;
short period = 8192;
byte freq = 57; // 2457Mhz (ANT+ frequency)
byte[] txBuffer;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.d(TAG, "GO");
mAntReceiver = new AntInterface();
AntInterface.ServiceListener mAntServiceListener = new AntInterface.ServiceListener(){
public void onServiceConnected() {
Log.d(TAG, "onConnected");
try
{
Log.d(TAG, "try1");
mAntReceiver.enable();
mAntReceiver.claimInterface();
}
catch (AntInterfaceException e){
Log.e(TAG, "FAIL: can not enable or/and claim ANT");
}
try {
if(mAntReceiver.hasClaimedInterface()){
try
{
Log.d(TAG, "try2");
mAntReceiver.ANTAssignChannel(channelNumber,AntDefine.PARAMETER_TX_NOT_RX,network);
mAntReceiver.ANTSetChannelId(channelNumber, deviceNumber, deviceType, TransmissionType);
mAntReceiver.ANTSetChannelPeriod(channelNumber, period);
mAntReceiver.ANTSetChannelRFFreq(channelNumber, freq);
mAntReceiver.ANTOpenChannel(channelNumber);
}
catch (AntInterfaceException e){
Log.e(TAG, "FAIL: can not assign the channel");
}
try
{
Log.d(TAG, "try3");
txBuffer = new byte[8];
mAntReceiver.ANTTxMessage(txBuffer);
Log.d(TAG,"TX:"+txBuffer);
}
catch (AntInterfaceException e){
Log.e(TAG, "FAIL: can not send");
}
}
} catch (AntInterfaceException e) {
Log.e(TAG, "FAIL: the BIG one!!!");
}
}
public void onServiceDisconnected() {
// TODO generated method stub
}
};
if(AntInterface.hasAntSupport(this));
{
Log.d(TAG, "has support");
mAntReceiver.initService(this.getApplicationContext(), mAntServiceListener);
}
}
}