Académique Documents
Professionnel Documents
Culture Documents
INTRODUCTION
Android is a Linux-based operating system for mobile devices such as smartphones and tablet computers. It is developed by the Open Handset Alliance, led by Google, and other companies.
RELATED INFORMATIOS
LAYERS ON ANDROID OS
A tool called dx is used to convert some (but not all) Java .class files into the .dex format.
FUNCTION OF XML
Layout
String storage Shared preferences
Define Buttons and Text fields Calling that layout on run time
All strings for that application can be stored in an xml file String ID are called to with @ symbol to get the string value Retained values can be stored in xml files Using inbuilt functions we can fetch the data from that xml file using the ID
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello, I am a TextView" /> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello, I am a Button" /> </LinearLayout>
super.onCreate(savedInstanceState); setContentView(R.layout.main_layout);
}
String.xml file in the android project is the space for string storage
public class Calc extends Activity { public static final String PREFS_NAME = "MyPrefsFile";
@Override protected void onStop(){ super.onStop(); // We need an Editor object to make preference changes. // All objects are from android.context.Context SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("silentMode", mSilentMode); // Commit the edits! editor.commit();
SQLITE
The recommended method to create a new SQLite database is to create a subclass of SQLiteOpenHelper
override the onCreate() method, in which you can execute a SQLite command to create tables in the database.
SQLITE(EXAMPLE)
public class ContactOpenHelper extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 2; private static final String _TABLE_CONTACTS = contact"; private static final String TABLE_CREATE = "CREATE TABLE " + TABLE_CONTACT + " (" + KEY_ID + " TEXT, " + KEY_NAME + " TEXT KEY_PH_NO + " TEXT);";
ContactOpenHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); }
SQLITE(INSERT)
ContentValues values = new ContentValues(); values.put(KEY_NAME, contact.getName()); values.put(KEY_PH_NO, contact.getPhoneNu()); sql = "INSERT INTO table1 (field1, field2, field3) " + "VALUES (" + KEY_ID+ ", " + KEY_NAME +,+KEY_PH_NO+ ")"; Log.v("Test Saving", sql); myDataBase.rawQuery(sql, null);
SQLITE(READ)
public Contact getContact(int id) { SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.query(TABLE_CONTACTS, new String[] { KEY_ID, KEY_NAME, KEY_PH_NO }, KEY_ID + "=?", new String[] { String.valueOf(id) }, null, null, null,
Contact contact = new Contact(Integer.parseInt(cursor.getString(0)), cursor.getString(1), cursor.getString(2)); // return contact return contact; }
LAYOUTS
LAYOUTS
LINEAR FRAME TABLE RELATIVE
CONTENT PROVIDERS
Enable use to get the data from other process too
Getting the data from the phone applications like sms ,log,contact etc are being handled by content providers
RESOURCE MANAGER
Once an application is being created it works on all cofiguration of phones with same android os version
NOTIFICATION MANAGER
A persistent icon that goes in the status bar and is accessible through the launcher, (when the user selects it, a designated Intent can be launched),
ACTIVITY MANAGER
Configuration changes
Hands on Exercise
Step 1:Hello world Application Step 2:Set a toast/notification Step3:Send sms Step4:Set notification for receive sms Step5:Sms notification application is being made