Google Plus Sliding Menu in Android

You might have noticed that lot of android applications introduced a sliding panel menu to navigate between major modules of the application. Previously this kind of UI was done using some third party libraries where a list view and some swiping gestures used to achieve this. But now android itself officially introduced sliding panel menu by introducing a newer concept called Navigation Drawer.



Download Project

Most of the time Sliding Menu (Navigation Drawer) will be hidden and can be shown by swiping the screen from left edge to right or tapping the app icon on the action bar.


You can see lot of popular applications like Facebook, Youtube, Google + already introduced navigation drawer menu in their applications. Following are the navigation drawer menus of multiple apps.

Online Examination JSP Project

Exam Software is a Test Management Software, which offers a complete solution for Computer Based Test (CBT) .They are used to set up multiple choice tests for set time periods that when submitted are automatically corrected and the results logged beside the student’s reference number.

Download Project 
Download Project Report

FEATURES

  • Administrator login.
  • Student registration.
  • Management and update of student information ,instructions and questions.
  • Scope for fixing negative marks and maximum marks to each question.
  • Display of result in the form of total score ,correct responses attempted and non attempted questions.





WHAT IMPACT DOES IT HAVE

  • Physical presence at a given location is absolutely not necessary.
  • No time is spent on evaluation.
  • Results are available instantly.
  • The time of starting and completion of examination can be recorded at the server and the student cannot manipulate the same.
  • Even for subjects that the actual examination that will not be conducted online students can be given extensive practice and training by holding online Mock Tests.
  • Almost all competitive exams are multiple choice types and these can be easily conducted online, for example GCET – Goa Common Entrance Test held to shortlist candidates for medical and engineering courses.
  •  Trends of the examination including topic wise trends of each subject can be easily obtained if required.

How to Get Network Operator Code, Name, Type, Subscriber ID & Country ISO in Android

Step 1 : Select File -> New -> Project -> Android Application Project (or) Android Project. Fill the forms and click "Finish" button.
Step 2 : Open res -> layout -> activity_main.xml (or) main.xml and add following code :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
 
    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:textSize="15sp"
        android:gravity="center" />
 
</RelativeLayout>
Step 3 : Open src -> package -> MainActivity.java and add following code :
package balaji.mobile_network_type;
 
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.telephony.TelephonyManager;
import android.widget.TextView;
 
public class MainActivity extends Activity {
 
 TelephonyManager tel;
 TextView text;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        text = (TextView) findViewById(R.id.textView2);
        
        text.setText("Operator Code : " + tel.getNetworkOperator().toString()
          + "\nSubscriber ID : " + tel.getSubscriberId().toString()
          + "\nOperator Name : " + tel.getNetworkOperatorName().toString()
          + "\nNetwork Type : " + tel.getNetworkType()
          + "\nCountry ISO : " + tel.getNetworkCountryIso().toString());
    }
}
Our output will be like this :

How to Get Sim Serial Number & Line Number in Android

Step 1 : Select File -> New -> Project -> Android Application Project (or) Android Project. Fill the forms and click "Finish" button.
Step 2 : Open res -> layout -> activity_main.xml (or) main.xml and add following code :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
 
    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:textSize="15sp"
        android:gravity="center" />
 
</RelativeLayout>
Step 3 : Open src -> package -> MainActivity.java and add following code :
package balaji.sim_type2;
 
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.telephony.TelephonyManager;
import android.widget.TextView;
 
public class MainActivity extends Activity {
 
 TelephonyManager tel;
 TextView text;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        text = (TextView) findViewById(R.id.textView2);
                
        text.setText("Serial Number : " + tel.getSimSerialNumber().toString()
          + "\nMobile Number : " + tel.getLine1Number().toString());
    }
}
Our output will be like this :

How to Get Sim Operator Code, Name & Country Code in Android

Step 1 : Select File -> New -> Project -> Android Application Project (or) Android Project. Fill the forms and click "Finish" button.
Step 2 : Open res -> layout -> activity_main.xml (or) main.xml and add following code :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
 
    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:textSize="15sp"
        android:gravity="center" />
 
</RelativeLayout>
Step 3 : Open src -> package -> MainActivity.java and add following code :
package balaji.sim_type;
 
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.telephony.TelephonyManager;
import android.widget.TextView;
 
public class MainActivity extends Activity {
 
 TelephonyManager tel;
 TextView text;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        text = (TextView) findViewById(R.id.textView2);
        
        text.setText("Operator Code : " + tel.getSimOperator().toString()
          + "\nOperator Name : " + tel.getSimOperatorName().toString()
          + "\nCountry ISO : " + tel.getSimCountryIso().toString());
    }
}
Our output will be like this :

How to Get Phone Information in Android

How to Get Model Number, Board, Brand, Display, FingerPrint, ID, TAGS, Type, AndroidVersion, API Level, CodeName & INCREMENTAL in Android.

Step 1 : Select File -> New -> Project -> Android Application Project (or) Android Project. Fill the forms and click "Finish" button.
Step 2 : Open res -> layout -> activity_main.xml (or) main.xml and add following code :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
 
    <TextView
        android:id="@+id/textView2"
        android:textColor="#4169E1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10sp"
        android:layout_marginTop="20sp"  />
 
</RelativeLayout>
Step 3 : Open src -> package -> MainActivity.java and add following code :
package balaji.phone_type;
 
import android.os.Bundle;
import android.app.Activity;
import android.text.Html;
import android.widget.TextView;
 
public class MainActivity extends Activity {
 
 String ModelNumber, Board, Brand, Display, FingerPrint, ID, TAGS, Type, 
  AndroidVersion, APILevel, CodeName, INCREMENTAL;
 
 TextView text;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        ModelNumber = android.os.Build.MODEL;
        Board = android.os.Build.BOARD;
        Brand = android.os.Build.BRAND;
        Display = android.os.Build.DISPLAY;
        FingerPrint = android.os.Build.FINGERPRINT;
        ID = android.os.Build.ID;
        TAGS = android.os.Build.TAGS;
        Type = android.os.Build.TYPE;
        
        AndroidVersion = android.os.Build.VERSION.RELEASE;
        APILevel = android.os.Build.VERSION.SDK;
        CodeName = android.os.Build.VERSION.CODENAME;
        INCREMENTAL = android.os.Build.VERSION.INCREMENTAL;
        
        text = (TextView) findViewById(R.id.textView2);
        
        text.setText(Html.fromHtml("Phone Type" +
  "<br/><br/><font color = 'red';>Model Number : </font></font>" + ModelNumber 
  + "<br/><font color = 'red';>Board : </font>" + Board
  + "<br/><font color = 'red';>Brand : </font>" + Brand
  + "<br/><font color = 'red';>Display : </font>" + Display
  + "<br/><font color = 'red';>FingerPrint : </font>" + FingerPrint
  + "<br/><font color = 'red';>ID : </font>" + ID
  + "<br/><font color = 'red';>TAGS : </font>" + TAGS
  + "<br/><font color = 'red';>Type : </font>" + Type          
            
  + "<br/>"
  
  + "<br/><font color = 'red';>Android Version : </font>" + AndroidVersion
  + "<br/><font color = 'red';>API Level : </font>" + APILevel
  + "<br/><font color = 'red';>CodeName : </font>" + CodeName
  + "<br/><font color = 'red';>INCREMENTAL : </font>" + INCREMENTAL));
    }
}
Our output will be like this :

How to Find IMSI Number in Android

Step 1 : Select File -> New -> Project -> Android Application Project (or) Android Project. Fill the forms and click "Finish" button.
Step 2 : Open res -> layout -> activity_main.xml (or) main.xml and add following code :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
 
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="50dp"
        android:textColor="#4169E1"
        android:textSize="18sp"
        android:text="IMSI Number" />
 
    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:textSize="15sp"
        android:text="IMSI" />
 
</RelativeLayout>
Step 3 : Open src -> package -> MainActivity.java and add following code :
package balaji.imsi_number;
 
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.telephony.TelephonyManager;
import android.widget.TextView;
 
public class MainActivity extends Activity {
 
 TextView text;
 TelephonyManager tel;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        text = (TextView) findViewById(R.id.textView2);
        tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        text.setText(tel.getSubscriberId().toString());
    }
}
Step 4 : Open AndroidManifest.xml and add following code :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="balaji.imsi_number"
    android:versionCode="1"
    android:versionName="1.0" >
 
    <uses-sdk
        android:minSdkVersion="3"
        android:targetSdkVersion="15" />
    
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
 
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
 
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
 
</manifest>
Step 5 : Our output will be like this :

How to Use Google Map with Zooming Controls in Android

Step 1 : Select File -> New -> Project -> Android Application Project (or) Android Project. Fill the forms and click "Finish" button.
Step 2 : Open res -> layout -> activity_main.xml (or) main.xml and add following code :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    
    <com.google.android.maps.MapView 
        android:id="@+id/mapView" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:enabled="true" 
        android:clickable="true" 
        android:apiKey="Your API Key"/>
 
</RelativeLayout>
Step 3 : Open src -> package -> MainActivity.java and add following code :
package balaji.google_map_zoom.controls;
 
import android.os.Bundle;
import android.view.Menu;
import android.app.Activity;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
 
public class MainActivity extends MapActivity {
 /** Called when the activity is first created. */
 
 MapView mapView;
 
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  
  mapView = (MapView) findViewById(R.id.mapView);
  
  mapView.setBuiltInZoomControls(true);
 }
    
    @Override
    protected boolean isRouteDisplayed() {
     // TODO Auto-generated method stub
     return false;
    }
}
Step 4 : Open AndroidManifest.xml and add following code :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="balaji.google_map_zoom.controls"
    android:versionCode="1"
    android:versionName="1.0" >
 
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />
    <uses-permission android:name="android.permission.INTERNET"/>
 
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <uses-library android:name="com.google.android.maps"/>
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
 
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
 
</manifest>
Now Execute our Program

How to Display Google Map in Android

Step 1 : Select File -> New -> Project -> Android Application Project (or) Android Project. Fill the forms and click "Finish" button.
Step 2 : Open res -> layout -> activity_main.xml (or) main.xml and add following code :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    
    <com.google.android.maps.MapView
  android:id="@+id/mapView"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:enabled="true"
  android:clickable="true"
  android:apiKey="Your API Key" />
    
</RelativeLayout>
Step 3 : Open src -> package -> MainActivity.java and add following code :
package balaji.google_map_display;
 
import android.os.Bundle;
import android.view.Menu;
import android.app.Activity;
import com.google.android.maps.MapActivity;
 
public class MainActivity extends MapActivity {
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
 }
    
    @Override
    protected boolean isRouteDisplayed() {
     // TODO Auto-generated method stub
     return false;
    }
}
Step 4 : Open AndroidManifest.xml and add following code :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="balaji.google_map_display"
    android:versionCode="1"
    android:versionName="1.0" >
 
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />
    <uses-permission android:name="android.permission.INTERNET"/>
 
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <uses-library android:name="com.google.android.maps" />
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
 
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
 
</manifest>
Now Execute our program

How to Get Google Map API key for Android

Today i am telling you how to integrate google map in android but firstly we need to get google map api key.
And you'll get it i am telling you
Step 1 : Open Terminal and type below command.
keytool -list -keystore ~/.android/debug.keystore
Step 2 : The Password is Empty. So directly hit the Enter.
Step 3 : Now you can get Certificate fingerprint (MD5) like below :


Step 4 : Go to below URL, type your Certificate's MD5 fingerprint & accept the terms and conditions then Click Generate API Key
https://developers.google.com/android/maps-api-signup
Step 5 : Now login to your gmail account
Step 6 : At finally you can get Google Map API key like below :


Photo Puzzle Game Swing Game Project

Hello Friends,
I am giving you an interesting game in Core Java(Swing). Its is a photo puzzle game development in java swing application.this is game simple game useful for student.and learning game development in java swing.in this project photo will divide.move up and down create proper image.

Identify.java is the main class for run this swing game project.

How to Send SMS through Android Application

Step 1 : Select File -> New -> Project -> Android Application Project (or) Android Project. Fill the forms and click "Finish" button.
Step 2 : Open res -> layout -> activity_main.xml (or) main.xml and add following code :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
 
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="30dp"
        android:text="Send SMS" />
 
    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="33dp"
        android:hint="Phone Number"
        android:ems="10"
        android:inputType="number" >
 
        <requestFocus />
    </EditText>
 
    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="22dp"
        android:hint="Message"
        android:ems="10"
        android:inputType="textMultiLine" />
 
</RelativeLayout>
Step 3 : Open src -> package -> MainActivity.java and add following code :
package balaji.sms_sendind;
 
import android.os.Bundle;
import android.app.Activity;
import android.telephony.SmsManager;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
 
public class MainActivity extends Activity {
 
 Button Send;
 EditText Phone, Msg;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        Phone = (EditText) findViewById(R.id.editText1);
        Msg = (EditText) findViewById(R.id.editText2);
        
        Send = (Button) findViewById(R.id.button1);
        Send.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View v)
            {
                sendSMS(Phone.getText().toString(), Msg.getText().toString());
            }
        });
    }
 
    public void sendSMS(String phoneNumber, String message)
    {
        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phoneNumber, null, message, null, null);
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }    
}
Output look like below image :




How to Create and Use your Own Content Provider in Android

Step 1 : Select File -> New -> Project -> Android Application Project (or) Android Project. Fill the forms and click "Finish" button.
Step 2 : Open res -> layout -> activity_main.xml (or) main.xml and add following code :
<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/txtISBN"
     android:hint="ISBN"
     android:textSize="15dp"
     android:paddingLeft="10dp"
     android:paddingRight="10dp"  
     android:layout_height="wrap_content"
     android:layout_width="fill_parent" />
  
 <EditText
     android:id="@+id/txtTitle"
     android:hint="Title"
     android:textSize="15dp"
     android:paddingLeft="10dp"
     android:paddingRight="10dp"  
     android:layout_height="wrap_content"
     android:layout_width="fill_parent" />
  
 <Button
     android:text="Add title"
     android:id="@+id/btnAdd"
     android:textSize="15dp"
     android:paddingLeft="10dp"
     android:paddingRight="10dp"  
     android:layout_width="fill_parent"
     android:layout_height="wrap_content" />
  
 <Button
     android:text="Retrieve titles"
     android:id="@+id/btnRetrieve"
     android:textSize="15dp"
     android:paddingLeft="10dp"
     android:paddingRight="10dp"  
     android:layout_width="fill_parent"
     android:layout_height="wrap_content" />
 
</LinearLayout>
Step 3 : Open src -> package -> BooksProvider.java and add following code :
package balaji.contentprovider_own;
 
import android.content.ContentProvider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
 
public class BooksProvider extends ContentProvider
{
    public static final String PROVIDER_NAME =
        "net.learn2develop.provider.Books";
    public static final Uri CONTENT_URI =
        Uri.parse("content://"+ PROVIDER_NAME + "/books");
    public static final String _ID = "_id";
    public static final String TITLE = "title";
    public static final String ISBN = "isbn";
    private static final int BOOKS = 1;
    private static final int BOOK_ID = 2;
    private static final UriMatcher uriMatcher;
    static{
        uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
        uriMatcher.addURI(PROVIDER_NAME, "books", BOOKS);
        uriMatcher.addURI(PROVIDER_NAME, "books/#", BOOK_ID);
    }
    //---for database use---
    private SQLiteDatabase booksDB;
    
