Friday, May 8, 2015

SIP call flow generator

trying to run the cmake gave the below error:

-bash: cmake: command not found 

Install the cmake using port. 

sudo port cmake

then entered cmake … 

it shown below.

-- *** Will build version 20110914-160 ***
-- Configuring done
-- Generating done
-- Build files have been written to: /Users//Desktop/r/callflow-20120624-180/build

then the below command 

sudo make install

when trying to run, it was failing with the below error. 

callflow: error: setup directory "/usr/local/callflow" does not exist
Adjust your configuration

Found the links mentioned in the reference. 

sudo mkdir /usr/local/callflow

trying to run again 

h$ callflow pre-15050101.pcap
getopt: illegal option -- l
getopt: illegal option -- g
Terminating...

gave the terminating. 


References:

Wednesday, May 6, 2015

Android Battery Charging Status and broadcast


Below code can be used to query the battery status. This uses a sticky intent concept. 

        IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
        Intent batteryStatus = registerReceiver(null, ifilter);

        // Are we charging / charged?
        int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
        boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
                status == BatteryManager.BATTERY_STATUS_FULL;

        Log.v(LOG_TAG,"Charging status is :"+status);
        // How are we charging?
        int chargePlug = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
        boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
        boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;

        Log.v(LOG_TAG,"Charging Via :"+chargePlug);

        Intent batteryLevelIntent = new Intent(BROADCAST_ACTION);
        batteryLevelIntent.putExtra("chargingStatus",status);
        batteryLevelIntent.putExtra("chargingVia",chargePlug);
        batteryLevelIntent.putExtra("statusQueried",true);

        LocalBroadcastManager.getInstance(AppUtils.getAppContext()).sendBroadcast(intent);


Same thing can be done inside an intent receive method. We need to add below to the AndroidManifest xml file 

android:name=".sensors.PowerConnectionReceiver">
           
                android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
                android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/>
           
       

References:

Tuesday, May 5, 2015

Android Battery Charging Status and broadcast


Below code can be used to query the battery status. This uses a sticky intent concept. 

        IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
        Intent batteryStatus = registerReceiver(null, ifilter);

        // Are we charging / charged?
        int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
        boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
                status == BatteryManager.BATTERY_STATUS_FULL;

        Log.v(LOG_TAG,"Charging status is :"+status);
        // How are we charging?
        int chargePlug = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
        boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
        boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;

        Log.v(LOG_TAG,"Charging Via :"+chargePlug);

        Intent batteryLevelIntent = new Intent(BROADCAST_ACTION);
        batteryLevelIntent.putExtra("chargingStatus",status);
        batteryLevelIntent.putExtra("chargingVia",chargePlug);
        batteryLevelIntent.putExtra("statusQueried",true);

        LocalBroadcastManager.getInstance(AppUtils.getAppContext()).sendBroadcast(intent);


References:

Monday, May 4, 2015

SIPp making REGISTER work

My Intention mainly was to test an INVITE. But after installation, found that the simulation XML was not in the test suite. 

So, created one like this 

"1.0" encoding="ISO-8859-1" ?>
"sipp.dtd">

name="REGISTER without authentication">
    
   
    request="REGISTER" />
    <![CDATA[
        
        SIP/2.0 200 OK
        [last_Via:]
        [last_From:]
        [last_To:];tag=[call_number]
        [last_Call-ID:]
        [last_CSeq:]
        Contact:
        Content-Length: 0
        Expires: 3600
        
    ]]>
   

After having the above, the SIPP was started like this below. 

./sipp -sf sipp_register_no_auth.xml -t t1

after running the client app and the REGISTER was successful. The screen showed like below. 



Tutorial in below reference section was helpful to get an idea. 

References:

Saturday, May 2, 2015

Android Detecting Screen orientation

Below code works magnificiently for detecting whether the Activity is in portrait or landscape orientation

 public static int getScreenOrientation(Activity activity) {
        int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
        int orientation = activity.getResources().getConfiguration().orientation;
        if (orientation == Configuration.ORIENTATION_PORTRAIT) {
            if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_270) {
                return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
            } else {
                return ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
            }
        }
        if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
            if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) {
                return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
            } else {
                return ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
            }
        }
        return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
    }

references:

Android speech to text Avoiding Google native Popup.

Normally, below what can be used to bring up the native speech recogniser window. 
 Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
                "Say Something!");
        try {
            ((Activity)getAppContext()).startActivityForResult(intent, 100);
        } catch (ActivityNotFoundException a) {
            Toast.makeText(getAppContext(),
                    "Sorry Speech to text is not supported",
                    Toast.LENGTH_SHORT).show();
        }

However, this above brings up the native popup. To avoid this, below technique can be used 

        speechRecognizer = SpeechRecognizer.createSpeechRecognizer(AppUtils.getAppContext());
        speechRecognizer.setRecognitionListener(new SpeechRecognizerListener());

        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,"livingmobile.com.eome");

        intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,5);
        speechRecognizer.startListening(intent);


public class SpeechRecognizerListener implements RecognitionListener {
    public void onResults(Bundle results)
    {
        String str = new String();
        Log.d(LOG_TAG, "onResults " + results);
        ArrayList data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < data.size(); i++)
        {
            Log.d(LOG_TAG, "result " + data.get(i));
            buffer.append(data.get(i));
            buffer.append(",");

        }
        Toast.makeText(AppUtils.getAppContext(), buffer.toString(), Toast.LENGTH_SHORT).show();
    }
}

References

Friday, May 1, 2015

Android Ambient Light Sensing


In Android, Ambient Light Sensing is pretty much straight forward. Below is the code to achieve this. Also including some of the experiences in testing this out with the real hardware , my Android One phone. 

android.hardware.SensorManager sensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
        if(sensorManager != null) {
            Sensor lightSensor
                    = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
            if (lightSensor == null){
                Log.v(LOG_TAG,"light sensor is null!");
            }else{
                float max =  lightSensor.getMaximumRange();
                Log.v(LOG_TAG,"Max light range is :"+max);
                sensorManager.registerListener(lightSensorEventListener,
                        lightSensor,
                        SensorManager.SENSOR_DELAY_NORMAL);

            }
        }
        else
        {
            Log.v(LOG_TAG,"Sensor manager is null during create");
        }

SensorEventListener lightSensorEventListener
            = new SensorEventListener(){

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onSensorChanged(SensorEvent event) {
            // TODO Auto-generated method stub
            if(event.sensor.getType()==Sensor.TYPE_LIGHT){
                final float currentReading = event.values[0];
                Log.v(LOG_TAG,"Current reading from light sensor is :"+currentReading);
            }
        }

    };


Based on experience, few points below 

- During day light, the onSensorChanged call back get called frequently with values > 70 
- When there is no light, the value becomes < 10

References: