Pages

Tuesday 8 April 2014

How to generate MD5, SHA, SHA256 key.

Hi,
     Here i am showing you have to create SHA,MD5,SHA256 key using keytool. You need to use this key to get API key of Google Map,GCM etc.  

 First give path to your java/bin folder like...

C:\Program Files\Java\jdk1.7.0\bin>   

Here is command which you need to use to get keys. I am using development debug key you can replace place,alias name,password with your release key.    

C:\Program Files\Java\jdk1.7.0\bin>keytool -list -v -keystore "C:\Users\Sandy\.a
ndroid\debug.keystore" -alias androiddebugkey -storepass android -keypass androi

And here you will get what you expecting.
lias name: androiddebugkey
Creation date: 7 Jan, 2014
Entry type: PrivateKeyEntry
Certificate chain length: 1
Certificate[1]:
Owner: CN=Android Debug, O=Android, C=US
Issuer: CN=Android Debug, O=Android, C=US
Serial number: 62b40369
Valid from: Tue Jan 07 11:05:57 IST 2014 until: Thu Dec 31 11:05:57 IST 2043
Certificate fingerprints:
         MD5:  45:BA:0F:92:F6:DD:D6:8D:E5:47:FA:56:CB:E6:0E:BF
         SHA1: 3C:CF:6B:35:5F:A5:C8:DB:4F:92:FE:CB:BD:53:81:F7:B5:6D:2D:2C
         SHA256: E6:3F:12:23:30:EB:EE:28:62:41:47:25:84:A7:D7:86:F0:77:DA:C8:26:
66:FA:04:EA:5F:21:87:7F:18:03:2F
         Signature algorithm name: SHA256withRSA
         Version: 3

Extensions:

#1: ObjectId: 2.5.29.14 Criticality=false
SubjectKeyIdentifier [
KeyIdentifier [
0000: 72 E1 56 BD FB A1 2E 4E   17 B6 B9 BF 9B 34 D7 C7  r.V....N.....4..
0010: C0 93 DD A7                                        ....
]
]
 

Wednesday 13 November 2013

Multi Item ListView using Base Adapter

                                         Multi Item ListView using Base Adapter

Today, We will learn how to create multi item listview using base adapter.

1. First create new project, After creating new project open your main.xml file and add listview in this like.

<ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="36dp" >
    </ListView>

2. Create custom layout for your listview which contain two textview and one imageview.
See following code.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:padding="6dip" >
    <ImageView
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="6dip"
        android:contentDescription="TODO"
        android:src="@drawable/ic_launcher" />
    <TextView
        android:id="@+id/names"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/icon"
        android:layout_marginLeft="14dp"
        android:layout_toRightOf="@+id/icon"
        android:text="TextView" />
    <TextView
        android:id="@+id/profession"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/icon"
        android:layout_alignLeft="@+id/names"
        android:text="TextView" />
</RelativeLayout>  


3. Create MainActivity.java.  :- Initialize listview , create two array for your listview, Suppose i take name and profession.   

you need to pass both arry and activity context to your custom adapter class. 

ListAdpater = new DynamicListAdapter(this,Names,Profession);  

Then set adapter to your listview like

listviewObj.setAdapter(ListAdpater);  

Take a look at following code.

public class MainActivity extends Activity { private ListView listviewObj; private DynamicListAdapter ListAdpater; private String[] Names = {"Sandeep Armal","Arun Choudhari", "Pradeep Chavan","Shrikant Pathe","Sarang Takone","Abhiraj Nagtode"}; private String[] Profession = {"Android Developer","Network Adminstartor", "Database Adminstrative","Customer Support","BMC Tool Manager","WildLife Photographer"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initializeVariable(); ListAdpater = new DynamicListAdapter(this,Names,Profession); listviewObj.setAdapter(ListAdpater); } private void initializeVariable() { listviewObj = (ListView)findViewById(R.id.listView1); } }
4.  Create Custom Adapetr class.
Then custom adapter class. in this code your are actually getting and setting value in listview.
Extend BaseAdapter class , After extending you will get override method in your class .

You can get view of your custom listview in getView() method. In this method you can initialize your textviews, ImageView and set value to this object.  See.

public class DynamicListAdapter extends BaseAdapter{ private String[] names; private String[] profession; private Activity context; private static LayoutInflater layoutInflater = null; public DynamicListAdapter(Activity context, String[] names, String[] profession) { this.names = names; this.profession = profession; this.context = context; layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); }
@Override public int getCount() { // TODO Auto-generated method stub return this.names.length; }
@Override public Object getItem(int position) { // TODO Auto-generated method stub return position; }
@Override public long getItemId(int position) { // TODO Auto-generated method stub return position; }
@Override public View getView(int arg0, View convertView, ViewGroup arg2) { View view = convertView;     if(convertView==null)               view = layoutInflater.inflate(R.layout.list_item_layout, null);   ImageView  icon = (ImageView)view.findViewById(R.id.icon); TextView tvNames = (TextView)view.findViewById(R.id.names); TextView tvProfession = (TextView)view.findViewById(R.id.profession); icon.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_launcher)); tvNames.setText(names[arg0]); tvProfession.setText(profession[arg0]);
return view; }} 
Enjoy code.

download code from here

Friday 24 August 2012

Detecting Android Device on Ubuntu(Linux) 0r ????????? No permission for Device

Hi,  
   To test our Android Application we need to use Device(Mobile Handset, Tablet or Emulator).
It's Easy to run Android Application on Emulator. But some time we need to run or test the Application on actual device. Before testing application we need to check whether device drive properly install or not.

When u connect device on Ubuntu. Many time it show one message on terminal( Command prompt),  

?????????? No permission for Device.   

At this time you need to kill  all adb using   write following on terminal. do not give any path before this.

>>>>killall adb    

Then you need to start your server or adb again.... But before that you need to close your eclipse.  then type on terminal...

>>>>Sudo '/your adb path here/' start-server

your server will start and showing starting message on terminal.

Then check whether testing device is visible or not on terminal. Use following command for that...

>>>> '/your adb path here/' devices

it show following message  

List of attached devices
Smart Tab 1.  

you will also find your device in Eclipse...
  open device in Eclipse... it will show the devices which are attached including Emulator

Enjoy...
Save Tree save world

Sunday 15 April 2012

Button-Android Fundamental-part-1

Button:-
               This is first part of Android fundamental for new Android user.In this part we study about the Button.

Create Button:-
                           To use Button, we need to create button in sample.xml file.we can create button by two way.
1.Using .xml file
2.By java code

1.Sample.xml file:-
                              You need to drag and drop button from form widget. or you manually write code for button in sample.xml file.
Here is code for Button.

<Button 
        android:id="@+id/button1"
        android:layout_width="106dp"
        android:layout_height="90dp"
        android:textSize="15px"
        android:text="Home"
        android:drawableTop="@drawable/faq"
        android:textColor="@color/myWhiteColor"
        android:background="@drawable/examguide_btnmain"
        android:gravity="center" android:layout_marginTop="25dp"></Button>

Property Description:- 
                            1.Android-id:-  You need to set id for button for further use in .java file.we need id of any widget to allocate some work for further coding.   
               Button Home=(Button)findViewById(R.id.button1); 
      Here we assign id to Home button.
                           2.Android:text:- Text which we require to show on Button. we assign "Home" text to Button.
                           3.Android:layout_height/Android:layout_width:-Here we decide height and width of Button.
                           4.android:drawableTop:- We can assign any image to button on respective side. Like top, Bottom, Right, Left.
                           5.android:textColor:- Using this property we can assign color to Button-text.
                           6.android:gravity:- Gravity are use to set gravity for text.you can choose any gravity as per your need.
                           7.android:layout_marginTop:- We can allocate margin in left, right, top and at bottom.
                           8.android:background:-  We use this property to hide button view. using this property we able to show only text and image of button but you need to use appropriate color which match with background.

2. By Programatically:-
                                       Here is sample code for add Button in java program.

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState); 

          //Create instance of button
          Button Home = new Button(this);
          Home .setText("Home");

         //we use linear layout to add button.
        LinearLayout layout = (LinearLayout ) View.inflate(this, R.layout.sample, null);
        //add the button to the view
       layout  .addView(Home );
       //set the layout using the inflated view
        setContentView(layout);
  
   }

3. Use of Button:-  
                            We use button for do some work after click on it.
 we use Onclick() method for that. Here is sample code which jump from one activity to second activity.

