Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

Android simple ANT+ App

Avatar
Rank

Total Posts: 6

Joined 0

PM

Hi,

I try to make a simple app which only sends a message to a PC with a dongle. Just to know everything is working:

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(channelNumberdeviceNumberdeviceTypeTransmissionType);
                            
mAntReceiver.ANTSetChannelPeriod(channelNumberperiod);
                            
mAntReceiver.ANTSetChannelRFFreq(channelNumberfreq);                           
                            
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);
        
}
        
        
    }


What is wrong?      
Avatar
RankRank

Total Posts: 39

Joined 2011-06-29

PM

I took your code and got a SecurityException when I ran it. As described in the Creating ANT+ Android Applications document, your app needs to use the ANT permissions:

<uses-permission android:name="com.dsi.ant.permission.ANT" >
<uses-permission android:name="com.dsi.ant.permission.ANT_ADMIN" >

With that added addition I was able to pick up the phone on ANTware