Saturday 5 April 2014

Android change Background color on Action Bar

1. Add Action Bar to your project.

2. Open the ActivityMain.java file and add the below imports to the imports section.

    import android.app.ActionBar;
    import android.graphics.drawable.ColorDrawable;

3. Then, in the ActivityMain.java file add the below to the onCreate method.

           ActionBar ab = getActionBar(); 
ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#81a3d0"));     
          ab.setBackgroundDrawable(colorDrawable);

4. Determine the Hex color you would like and update the Color.parColor above to your specific color.

Friday 4 April 2014

Capture Speech/Voice Input for Google Glass

This tutorial will walk you through the steps and code snippets for capturing user speech/voice input in your GDK based Glassware.
Step 1:
Create an Android project as shown below. If you haven’t tried installing any sample Glassware on your Google Glass, please visit this tutorial.
Create an Android Project
Create an Android Project
Step 2:
Create an Android Activity and edit the AndroidManifest.xml as shown below:
<activity
android:name=”com.example.capturespeechinput.MainActivity”
android:label=”@string/app_name” >
<intent-filter>
<action android:name=”android.intent.action.MAIN” />
<action android:name=”com.google.android.glass.action.VOICE_TRIGGER” />
<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
<meta-data
android:name=”com.google.android.glass.VoiceTrigger”
android:resource=”@xml/voice_trigger_start” />
</activity>
Step 3:
Now, create a folder called xml under res and create an xml file called voice_trigger_start.xml.
Paste the following content inside:
<?xml version=”1.0″ encoding=”utf-8″?>
<trigger keyword=”Capture Speech” >
         <input prompt=”Speak now!” />
</trigger>
Step 4:
Edit the activity_main.xml (Your activity’s layout page) to include a TextView with the id – ‘capturedSpeechToText’ as follows:
<TextView
android:id=”@+id/capturedSpeechToText”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”" />
Step 5:
Edit your MainActivity Java Class to include the following code snippet to captured the spoken text in the onCreate() method:
ArrayList<String> voiceResults = getIntent().getExtras().getStringArrayList(RecognizerIntent.EXTRA_RESULTS);
if (voiceResults != null && voiceResults.size() > 0) {
String spokenText = voiceResults.get(0);
TextView capturedSpeechToTextViewObj = ((TextView) findViewById(R.id.capturedSpeechToText));
capturedSpeechToTextViewObj.setText(spokenText);
}
Step 6:
Now, build and deploy the Android application on to your Google Glass and enjoy the output:
Capture Speech - Launch Application
Capture Speech – Launch Application
Voice Prompt - Speak Now
Voice Prompt – Speak Now
Voice Input for Google Glass
Voice Input for Google Glass
Voice captured in your GDK Application
Voice captured in your GDK Application

ANDROID 4.4 – KITKAT – STEP DETECTOR CODE

One of the new features in Android 4.4, KitKat is the “Step Counter” and “Step Detector” sensors.

I hope this example will be good enough and helpful in getting started with new Step related features on Android 4.4. 
Step 1: Create SensorEventListener

public class MainActivity extends Activity implements SensorEventListener{



private TextView textView;

private SensorManager mSensorManager;

private Sensor mStepCounterSensor;

private Sensor mStepDetectorSensor;


Step 2: Get SensorManager and Step Sensors

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.textview);

mSensorManager = (SensorManager)        
            getSystemService(Context.SENSOR_SERVICE);
mStepCounterSensor = mSensorManager
  .getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
mStepDetectorSensor = mSensorManager
  .getDefaultSensor(Sensor.TYPE_STEP_DETECTOR);
}

Step 3: Implement SensorEventListener.onSensorChanged  method

public void onSensorChanged(SensorEvent event) {
Sensor sensor = event.sensor;
float[] values = event.values;
int value = -1;
 
     if (values.length > 0) {
value = (int) values[0];
}

if (sensor.getType() == Sensor.TYPE_STEP_COUNTER) {
textView.setText("Step Counter Detected : " + value);
} else if (sensor.getType() == Sensor.TYPE_STEP_DETECTOR) {
  // For test only. Only allowed value is 1.0 i.e. for step taken
         textView.setText("Step Detector Detected : " + value);
}
}