    private static final String DATABASE_NAME = "Books";
    private static final String DATABASE_TABLE = "titles";
    private static final int DATABASE_VERSION = 1;
    private static final String DATABASE_CREATE =
            "create table " + DATABASE_TABLE +
            " (_id integer primary key autoincrement, "
            + "title text not null, isbn text not null);";
    private static class DatabaseHelper extends SQLiteOpenHelper
    {
        DatabaseHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }
        @Override
        public void onCreate(SQLiteDatabase db)
        {
            db.execSQL(DATABASE_CREATE);
        }
        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion,
        int newVersion) {
            Log.w("Content provider database",
                 "Upgrading database from version " +
                 oldVersion + " to " + newVersion +
                 ", which will destroy all old data");
            db.execSQL("DROP TABLE IF EXISTS titles");
            onCreate(db);
        }
    }
    @Override
    public int delete(Uri arg0, String arg1, String[] arg2) {
 
     // arg0 = uri
        // arg1 = selection
        // arg2 = selectionArgs
        int count=0;
        switch (uriMatcher.match(arg0)){
            case BOOKS:
                count = booksDB.delete(
                        DATABASE_TABLE,
                        arg1,
                        arg2);
                break;
            case BOOK_ID:
                String id = arg0.getPathSegments().get(1);
                count = booksDB.delete(
                        DATABASE_TABLE,
                        _ID + " = " + id +
                        (!TextUtils.isEmpty(arg1) ? " AND (" +
                                arg1 + ')' : ""),
                                arg2);
                break;
            default: throw new IllegalArgumentException("Unknown URI " + arg0);
 
        }
        getContext().getContentResolver().notifyChange(arg0, null);
        return count;
    }
    @Override
    public String getType(Uri uri) {
        switch (uriMatcher.match(uri)){
            //---get all books---
            case BOOKS:
                return "vnd.android.cursor.dir/vnd.learn2develop.books ";
            //---get a particular book---
            case BOOK_ID:
                return "vnd.android.cursor.item/vnd.learn2develop.books ";
            default:
                throw new IllegalArgumentException("Unsupported URI: " + uri);
        }
    }
    @Override
    public Uri insert(Uri uri, ContentValues values) {
        //---add a new book---
        long rowID = booksDB.insert(
            DATABASE_TABLE,
            "",
            values);
        //---if added successfully---
        if (rowID>0)
        {
            Uri _uri = ContentUris.withAppendedId(CONTENT_URI, rowID);
            getContext().getContentResolver().notifyChange(_uri, null);
            return _uri;
        }
        throw new SQLException("Failed to insert row into " + uri);
    }
    @Override
    public boolean onCreate() {
        Context context = getContext();
        DatabaseHelper dbHelper = new DatabaseHelper(context);
        booksDB = dbHelper.getWritableDatabase();
        return (booksDB == null)? false:true;
    }
    @Override
    public Cursor query(Uri uri, String[] projection, String selection,
            String[] selectionArgs, String sortOrder) {
        SQLiteQueryBuilder sqlBuilder = new SQLiteQueryBuilder();
        sqlBuilder.setTables(DATABASE_TABLE);
        if (uriMatcher.match(uri) == BOOK_ID)
            //---if getting a particular book---
            sqlBuilder.appendWhere(
 
              _ID + " = " + uri.getPathSegments().get(1));
        if (sortOrder==null || sortOrder=="")
            sortOrder = TITLE;
        Cursor c = sqlBuilder.query(
                booksDB,
                projection,
                selection,
                selectionArgs,
                null,
                null,
                sortOrder);
        //---register to watch a content URI for changes---
        c.setNotificationUri(getContext().getContentResolver(), uri);
        return c;
    }
    @Override
    public int update(Uri uri, ContentValues values, String selection,
            String[] selectionArgs) {
        int count = 0;
        switch (uriMatcher.match(uri)){
            case BOOKS:
                count = booksDB.update(
                        DATABASE_TABLE,
                        values,
                        selection,
                        selectionArgs);
                break;
 
            case BOOK_ID:
                count = booksDB.update(
                        DATABASE_TABLE,
                        values,
                        _ID + " = " + uri.getPathSegments().get(1) +
                        (!TextUtils.isEmpty(selection) ? " AND (" +
                            selection + ')' : ""),
                        selectionArgs);
                break;
            default: throw new IllegalArgumentException("Unknown URI " + uri);
        }
        getContext().getContentResolver().notifyChange(uri, null);
        return count;
    }
}
Step 4 : Open src -> package -> MainActivity.java and add following code :
package balaji.contentprovider_own;
 
import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        Button btnAdd = (Button) findViewById(R.id.btnAdd);
        
        btnAdd.setOnClickListener(new View.OnClickListener() {
         public void onClick(View v) {
          //---add a book---
          ContentValues values = new ContentValues();
                
          values.put(BooksProvider.TITLE,((EditText) 
                  findViewById(R.id.txtTitle)).getText().toString());
                
          values.put(BooksProvider.ISBN, ((EditText) 
                  findViewById(R.id.txtISBN)).getText().toString());
                
          Uri uri = getContentResolver().insert(
                      BooksProvider.CONTENT_URI, values);
 
          Toast.makeText(getBaseContext(),uri.toString(),
                  Toast.LENGTH_LONG).show();
  }
 });

        Button btnRetrieve = (Button) findViewById(R.id.btnRetrieve);
        
        btnRetrieve.setOnClickListener(new View.OnClickListener() {
         @SuppressWarnings("deprecation")
         public void onClick(View v) {
          //---retrieve the titles---
          Uri allTitles = Uri.parse(
    "content://net.learn2develop.provider.Books/books");
          Cursor c = managedQuery(allTitles, null, null, null,
    "title desc");
          if (c.moveToFirst()) {
           do{
            Toast.makeText(getBaseContext(), "ContentProviders "+ 
            c.getString(c.getColumnIndex(
     BooksProvider._ID)) + ", " +
     c.getString(c.getColumnIndex(
     BooksProvider.TITLE)) + ", " +
     c.getString(c.getColumnIndex(
     BooksProvider.ISBN))+"", Toast.LENGTH_LONG).show();
           } while (c.moveToNext());
          }
         }
        });
    }
                  
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }    
}
Output look like below images :


How to Create Browser Content Provider in Android

Step 1 : Select File -> New -> Project -> Android Application Project (or) Android Project. Fill the forms and click "Finish" button.
Step 2 : Open res -> layout -> activity_main.xml (or) main.xml and add following code :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    
    <ListView
        android:id="@+id/android:list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
    
    <TextView
        android:id="@+id/Title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="10dp"
        android:textSize="17dp"/>
    
    <TextView
        android:id="@+id/BookMark"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:textSize="17dp" />
 
</RelativeLayout>
Step 3 : Open src -> package -> MainActivity.java and add following code :
package balaji.contentprovider_browser;
 
import android.os.Bundle;
import android.provider.Browser;
import android.app.ListActivity;
import android.database.Cursor;
import android.view.Menu;
import android.widget.SimpleCursorAdapter;
 
public class MainActivity extends ListActivity {
 
  @SuppressWarnings("deprecation")
 @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
         
         Cursor cursor = getContentResolver().query
           (Browser.BOOKMARKS_URI, null, null, null, null);
 
         String s[] = new String[] {
                 Browser.BookmarkColumns.BOOKMARK,
                 Browser.BookmarkColumns.TITLE };
         int view[] = new int[] {
                 R.id.BookMark, R.id.Title };
 
         SimpleCursorAdapter adapter = new SimpleCursorAdapter
           (this, R.layout.activity_main, cursor, s, view);
         this.setListAdapter(adapter);         
        }
 
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
  getMenuInflater().inflate(R.menu.activity_main, menu);
         return true;
        }    
}
Output look like below image :

How to Create Contact Content Provider in Android

