‏הצגת רשומות עם תוויות andriod. הצג את כל הרשומות
‏הצגת רשומות עם תוויות andriod. הצג את כל הרשומות

יום ראשון, 27 באפריל 2014

Generating ndk h files using Eclipse

I  found that the best way to generate Android ndk h file is by using Eclipse extended tools options.
By using the following properties dialog run -> external tools -> external tools configuration ,we can declare an external tool that generate the native h files .
Capture5 
-classpath  "${project_classpath};C:\DevTools\Android\adt-bundle-windows-x86-20131030\sdk\platforms\android-19\android.jar" ${java_type_name}

 I found it beater to declare the pathes hard coded .
Capture6
Capture7 
The result:
Capture8
Resources:
The book:Pro Android C++ with the NDK by Onur Cinar



יום שישי, 25 באפריל 2014

Android AsyncTask

The following is a sample of using Android AsyncTask .
 
Part of the main activity that's call to start or cancel the AsyncTask .

 final Button TestAsyncTaskBtn = (Button) findViewById(R.id.TestAsyncTask);
        
        TestAsyncTaskBtn.setOnClickListener(new View.OnClickListener() {
	        @Override
	        public void onClick(View v) {
	        	
	        	
	        	mTheAsyncTask = new PlayWithAsyncTask(MainActivity.this);
	        	
	        	mTheAsyncTask.execute("Zvika" , "MS");	        	
	        	
	        }
        });
        
    final Button CancelAsyncTaskBtn = (Button) findViewById(R.id.CancelTestAsyncTask);
    
    
    CancelAsyncTaskBtn.setOnClickListener(new View.OnClickListener() {
	        @Override
	        public void onClick(View v) {
	        
	        	if ( mTheAsyncTask != null )
	        	{
	        		if ( mTheAsyncTask.isCancelled() == false )
	        		{
	        			mTheAsyncTask.cancel(true);
	        		}	
	        	}
	        	
	        }
        });

The AsyncTask extender


package com.example.testapis;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.util.Log;
public class PlayWithAsyncTask extends AsyncTask <String , String , String >{
	private int mCount = 0 ;
	private ProgressDialog mProgress;
	private Activity mCallingActivity ;
	public PlayWithAsyncTask(Activity pCallingActivity ) {
		super();
		mCallingActivity = pCallingActivity;
	}
	
	@Override
	  protected void onPreExecute()
	  {
		mProgress = new ProgressDialog (mCallingActivity);
		
		mProgress.setCancelable(true);
		
		mProgress.setTitle("Waiting for action!!!");
		mProgress.setMessage("Before start");
		mProgress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
		mProgress.setProgress(0);
		
		mProgress.setMax(30);
		
		mProgress.show();
		
	  }
	
	@Override
	protected String doInBackground(String... arg0) 
    {	
    	Log.i ("PlayWithAsyncTask" , "The data: " + arg0[0]);
    	
		while (  mCount < 30 )
		{
		
			try {
				Thread.sleep(100);
				publishProgress ( Integer.toString(mCount));
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				Log.i ("PlayWithAsyncTask" , e.toString());
			}
			
			mCount ++;
		}
		
		return "Count until:" + Integer.toString(mCount);
	}
	@Override
	 protected void onPostExecute(String pResult )
	 {
		Log.w("PlayWithAsyncTask ",  " The execute result: " + pResult);
		
		mProgress.dismiss();
	 }
	
	@Override
	protected void onCancelled() 
	{
		Log.i ("PlayWithAsyncTask" , "onCancelled was called ");
	
		mProgress.dismiss();
	}
	@Override
	protected void onProgressUpdate(String... pvalues)				   	
	{
		mProgress.setMessage("" + pvalues[0]);
		
		mProgress.incrementProgressBy(1);
		
		Log.w("PlayWithAsyncTask",  " - the Progress - " + pvalues[0]);
	}
	
}

The result 
Capture2



Note :
The AsyncTask template contains 3 type parameters :
Params, the type of the parameters sent to the task upon execution.
Progress, the type of the progress units published during the background computation.
Result, the type of the result of the background computation.

from http://developer.android.com/reference/android/os/AsyncTask.html

יום שבת, 22 ביוני 2013

Deploy android application to device in eclipse

1.Start the device and In developer settings select the clean bugs using USB
2.Connect the device using usb
3.Test device existence and connation using:
C:\devtools\Android\adt-bundle-windows-x86\sdk\platform-tools>adb devices.
Capture39

4.Open the Run->Run configuration dialog
5.Change to :Always prompt to pick device

Capture40

Start debugging your application.
Resources:
http://www.mkyong.com/android/android-debugging-on-real-device/

יום שני, 3 ביוני 2013

Getting USB device Interfaces

 