Step 4: Register and Unregister Sensors

 protected void onResume() {

super.onResume();

     mSensorManager.registerListener(this, mStepCounterSensor,

SensorManager.SENSOR_DELAY_FASTEST);  
     mSensorManager.registerListener(this, mStepDetectorSensor,

SensorManager.SENSOR_DELAY_FASTEST);

}

 protected void onStop() {
super.onStop();
mSensorManager.unregisterListener(this, mStepCounterSensor);
mSensorManager.unregisterListener(this, mStepDetectorSensor);
}

Step 5: Update Android Manifest configuration for these new features
    
    res/values/strings.xml:

  <string name="step_counter">
         android.hardware.sensor.stepcounter
   </string>

   
<string name="step_detector">
         android.hardware.sensor.stepdetector
   </string>

    AndroidManifest.xml

    <uses-feature 
          android:name="@string/step_detector" android:required="false"/>
    
    <uses-feature 
           android:name="@string/step_counter" android:required="false"/>


 Step 6: Test run your simple pedometer application




Step 7: Your Homework : Extend and customize your application by managing step sensor data as per your ideas

Wednesday 2 April 2014

5 things every beginning Android app developer should know

The world has entered a mobile age, and the app industry is booming as a result. Worth $53 billion in 2012, the global app economy is expected to grow to $143 billion by 2016. Everyone wants a piece of the digital pie, but few mobile app developers are armed with the facts.
Every app is just one drop in the vast ocean of the app store. If you want to stand out and have a chance of building a profitable user base, there are a few things you should know before you begin development:

1. Imitation is not always the sincerest form of flattery

If your product is good, people will copy you. The better it is, the likelihood of being ripped off increases exponentially. This is a multi-industry reality and it’s the first thing you should keep in mind as you develop your mobile app.
If you know you have an excellent product in the works, a strong launch is critical. The initial loyal user base you attract as a result of high visibility will help you stay on top when the imitators eventually end up publishing similar products.
The more active users you have, the better your app holds its ground in the store. Additionally, those are the users who convert to paying customers.

2. It is far too easy to get lost in the crowd

One of the biggest challenges mobile app developers face is discoverability. With more than a million mobile apps in each of the app stores (Apple and Android), it is becoming harder and harder to generate organic users.
To overcome this, you should plan on putting time and effort into app store optimization techniques. The app name, icon, description and screenshots – all of these need high attention and professional care to reach the best results.
Invest time and money to produce a unique presentation of your app before it is downloaded to grab the attention and pique the interest of users.

3. You don’t have to play by the rules to go viral

When it comes to distribution, developers often think the only path to topping the charts is through organic results. This is usually not the case! Going viral is rare, so developers should not be shy about opening their pockets and buying some downloads.
Set a budget and contact a solid network, target your audience, and get those users. This is particularly crucial for your launch to ensure a strong start.
Another area in which to exercise a bit of creativity is monetization. Do not be fearful of trying new monetization solutions. Far too many mobile app developers “settle” for the generic solution of placing a flat, boring banner in their ad because they feel it’s the only solution. Wrong! Get your creative juices flowing to come up with an innovative solution.
For example, users are far more tolerant of in-app advertising than you may think, particularly if your app is well-made and solves a problem for them, or even provides a few moments of fun.
A well-integrated, well-timed full-page ad, app wall, or video can generate revenue in a way that compliments the app experience rather than damaging or distracting from the experience.

4. There is a best time to launch your mobile app

You’ve probably heard the expression, “Good things come to those who wait.” This is especially true when it comes to choosing the right moment to launch your mobile app.
If you are accustomed to publishing on the Web, toss everything you know out the window, because the best times to publish mobile apps are during the summer and the December holidays. People are on the road and glued to their devices. Use this to your advantage and plan to boost your app just before the holidays for a massive wave of fresh users.

5. The new kids on the block are the most popular

Before you release your app, ask yourself the question, “What problem does this app solve?” Why will users be attracted to it? There are plenty of strange viral app sensations out there. They end up topping the charts but do not frequently last. The apps with staying power are the ones addressing a need in the lives of their users.
When people say, “I wish there was an app for that” and a search reveals your app, this generates excitement. Further, everyone loves being “the first” to know about a cool new product so they can tell their friends and colleagues about it. This can only help your user base grow.
What do you think? What are the things you take into consideration as you develop new mobile apps?