Tuesday, December 20, 2011

Google TV a Smarter way Of Viewing TV

Hi ,


Today I have started my new application for Google tv on Android platform.
its very intresting .
To develop the applications on google tv we need to have the Android Sdk Api level 12 ,eclipse with Addon of google tv and Linux Platform with KVM.


Google TV a new experience that combines TV, the entire web, and apps as well as a way to search across them all. It is a software platform that is pre-installed on a TV or buddy box that connects to a TV.
Google TV is driving innovation with an open platform strategy that integrates seamlessly with existing cable, satellite, terrestrial, or IPTV subscriptions to enhance the television-viewing experience. Google TV is built on Android and Chrome platforms that provide a scalable way to bring your apps to TV.
To Learn More Follow the link.

Tuesday, November 22, 2011

How to Kill The Application



1) KILLING THE TASKS  AND KEEPS THE APPLICATION PACKAGE TO RESTART
      ActivityManager am = (ActivityManager) Tracking.this.getSystemService(ACTIVITY_SERVICE);
      List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
     ComponentName componentInfo = taskInfo.get(0).topActivity;
     am.restartPackage(componentInfo.getPackageName());
 
2) Calling Home   Activity
    
    Intent in = new Intent(Intent.ACTION_MAIN);
           in.addCategory(Intent.CATEGORY_HOME);
           in.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
           in.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
           startActivity(in);
3)          
           System.exit(0);

4)    Killing the Process by id
android.os.Process.killProcess(android.os.Process.myPid());

Friday, November 11, 2011

WiFi Manager in Android

Android comes with a complete support for the WiFi connectivity. The main component is the system-provided WiFiManager. As usual, we obtain it via getSystemServices() call to the current context.

Once we have the WiFiManager, we can ask it for the current WIFi connection in form of WiFiInfo object. We can also ask for all the currently available networks via getConfiguredNetworks(). That gives us the list of WifiConfigurations.

In this example we are also registering a broadcast receiver to perform the scan for new networks. 




CODE:



public class WiFiDemo extends Activity implements OnClickListener {
private static final String TAG = "WiFiDemo";
WifiManager wifi;
BroadcastReceiver receiver;

TextView textStatus;
Button buttonScan;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

// Setup UI
textStatus = (TextView) findViewById(R.id.textStatus);
buttonScan = (Button) findViewById(R.id.buttonScan);
buttonScan.setOnClickListener(this);

// Setup WiFi
wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);

// Get WiFi status
WifiInfo info = wifi.getConnectionInfo();
textStatus.append("\n\nWiFi Status: " + info.toString());

// List available networks
List<WifiConfiguration> configs = wifi.getConfiguredNetworks();
for (WifiConfiguration config : configs) {
textStatus.append("\n\n" + config.toString());
}

// Register Broadcast Receiver
if (receiver == null)
receiver = new WiFiScanReceiver(this);

registerReceiver(receiver, new IntentFilter(
WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
Log.d(TAG, "onCreate()");
}

@Override
public void onStop() {
unregisterReceiver(receiver);
}

public void onClick(View view) {
Toast.makeText(this, "On Click Clicked. Toast to that!!!",
Toast.LENGTH_LONG).show();

if (view.getId() == R.id.buttonScan) {
Log.d(TAG, "onClick() wifi.startScan()");
wifi.startScan();
}
}

}

The WiFiScanReceiver is registered by WiFiDemo as a broadcast receiver to be invoked by the system when new WiFi scan results are available. WiFiScanReceiver gets the callback via onReceive(). It gets the new scan result from the intent that activated it and compares it to the best known signal provider. It then outputs the new best network via a Toast.

WiFiScanReceiver.java


public class WiFiScanReceiver extends BroadcastReceiver {
  private static final String TAG = "WiFiScanReceiver";
  WiFiDemo wifiDemo;


  public WiFiScanReceiver(WiFiDemo wifiDemo) {
    super();
    this.wifiDemo = wifiDemo;
  }