The following code is part of the MissileLauncherActivity of the MissileLauncher api Demo.
The onResume method
The onResume method may be called due to intend invocation caused by the USB device plugin or disconnecting.
The method retrieve the UsbDevice object from the calling intend data. the USBDevice Repents a connected USB device and contains methods to access its identifying information, interfaces, and endpoints. .

  1:     @Override
  2:     public void onResume() {
  3:         super.onResume();
  4:         mSensorManager.registerListener(mGravityListener, mGravitySensor,
  5:                 SensorManager.SENSOR_DELAY_NORMAL);
  6: 
  7:         Intent intent = getIntent();
  8:         Log.d(TAG, "intent: " + intent);
  9:         String action = intent.getAction();
 10: 
 11:         UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
 12:         if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
 13:             setDevice(device);
 14:         } else if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
 15:             if (mDevice != null && mDevice.equals(device)) {
 16:                 setDevice(null);
 17:             }
 18:         }
 19:     }

The setDevice method
The setDevice method tries to pitch the USB interface out of the usbdevice and tries to fetch the USB interface type interrupt  out of this endpoint.
The method tries to open connection to the device using the UsbManager.

  1:  private void setDevice(UsbDevice device) {
  2:         Log.d(TAG, "setDevice " + device);
  3:         if (device.getInterfaceCount() != 1) {
  4:             Log.e(TAG, "could not find interface");
  5:             return;
  6:         }
  7:         UsbInterface intf = device.getInterface(0);
  8:         // device should have one endpoint
  9:         if (intf.getEndpointCount() != 1) {
 10:             Log.e(TAG, "could not find endpoint");
 11:             return;
 12:         }
 13:         // endpoint should be of type interrupt
 14:         UsbEndpoint ep = intf.getEndpoint(0);
 15:         if (ep.getType() != UsbConstants.USB_ENDPOINT_XFER_INT) {
 16:             Log.e(TAG, "endpoint is not interrupt type");
 17:             return;
 18:         }
 19:         mDevice = device;
 20:         mEndpointIntr = ep;
 21:         if (device != null) {
 22:             UsbDeviceConnection connection = mUsbManager.openDevice(device);
 23:             if (connection != null && connection.claimInterface(intf, true)) {
 24:                 Log.d(TAG, "open SUCCESS");
 25:                 mConnection = connection;
 26:                 Thread thread = new Thread(this);
 27:                 thread.start();
 28: 
 29:             } else {
 30:                 Log.d(TAG, "open FAIL");
 31:                 mConnection = null;
 32:             }
 33:          }
 34:     }

Sources
http://developer.android.com/guide/topics/connectivity/usb/host.html

יום שבת, 1 ביוני 2013

Controlling the USB FX device from Android tablet

In order to control a usb device I used the USB host api I started to learn the topic using the android missilelauncher demo .

Changing the device_filter.xml file to describe the USB FX2 device.

  1: <resources>
  2:     <usb-device vendor-id="1351" product-id="4098" />
  3: </resources>
  4: 

I want to get a callback notification when  the USB FX 2 device get connected to the android device.


Add to the manifest


  1: <intent-filter>
  2:   <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
  3: </intent-filter>
  4: <intent-filter>
  5:  <action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
  6: </intent-filter>
  7: <meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
  8:     android:resource="@xml/device_filter" />
  9: <meta-data android:name="android.hardware.usb.action.USB_DEVICE_DETACHED"
 10:     android:resource="@xml/device_filter" />

Register the broadcast activities in the onCreate method


  1: //register for USBFX2 attachment
  2: IntentFilter attachedFilter = new IntentFilter(UsbManager.ACTION_USB_DEVICE_ATTACHED);     
  3: IntentFilter detachedFilter = new IntentFilter(UsbManager.ACTION_USB_ACCESSORY_DETACHED);
  4: registerReceiver(mUsbFX2AttachedReceiver, attachedFilter);
  5: registerReceiver(mUsbFX2AttachedReceiver, detachedFilter);

declaring the BroadcastReceiver for the attached and detached events:


  1: private final BroadcastReceiver mUsbFX2AttachedReceiver = new BroadcastReceiver()
  2:     {
  3:     @Override
  4:     public void onReceive(Context context, Intent intent)
  5:         {
  6:        String action = intent.getAction();
  7:       
  8:          if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
  9:         Toast.makeText(context, "UsbFX2 has connected", Toast.LENGTH_SHORT).show();                  
 10:          }
 11:          if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
 12:            Toast.makeText(context, "UsbFX2 has detached", Toast.LENGTH_SHORT).show();                  
 13:          }
 14:         }
 15:     };

Sources:


http://stackoverflow.com/questions/11191835/receive-intent-action-usb-device-attached-through-code
http://www.ezequielaceto.com.ar/techblog/?p=396 
http://developer.android.com/guide/topics/connectivity/usb/host.html
http://stackoverflow.com/questions/11638216/how-to-make-an-basic-android-usb-host-application