Home.setOnClickListener(new View.OnClickListener()
        {
          
            @Override
            public void onClick(View v)
            {

                 Intent intent = new Intent(getApplication(),Activity2.class);
                 startActivity(intent);

                 //Uri uri = Uri.parse("http://www.mpsc.gov.in/advertisements.jsp?head=1&status=1");
                // Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                // startActivity(intent);
 
            }
        });


Commented line are use to jump on specific web page.

4.Image:-
                    Here is image which use all above properties.
 


                  
         

Enjoy..........

SAVE TREE SAVE LIFE................
                           


 

Monday 2 April 2012

Resources NotFoundException

Error:-
         I got following error while Debugging OF my Application.
 
          Uncaught handler: thread main exiting due to uncaught exception
android.content.res.Resources$NotFoundException: String resource ID #0x1


I got this error when i am trying to fetch data from database and try to assign this data to EditText.

I had one integer return type method which return NoOfQuestion  which i want to show in EditText like this..

txtNoQuestion.setText((owq.getNoOfQuestion()));        //Incorrect        txtNoMarks.setText((owq.getMarks()));                        //Incorrect

Then i use following method and it solve my Problem.

txtNoQuestion.setText(Integer.toString(owq.getNoOfQuestion()));   //Correct                        txtNoMarks.setText(Integer.toString(owq.getMarks()));                 //correct                                



Enjoy......

SAVE TREE SAVE LIFE 

Sunday 1 April 2012

Single Time Login Page.

Introduction:-
                     Single time Login means Whenever we release Android Application in Android Market we 
need  allow login process to user only for single time. User enter his information and get login. When user open application second time then application directly jump on Main page instead of login page.
              For this process  we need to store some flag or value into database for further matching. For this, 

Process:-
                We create one static string variable in any activity which user must visit after login (Page which open after login page).
Write this code in onCreate () method of MainActivity.java
  public static final String PREFS_NAME = "MyPrefsFile";

Then we need to create object of SharedPreference in MainActivity.java which can retrieve and modify value.Only one instance of the  SharedPreference object is returned to any callers for the same name.

SharedPreferences settings = getSharedPreferences(MainActivity.PREFS_NAME, 0);

getSharedPreferences():- Retrieve and hold the contents of the preferences file ''MainActivity.PREFS_NAME".

Parameter:-
1. name(MainActivity.PREFS_NAME):- Desired preferences file. If a preferences file by this name does not exist, it will be created when you retrieve an editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).

2. mode(0):- MODE_WORLD_WRITEABLE to control permissions.

Then we need to create instance of  Editor.

 SharedPreferences.Editor editor = settings.edit();

Interface used for modifying values in a SharedPreferences object. All changes you make in an editor are batched, and not copied back to the original SharedPreferences until you call commit() or apply()
We set Boolean value to check user enter in this activity or not.
Following code for set value.

        //Set "ifLoggedIn" to true
          editor.putBoolean("hasLoggedIn", true);

          // Commit the edits!
          editor.commit();



Then we need to check this value in onCreate() method of LoginActivity.java whether user logged in or not.

SharedPreferences settings = getSharedPreferences(ExamGuideActivity.PREFS_NAME, 0);
        //Get "hasLoggedIn" value. If the value doesn't exist yet false is returned
        boolean hasLoggedIn = settings.getBoolean("hasLoggedIn", false);

        if(hasLoggedIn)
        {
             startActivity(new Intent(this, FirstActivity.class ));
        }
        else
        {
             startActivity(new Intent(this, LoginActivity.class ));
        }

Enjoy......

SAVE TREE SAVE LIFE 

                                                               

Monday 12 March 2012

SQLite

Introduction:-
                      SQLite is a popular choice for local/client storage on web browsers. It has many bindings to programming languages.SQLite is an Open Source Database which is embedded into Android. SQLite supports standard relational database features like SQL syntax, transactions and prepared statements. In addition it requires only little memory at runtime (approx. 250 KByte).

In Android:-
                    
SQLite is available on every Android device. Using an SQLite database in Android does not require any database setup or administration.
You only have to define the SQL statements for creating and updating the database. Afterwards the database is automatically managed for you by the Android platform.

Android Architecture :-
 1.SQLiteOpenHelper:-
                                      SqLiteOpenHelper are use to database creation and managing database version.
In SQLiteOpenHelper you implement onCreate(SQLiteDatabase), onUpgrade(SQLiteDatabase, int, int) and and optionally onOpen(SQLiteDatabase) method.

-onCreate(SQLiteDatabase db):-
                                            Called when the database is created for the first time.
                                 @Override
                                  public void onCreate(SQLiteDatabase db)
                                 {
                                             db.execSQL(DATABASE_CREATE);
                                  }

- onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion):-
                                             Called when the database needs to be upgraded.
                                    @Override
                                     public void onUpgrade(SQLiteDatabase db, int oldVersion,  int newVersion)
                                     {
                                             Log.w(TAG, "Upgrading database from version " + oldVersion
                                              + " to "
                                              + newVersion + ", which will destroy all old data");
                                               db.execSQL("DROP TABLE IF EXISTS titles");
                                              onCreate(db);
                                     }

- onOpen(SQLiteDatabase db):-
                                            Called when the database has been opened.
                                    
 2.SQLiteDatabase:-
                                      SQLiteDatabase is the base class for working with a SQLite database in Android. SQLiteDatabase has methods to create, delete, execute SQL commands, and perform other common database management tasks.

         3.Package:-
                           android.database.sqlite contain all related package of SQLite.

Creating Database:-
                                Following code show how to create database.Suppose it's a employee data including name and salary.                             
     private static final int DATABASE_VERSION = 1;
     private static final String DATABASE_CREATE =
                   "create table salary (_id integer primary key autoincrement, "
                   + "name text Not Null, salary text Not Null);";

Inserting Data in Database:-
                                           Using following function you can insert data into database.

                                public long insertsalary(String name, String salary)
                                {
                                               ContentValues initialValues = new ContentValues();
                                                initialValues.put(KEY_NAME, name);
                                                initialValues.put(KEY_SALARY, salary);
                                                return db.insert(DATABASE_TABLE, null, initialValues);
                                 }

Retrieving Data:- 
                     1. One Record:- Fetch one record at a time.
                                         public Cursor getdetails(String id) throws SQLException
                                        {
                                                        Cursor mCursor =
                                                                    db.query(true, DATABASE_TABLE, new String[]
                                                                     {
                                                                             KEY_ROWID,
                                                                              KEY_NAME,
                                                                             KEY_SALARY,
                                                                       },
                                                                     KEY_ROWID + "=" + id, null, null, null, null, null);
                                                       if (mCursor != null)
                                                      {
                                                                    mCursor.moveToFirst();
                                                       }
                                                      return mCursor;
                                       }

                 2. AllRecord:- Fetch all record..
                                   public Cursor getAllDetails()
                                  {
                                        return db.query(DATABASE_TABLE, new String[]
                                         {
                                                  KEY_ROWID,
                                                  KEY_NAME,
                                                  KEY_SALARY,
                                         },
                                             null,null,null,null,null);
                                   }
How to find Database:-
                                   SQLite database is located at DDMS. 
Select DDMS- Select FileBrowser\Data\Data\Your Package Name\Database\"database_Name.db".

SQLiteBrowser:-
                                 You find Database file but how to check the content of database whether insert correctly or not?. SQLite Browser is use to check the database content. You need to download it from following link.
Download SQlite Browser from here  

Delete One Record:-
                                 It's very easy to delete single record from database. You need only call the Delete() from your Activity and pass appropriate value(integer or string). You need to apply different query for integer and String.

                                1.Integer Parameter.
                                  public void delete(int value)
                                 {
                                        try{           
                                                   SQLiteDatabase db= this.getWritableDatabase();
                                                   db.delete(TABLE_NAME, COLUMN_ID+"="+value, null);

                                             }
                                             catch(Exception e){
                                             e.printStackTrace();
                                             }
                                  }    

        
                               2.String Parameter.
                                public void deleteBName(String keyword)
                               {
                                    try
                                    {
                                        SQLiteDatabase db=this.getWritableDatabase();
                          db.delete(TABLE_NAME,COLUMN1+"=?", new String [] {String.valueOf(keyword)});
                                    }
                                   catch(Exception e)
                                   {
                                           e.printStackTrace();
                                   }          
                             }

                   
Delete all Record:-
                               Following function delete all record.
                                public void deleteAll(){
                                try{           
                                       SQLiteDatabase db= this.getWritableDatabase();
                                       db.delete(TABLE_NAME, null, null);
                                     }catch(Exception e){
                                    e.printStackTrace();
                                     }
                               }


Thank you!

Save Tree Save Life.....