Step 1 : Select File -> New -> Project -> Android Application Project (or) Android Project. Fill the forms and click "Finish" button.
Step 2 : Open res -> layout -> activity_main.xml (or) main.xml and add following code :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    
    <ListView
        android:id="@+id/android:list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
    
    <TextView
        android:id="@+id/contactName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="10dp"
        android:textSize="17dp"/>
    
    <TextView
        android:id="@+id/contactID"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:textSize="17dp" />
    
</RelativeLayout>
Step 3 : Open src -> package -> MainActivity.java and add following code :
package balaji.contentprovider_contacts;
 
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.app.ListActivity;
import android.database.Cursor;
import android.view.Menu;
import android.widget.SimpleCursorAdapter;
 
public class MainActivity extends ListActivity {
 
    @SuppressWarnings("deprecation")
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        Uri allContacts = Uri.parse("content://contacts/people");
        Cursor c = managedQuery(allContacts, null, null, null, null);
            
        String[] columns = new String[] {
          ContactsContract.Contacts.DISPLAY_NAME,
                 ContactsContract.Contacts._ID };
            
        int[] views = new int[] {R.id.contactName, R.id.contactID };
        
        SimpleCursorAdapter adapter = new SimpleCursorAdapter
  (this, R.layout.activity_main, c, columns, views);
        this.setListAdapter(adapter);
    }
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}
Create Contacts in Emulator like below :

 Our output will be like this :


How to Find IMEI Number in Android

Step 1 : Select File -> New -> Project -> Android Application Project (or) Android Project. Fill the forms and click "Finish" button.
Step 2 : Open res -> layout -> activity_main.xml (or) main.xml and add following code :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
 
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="50dp"
        android:textColor="#4169E1"
        android:textSize="18sp"
        android:text="IMEI Number" />
 
    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:textSize="15sp"
        android:text="IMEI" />
 
</RelativeLayout>
Step 3 : Open src -> package -> MainActivity.java and add following code :
package balaji.imei_number;
 
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.telephony.TelephonyManager;
import android.widget.TextView;
 
public class MainActivity extends Activity {
 
 TelephonyManager tel;
 TextView imei;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
                
        tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        
        imei = (TextView) findViewById(R.id.textView2);
        imei.setText(tel.getDeviceId().toString());
    }
}
Step 5 : Our output will be like this :

How to Check URL Link based HttpURLConnection in Android

Step 1 : Select File -> New -> Project -> Android Application Project (or) Android Project. Fill the forms and click "Finish" button.
Step 2 : Open res -> layout -> activity_main.xml (or) main.xml and add following code :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >
 
    <TextView
        android:id="@+id/textView1"
        android:gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="35dp"
        android:textSize="18sp"
        android:textColor="#ff0000"
        android:text="HttpURLConnection\nURL Based" />
 
    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="Checking Connection.." />
 
</RelativeLayout>
Step 3 : Open src -> package -> MainActivity.java and add following code :
package balaji.check_httpurlconnection;
 
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import android.os.Bundle;
import android.app.Activity;
import android.widget.TextView;
 
public class MainActivity extends Activity {
 
 TextView text;
 String http_url = "http://sampleprogramz.com";
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  
  text = (TextView) findViewById(R.id.textView2);
  
  try {
         
         URL url = new URL(http_url);
         executeReq(url);
 
         text.setText("HttpURLConnection Available");
        }
        catch(Exception e) {
        
         text.setText("Connection Failed");
        }
 }
 
 private void executeReq(URL url) throws IOException {
  // TODO Auto-generated method stub
  
  HttpURLConnection con = (HttpURLConnection) url.openConnection();
  con.setReadTimeout(3000);
  con.setConnectTimeout(3500);
  con.setRequestMethod("GET");
  con.setDoInput(true);
  
  // Connect
  con.connect();
 }
}
Our output look like below image :

How to Check IP Address based HttpURLConnection in Android

Step 1 : Select File -> New -> Project -> Android Application Project (or) Android Project. Fill the forms and click "Finish" button.
Step 2 : Open res -> layout -> activity_main.xml (or) main.xml and add following code :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >
 
    <TextView
        android:id="@+id/textView1"
        android:gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="35dp"
        android:textSize="18sp"
        android:textColor="#ff0000"
        android:text="HttpURLConnection\nIP Based" />
 
    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="Checking Connection.." />
 
</RelativeLayout>
Step 3 : Open src -> package -> MainActivity.java and add following code :
package balaji.check_httpurlconnection_ip;
 
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import android.os.Bundle;
import android.widget.TextView;
import android.app.Activity;
 
public class MainActivity extends Activity {
 
 TextView text;
 String ip = "http://10.0.2.2/webservice/";
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  
  text = (TextView) findViewById(R.id.textView2);
  
  try {
   
   URL url = new URL(ip);
   executeReq(url);
   
   text.setText("HttpURLConnection Available");
        }
        catch(Exception e) {
        
         text.setText("Connection Failed");
        }  
 }
 
 private void executeReq(URL url) throws IOException {
  // TODO Auto-generated method stub
  
  HttpURLConnection con = (HttpURLConnection) url.openConnection();
  con.setReadTimeout(3000);
  con.setConnectTimeout(3500);
  con.setRequestMethod("GET");
  con.setDoInput(true);
  
  // Connect
  con.connect();
 }
}
Step 4 : Open AndroidManifest.xml and add following code :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="balaji.check_httpurlconnection_ip"
    android:versionCode="1"
    android:versionName="1.0" >
 
    <uses-sdk
        android:minSdkVersion="3"
        android:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.INTERNET"/>
 
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="balaji.check_httpurlconnection_ip.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
 
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
 
</manifest>
Our Output look like below image:

Free MP3 Songs Website Store in JSP Project

Project Name : MP3 video songs website development in jsp.
Description:
It is great and beautiful JSP project for website store



  • This project for student who have to learn jsp and development project in jsp.
  • In this project admin user and latest movie mp3 songs links.
  • Upload movie video songs and mp3 songs link share.
  • This project useful for student they have learn jsp.

Download Project :

You can develop this project in Many ways its your thought and thinking power .Latest mp3 video songs store website development in jsp is developed in jsp,java script,html,css,ajax,jquery programming language Using mysql database.

How to Insert Image Into Database Using JSP

Today i am telling you how to insert image into database using jsp.
A Blob stores a binary large object in the database table's row. Blob object contains a logical pointer which points to the Blob data, data is not directly stored in the row of the database table. Blob object  is valid for the duration of the transaction. The "getBlob()" and  "setBlob()" method of "ResultSet" ,"CallableStatement", and "PreparedStatement" interface , is used for accessing Blob value.


<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<%
Connection con=null;
ResultSet rs=null;
PreparedStatement psmt=null;
FileInputStream fis;

try{
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","tiger");
File image=new File("D:/obama.jpg");
psmt=con.prepareStatement("insert into inimage(name,city,image)"+"values(?,?,?)");
psmt.setString(1,"Barack Obama");
psmt.setString(2,"Wasington D.C.");
fis=new FileInputStream(image);
psmt.setBinaryStream(3, (InputStream)fis, (int)(image.length()));
int s = psmt.executeUpdate();
if(s>0) {
%>
<b><font color="Blue">
<% out.println("Image Uploaded successfully !"); %>
</font></b>
<%
}
else {
out.println("unsucessfull to upload image.");
}
con.close();
psmt.close();
}catch(Exception ex){
out.println("Error in connection : "+ex);
}
%>
Happy GoJ Codding !!!!

How to Clear and Delete Values from SharedPreferences

Step 1 : Select File -> New -> Project -> Android Application Project (or) Android Project. Fill the forms and click "Finish" button.
Step 2 : Open res -> layout -> activity_main.xml (or) main.xml and add following code :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
 
    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:hint="Id"
        android:padding="11dp"
        android:ems="10"
        android:inputType="number" >
 
        <requestFocus />
    </EditText>
 
    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:hint="Name"
        android:padding="11dp"
        android:ems="10"
        android:inputType="textPersonName" />
 
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText2"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:padding="11dp"
        android:text="Save" />
 
    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"        
 android:layout_below="@+id/button1"
 android:layout_marginTop="20dp"
 android:padding="11dp"
        android:text="Select" />
    
    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"        
 android:layout_below="@+id/button2"
 android:layout_marginTop="20dp"
 android:padding="11dp"
        android:text="Update" />
    
    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"        
 android:layout_below="@+id/button3"
 android:layout_marginTop="20dp"
 android:padding="11dp"
        android:text="Clear" />
    
 
</RelativeLayout>
Step 3 : Open src -> package -> MainActivity.java and add following code :
package balaji.shared_clear;
 
import android.os.Bundle;
import android.app.Activity;
import android.content.SharedPreferences;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
 
public class MainActivity extends Activity {
 

 private SharedPreferences prefs;
 private String prefName = "report";
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        final EditText e_id=(EditText) findViewById(R.id.editText1);
        final EditText e_name=(EditText) findViewById(R.id.editText2);
        Button save=(Button) findViewById(R.id.button1);
        Button select=(Button) findViewById(R.id.button2);
        Button update=(Button) findViewById(R.id.button3);
        Button clear=(Button) findViewById(R.id.button4);
        
        save.setOnClickListener(new View.OnClickListener() {
   
  @Override
  public void onClick(View v) {
   // TODO Auto-generated method stub
    
   prefs = getSharedPreferences(prefName, MODE_PRIVATE);
          SharedPreferences.Editor editor = prefs.edit();
        
          //---save the values in the EditText view to preferences---
   editor.putInt("id", Integer.parseInt(e_id.getText().toString()));
          editor.putString("name", e_name.getText().toString());
        
          //---saves the values---
                 editor.commit();
        
          Toast.makeText(getBaseContext(), "Saved",
    Toast.LENGTH_SHORT).show();
  }
 });
        
        select.setOnClickListener(new View.OnClickListener() {
   
  @Override
  public void onClick(View v) {
   // TODO Auto-generated method stub
    
   prefs = getSharedPreferences(prefName, MODE_PRIVATE);
   
          Toast.makeText(getBaseContext(), String.valueOf(prefs.getInt
    ("id", 100)), Toast.LENGTH_SHORT).show();
          Toast.makeText(getBaseContext(), prefs.getString
    ("name", "Balaji"), Toast.LENGTH_SHORT).show();
  }
 });
        
        update.setOnClickListener(new View.OnClickListener() {
   
  @Override
  public void onClick(View v) {
   // TODO Auto-generated method stub
    
   prefs = getSharedPreferences(prefName, MODE_PRIVATE);
          SharedPreferences.Editor editor = prefs.edit();
        
          //---save the values in the EditText view to preferences---
   editor.putInt("id", Integer.parseInt(e_id.getText().toString()));
        editor.putString("name", e_name.getText().toString());
        
          //---saves and update the values both are same---
                 editor.commit();
        
          Toast.makeText(getBaseContext(), "Updated Successfully",
    Toast.LENGTH_SHORT).show();
  }
 });
        
        clear.setOnClickListener(new View.OnClickListener() {
   
  @Override
  public void onClick(View v) {
   // TODO Auto-generated method stub
    
   prefs = getSharedPreferences(prefName, MODE_PRIVATE);
          SharedPreferences.Editor editor = prefs.edit();
        
   editor.clear();
   editor.commit();
  }
 });
    }
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }    
}
Output look like below images:




How to Update Values from Android to SharedPreferences