  @Override
  public void onReceive(Context c, Intent intent) {
    List<ScanResult> results = wifiDemo.wifi.getScanResults();
    ScanResult bestSignal = null;
    for (ScanResult result : results) {
      if (bestSignal == null
          || WifiManager.compareSignalLevel(bestSignal.level, result.level) < 0)
        bestSignal = result;
    }


    String message = String.format("%s networks found. %s is the strongest.",
        results.size(), bestSignal.SSID);
    Toast.makeText(wifiDemo, message, Toast.LENGTH_LONG).show();


    Log.d(TAG, "onReceive() message: " + message);
  }


}






The layout file for this example is fairly simple. It has one TextView wrapped in a ScrollView for scrolling purposes.

/res/layout/main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="fill_parent"
  android:layout_height="fill_parent">

  <Button android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:id="@+id/buttonScan"
    android:text="Scan"></Button>
  <ScrollView android:id="@+id/ScrollView01"
    android:layout_width="wrap_content" android:layout_height="wrap_content">
    <TextView android:layout_width="fill_parent"
      android:layout_height="wrap_content" android:id="@+id/textStatus"
      android:text="WiFiDemo" />
  </ScrollView>

</LinearLayout>


For the AndroidManifest.xml file, just remember to add the permissions to use WiFi:

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
  <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

Tuesday, September 27, 2011

Android’s Text to Speech

This is a sample activity which shows How to use Android’s Text to Speech capabilities. Text to Speech was introduced in Android 1.6, so when you create your new Android project make sure your minimum required SDK is set to Android 1.6 (or API level 4).

Underlying Algorithm:
Basic description of algorithm in step by step form:
1.) Create a Project MyTextToSpeech.
2.) Put the following code snippet in res/layout/main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   >
    
<EditText android:id="@+id/input_text" 
        android:text=""
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
/>
<Button android:id="@+id/speak_button" 
        android:text="Speak to me"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
/>
</LinearLayout>
3.) You just need to import the following packages and create a TextToSpeech object.
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
4.) The second is an OnInitListener which you will need to implement.
5.) Run the Application.
Steps to Create:
1.) Open Eclipse. Use the New Project Wizard and select Android Project Give the respective project name i.e. MyTextToSpeech. Enter following information:
Project name: MyTextToSpeech
Build Target: Android APIs 2.1
Application name: MyTextToSpeech
Package name: com.app.MyTextToSpeech
Create Activity: MyTextToSpeech
On Clicking Finish MyTextToSpeech code structure is generated with the necessary Android Packages being imported along with MyTextToSpeech.java. MyTextToSpeech class will look like following:
package com.app.MyTextToSpeech;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MyTextToSpeech extends Activity implements OnInitListener{
        /** Called when the activity is first created. */
        private int MY_DATA_CHECK_CODE = 0;
        private TextToSpeech tts;
        private EditText inputText;
        private Button speakButton;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            inputText = (EditText) findViewById(R.id.input_text);
            speakButton = (Button) findViewById(R.id.speak_button);
            speakButton.setOnClickListener(new OnClickListener() {                      
                @Override
                public void onClick(View v) {
                   String text = inputText.getText().toString();
                   if (text!=null && text.length()>0) {
                        Toast.makeText(MyTextToSpeech.this, "Saying: " + text, Toast.LENGTH_LONG).show();
                        tts.speak(text, TextToSpeech.QUEUE_ADD, null);
                   }
                }
            });
            Intent checkIntent = new Intent();
            checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
            startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);
       }
       protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == MY_DATA_CHECK_CODE) {
                if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
                        // success, create the TTS instance
                        tts = new TextToSpeech(this, this);
                } 
                else {
                        // missing data, install it
                        Intent installIntent = new Intent();
                        installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
                        startActivity(installIntent);
                }
         }
       }
        @Override
        public void onInit(int status) {                
          if (status == TextToSpeech.SUCCESS) {
                Toast.makeText(MyTextToSpeech.this, "Text-To-Speech engine is initialized", Toast.LENGTH_LONG).show();
          }
          else if (status == TextToSpeech.ERROR) {
                Toast.makeText(MyTextToSpeech.this, "Error occurred while initializing Text-To-Speech engine", Toast.LENGTH_LONG).show();
          }
        }
}
Output –The final output: