Tuesday, February 4, 2014

Service to Play Audio File

public class MyService extends Service{

    MediaPlayer player;
 
    public IBinder onBind(Intent arg0) {
        return null;
    }
  /*This Service used for Playing Music when any task is coming*/
    public void onCreate()
    {
        super.onCreate();
       
        player = MediaPlayer.create(MyService.this, R.raw.iphone_4s_new_2011);
        player.start();
        player.setLooping(true);
       
        System.out.println("songggggggggggggggggggggggggggggggggggggggggggg");
    }

    @Override
    public void onDestroy()
    {
        super.onDestroy();
        player.stop();
        player.release();      
}
}

startService(new Intent(this, MyService.class));

Wednesday, January 22, 2014

Enable GPS Dialog


Below Code display a dilog to enable gps if it is turned off



public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getGPSInfo();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

private void getGPSInfo() {
Criteria criteria = new Criteria();
String provider;
Location location;
LocationManager locationmanager = (LocationManager) this
.getSystemService(Context.LOCATION_SERVICE);

if (locationmanager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
provider = locationmanager.getBestProvider(criteria, false);
location = locationmanager.getLastKnownLocation(provider);

} else {
showGPSDisabledAlertToUser();
}
}


private void showGPSDisabledAlertToUser() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this);
alertDialogBuilder
.setMessage(
"GPS is disabled in your device. Would you like to enable it?")
.setCancelable(false)
.setPositiveButton("Goto Settings Page To Enable GPS",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent callGPSSettingIntent = new Intent(
android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(callGPSSettingIntent);

}
});

alertDialogBuilder.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {

dialog.cancel();
}
});
AlertDialog alert = alertDialogBuilder.create();
alert.show();
}// ;

}

You need to put following permissions in your manifestfile


<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

Wednesday, October 30, 2013

Stop EditText from gaining focus at Activity startup


<!-- Dummy item to prevent AutoCompleteTextView from receiving focus -->
<LinearLayout
    android:focusable="true" android:focusableInTouchMode="true"
    android:layout_width="0px" android:layout_height="0px"/>

<!-- :nextFocusUp and :nextFocusLeft have been set to the id of this component
     to prevent the dummy from receiving focus again -->
<AutoCompleteTextView android:id="@+id/autotext"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:nextFocusUp="@id/autotext" android:nextFocusLeft="@id/autotext"/>



http://stackoverflow.com/questions/1555109/stop-edittext-from-gaining-focus-at-activity-startup

Saturday, October 19, 2013

Android GCM PushNotification Testing


Some time we need to simulate push notification into our android device for testing purpose .
This facilty is still not provided into inbuilt android sdk .
But same can be achived from online api testing site called Hurl.it

Below are steps for that

Step 1 : In the Destination combo box select Post

Step 2: Click on Add headers button and put the following values for name and vale
            name = "Authorization"   value= "key=YOU_GOOGLE_API_KEY"
            name="Content-Type"   value ="application/json"
Step 3: Click on Add Body and put the json values into following format

Step 4 :put  "https://android.googleapis.com/gcm/send"  in url filed

          {
  • "registration_ids":[
    1. "sdfsdfsdf",
    2. "GCM REGISTRATION TOEKM OF YOUR DEVICE"
    ]
    ,
  • "data":{
    • "message":"testing",
    • "usertype":"driver",
    • "bookingid":"8"
    }
}

registration_ids and data are mandatory fields and under data u can send any string data 


Step 4: click on Launch Request

You can see the response in following formate

{"multicast_id": 4635199670770759000,"success": 1,"failure": 1,"canonical_ids": 0,"results": [{"error": "InvalidRegistration"},{"message_id": "0:1382190107462279%63ac093bf9fd7ecd"}]}

Tuesday, October 1, 2013

Android Custom autocomplete

Below is the sample code for a cuatom Autocomplete EditText in android
click here to download the sample code

Android Custom Receiver

Following is the sample code to create a custom Broadcast Reciever (Local receiver ) in android.
Clikc  here to download the sample code

Monday, September 16, 2013

Android Transparency in percentage



use a color with alpha value like this #33------ and set it as background of your editText using the xml attribute android:background=" "
  1. 0% (transparent) -> #00 in hex
  2. 20% -> #33
  3. 50% -> #80
  4. 75% -> #C0
  5. 100% (opaque) -> #FF
255 * 0.2 = 51 ==> in hex 33

Android animation

This page is still in construction .
just collecting the various souces get to display simlpe and easy animations in android

http://android-er.blogspot.in/2012/02/various-effect-of-interpolator-in.html

Thursday, September 12, 2013

Sms Receiver and Parser

Android code to receive and parse a sms

Click here to download the sample code

Wednesday, September 4, 2013

Android Cron to pull data From server

This sample app polls data from server after 10 secs
Click here to download sample code

Monday, July 15, 2013

Android Google Map V2

Click here to get the sample code to download the source code.

The documentation for working with Google Map V2 is not clear documentated.
For above code to work properly you need to added google play service library  .
http://developer.android.com/google/play-services/setup.html

Generate the api key for android mobile at
https://code.google.com/apis/console/?pli=1#project:757763940378:access

Reference url

http://iamvijayakumar.blogspot.in/2013/04/android-draw-route-between-two-geo.html



Sunday, June 16, 2013

Android custom button with server checking animation

This is a demo code which polls sever after every 1 seconds and starts blinking if the repose is gretaer then 1 else stops blinking

Sunday, June 9, 2013

Android custom gallery

Click here to get the sample code custom android gallery with swipe gesture

Thursday, May 16, 2013

Android Edit Text With Different shapes


The code for different edit shapes like rounded corner , oval shape etc can be created using shapes attributes

The code for below can be downloaded from here


http://stackoverflow.com/questions/3646415/how-to-create-edittext-with-rounded-corners

http://letustech.wordpress.com/category/android/