Step 1 : Select File -> New -> Project -> Android Application Project (or) Android Project. Fill the forms and click "Finish" button.
Step 2 : Open res -> layout -> activity_main.xml (or) main.xml and add following code :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
 
    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:hint="Id"
        android:padding="11dp"
        android:ems="10"
        android:inputType="number" >
 
        <requestFocus />
    </EditText>
 
    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:hint="Name"
        android:padding="11dp"
        android:ems="10"
        android:inputType="textPersonName" />
 
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText2"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:padding="11dp"
        android:text="Save" />
 
    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"        
 android:layout_below="@+id/button1"
 android:layout_marginTop="20dp"
 android:padding="11dp"
        android:text="Select" />
    
    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"        
 android:layout_below="@+id/button2"
 android:layout_marginTop="20dp"
 android:padding="11dp"
        android:text="Update" />
 
</RelativeLayout>
Step 3 : Open src -> package -> MainActivity.java and add following code :
package balaji.shared_update;
 
import android.os.Bundle;
import android.app.Activity;
import android.content.SharedPreferences;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
 
public class MainActivity extends Activity {
 
 private SharedPreferences prefs;
 private String prefName = "report";
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        final EditText e_id=(EditText) findViewById(R.id.editText1);
        final EditText e_name=(EditText) findViewById(R.id.editText2);
        Button save=(Button) findViewById(R.id.button1);
        Button select=(Button) findViewById(R.id.button2);
        Button update=(Button) findViewById(R.id.button3);
        
        save.setOnClickListener(new View.OnClickListener() {
   
  @Override
  public void onClick(View v) {
   // TODO Auto-generated method stub
    
   prefs = getSharedPreferences(prefName, MODE_PRIVATE);
          SharedPreferences.Editor editor = prefs.edit();
        
          //---save the values in the EditText view to preferences---
   editor.putInt("id", Integer.parseInt(e_id.getText().toString()));
          editor.putString("name", e_name.getText().toString());
        
          //---saves the values---
                 editor.commit();
        
          Toast.makeText(getBaseContext(), "Saved",
    Toast.LENGTH_SHORT).show();
  }
 });
        
        select.setOnClickListener(new View.OnClickListener() {
   
  @Override
  public void onClick(View v) {
   // TODO Auto-generated method stub
    
   prefs = getSharedPreferences(prefName, MODE_PRIVATE);
   
          Toast.makeText(getBaseContext(), String.valueOf(prefs.getInt
    ("id", 100)), Toast.LENGTH_SHORT).show();
          Toast.makeText(getBaseContext(), prefs.getString
    ("name", "Balaji"), Toast.LENGTH_SHORT).show();
  }
 });
        
        update.setOnClickListener(new View.OnClickListener() {
   
  @Override
  public void onClick(View v) {
   // TODO Auto-generated method stub
    
   prefs = getSharedPreferences(prefName, MODE_PRIVATE);
          SharedPreferences.Editor editor = prefs.edit();
        
          //---save the values in the EditText view to preferences---
   editor.putInt("id", Integer.parseInt(e_id.getText().toString()));
         editor.putString("name", e_name.getText().toString());
        
          //---saves and update the values both are same---
                 editor.commit();
        
          Toast.makeText(getBaseContext(), "Updated Successfully",
    Toast.LENGTH_SHORT).show();
  }
 });
    }
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }    
}
Your Output look like below images :






How to Retrive and Select Values from SharedPreferences to Android

Step 1 : Select File -> New -> Project -> Android Application Project (or) Android Project. Fill the forms and click "Finish" button.
Step 2 : Open res -> layout -> activity_main.xml (or) main.xml and add following code :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
 
    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:hint="Id"
        android:padding="11dp"
        android:ems="10"
        android:inputType="number" >
 
        <requestFocus />
    </EditText>
 
    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:hint="Name"
        android:padding="11dp"
        android:ems="10"
        android:inputType="textPersonName" />
 
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText2"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:padding="11dp"
        android:text="Save" />
 
    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"        
 android:layout_centerVertical="true"
 android:padding="11dp"
        android:text="Select" />
 
</RelativeLayout>
Step 3 : Open src -> package -> MainActivity.java and add following code :
package balaji.shared_select;
 
import android.os.Bundle;
import android.app.Activity;
import android.content.SharedPreferences;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
 
public class MainActivity extends Activity {
 
 private SharedPreferences prefs;
 private String prefName = "report";
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        final EditText e_id=(EditText) findViewById(R.id.editText1);
        final EditText e_name=(EditText) findViewById(R.id.editText2);
        Button save=(Button) findViewById(R.id.button1);
        Button select=(Button) findViewById(R.id.button2);
        
        save.setOnClickListener(new View.OnClickListener() {
   
  @Override
  public void onClick(View v) {
   // TODO Auto-generated method stub
    
   prefs = getSharedPreferences(prefName, MODE_PRIVATE);
          SharedPreferences.Editor editor = prefs.edit();
        
          //---save the values in the EditText view to preferences---
   editor.putInt("id", Integer.parseInt(e_id.getText().toString()));
   editor.putString("name", e_name.getText().toString());
        
          //---saves the values---
                 editor.commit();
        
          Toast.makeText(getBaseContext(), "Saved",
    Toast.LENGTH_SHORT).show();
  }
 });
        
        select.setOnClickListener(new View.OnClickListener() {
   
  @Override
  public void onClick(View v) {
   // TODO Auto-generated method stub
    
   prefs = getSharedPreferences(prefName, MODE_PRIVATE);
   
          Toast.makeText(getBaseContext(), String.valueOf(prefs.getInt
    ("id", 100)), Toast.LENGTH_SHORT).show();
          Toast.makeText(getBaseContext(), prefs.getString
    ("name", "Balaji"), Toast.LENGTH_SHORT).show();
  }
 });
    }
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}
Output look like below image :



How to Store and Insert Values from Android to SharedPreferences

Step 1 : Select File -> New -> Project -> Android Application Project (or) Android Project. Fill the forms and click "Finish" button.
Step 2 : Open res -> layout -> activity_main.xml (or) main.xml and add following code :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
 
    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="36dp"
        android:padding="11dp"
        android:hint="Id"
        android:ems="10"
        android:inputType="number">
 
        <requestFocus />
    </EditText>
 
    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="38dp"
        android:padding="11dp"
        android:hint="Name"
        android:ems="10"
        android:inputType="textPersonName" />
 
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText2"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="46dp"
        android:padding="11dp"
        android:text="Save" />
 
</RelativeLayout>
Step 3 : Open src -> package -> MainActivity.java and add following code :
package balaji.shared_insert;
 
import android.os.Bundle;
import android.app.Activity;
import android.content.SharedPreferences;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
 
public class MainActivity extends Activity {
 
 private SharedPreferences prefs;
 private String prefName = "report";
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        final EditText e_id=(EditText) findViewById(R.id.editText1);
        final EditText e_name=(EditText) findViewById(R.id.editText2);
        Button save=(Button) findViewById(R.id.button1);
        
        save.setOnClickListener(new View.OnClickListener() {
   
  @Override
  public void onClick(View v) {
   // TODO Auto-generated method stub
    
   prefs = getSharedPreferences(prefName, MODE_PRIVATE);
          SharedPreferences.Editor editor = prefs.edit();
        
          //---save the values in the EditText view to preferences---
   editor.putInt("id", Integer.parseInt(e_id.getText().toString()));
          editor.putString("name", e_name.getText().toString());
        
          //---saves the values---
                 editor.commit();
        
          Toast.makeText(getBaseContext(), "Saved",
    Toast.LENGTH_SHORT).show();
  }
 });        
    }
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }    
}
Your Output like below image:

How to Play MP3 Using Swing Code

Playing Mp3 using this java code  you need “Java Media Framework”, which can be download from following link:
www.oracle.com/technetwork/java/javase/download-142937.html

The Java Media Framework (JMF) is a Java library that enables audio, video and other time-based media to be added to Java  applications and applets.



Download and install this  setup, after installation the system will restart and it set default User Environment variable for jmf.

Copy this code , compile and run this program and enjoy  your own player.
import java.io.*;

 import java.awt.*;

 import javax.swing.*;

 import java.awt.event.*;

 import javax.swing.filechooser.*;

 import javax.swing.SwingUtilities;

 import javax.media.*;

 import java.io.File;

 import java.net.URL;

 import javax.media.Manager;

 import javax.media.Player;

class audio extends JPanel implements ActionListener

 {

JFrame frame;

 JButton b1,b3;

 JPanel p,p2;

 JFrame f1;

 JMenuBar mbar;

 JMenu m1,m2;

 JMenuItem ofile,exitfile,aboutus;

 JFileChooser fc;

 private Player audioplayer=null;

 private File file;

public audio()

 {

 f1=new JFrame("Audio Player");

 f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

 fc=new JFileChooser();

 mbar=new JMenuBar();

 mbar.setOpaque(true);

 mbar.setBackground(new Color(154, 165, 127));

m1=new JMenu("File");

 m2=new JMenu("Help");

 mbar.add(m1);

 mbar.add(m2);

 ofile=new JMenuItem("Open");

 ofile.addActionListener(new playing());

exitfile=new JMenuItem("Exit");

 exitfile.addActionListener(this);

 aboutus=new JMenuItem("AboutUs");

 aboutus.addActionListener(this);

 m1.add(ofile);

 m1.addSeparator();

 m1.add(exitfile);

 m2.add(aboutus);

f1.setJMenuBar(mbar);

 p=new JPanel();

 p2=new JPanel();

 p.setLayout(null);

 p.setBackground(Color.blue);

 p.add(p2).setBounds(0,0,350,60);

 p2.setBackground(Color.darkGray);

 f1.add(p);

b1=new JButton("Play");

 b1.addActionListener(new playing());

 b3=new JButton("Stop");

 b3.setEnabled(false);

 b3.addActionListener(this);

 p2.add(b1);

 p2.add(b3);

 f1.setSize(350,110);

 f1.setVisible(true);

}

 public void actionPerformed(ActionEvent evt)

 {

 if(evt.getSource()==ofile)

 {

 int returnVal=fc.showOpenDialog(audio.this);

 if(returnVal==JFileChooser.APPROVE_OPTION)

 {

 file=fc.getSelectedFile();

 }

 else

 {

System.out.println("File Access Canceled by user");

 }

}

 if(evt.getSource()==b3)

 {

 audioplayer.stop();

 b1.setEnabled(true);

 b3.setEnabled(false);

 }

if(evt.getSource()==exitfile)

 {

 System.exit(0);

 }

 if(evt.getSource()==aboutus)

 {

 JFrame af1=new JFrame("About Us");

 af1.setVisible(true);

 af1.setSize(350,200);

 af1.setLocation(300,300);

 JPanel ap1=new JPanel();

 ap1.setBackground(Color.white);

 af1.add(ap1);

 JLabel l1=new JLabel("Developed by Ashish....",JLabel.CENTER);</p>

ap1.add(l1);

}

 }

 public void oplay()

 {

 fc.setFileSelectionMode(JFileChooser.FILES_ONLY);

 int result=fc.showOpenDialog(this);

 if(result==JFileChooser.CANCEL_OPTION)

 file=null;

 else

 file=fc.getSelectedFile();

 }

 public void cplay()

 {

 if(file==null)

 return;

 try

 {

audioplayer = Manager.createRealizedPlayer(file.toURI().toURL());

 audioplayer.start();

 }

 catch(Exception xe)

 {

 JOptionPane.showMessageDialog(frame,"Invalid Files Types..","Error  loading page",JOptionPane.ERROR_MESSAGE);</p>

}

 }

 public class playing implements ActionListener

 {

 public void actionPerformed(ActionEvent e)

 {

oplay();

 cplay();

 b1.setEnabled(false);

b3.setEnabled(true);

}

 }

 public static void main(String args[])

 {

 audio me = new audio();

}

}