Filna 4
Filna 4
Filna 4
This method is used to create/open database. As the name suggests, it will open a database
connection if it is already there, otherwise, it will create a new one.
Example,
db=openOrCreateDatabase("XYZ_Database",SQLiteDatabase.CREATE_IF_NECESSARY,null);
ARGUMENTS
This command is used to execute a single SQL statement that doesn't return
any data means other than SELECT or any other.
db.execSQL("Create Table Temp (id Integer, name Text)");
In the above example, it takes "CREATE TABLE" statement of SQL. This will
create a table of "Integer" & "Text" fields.
This class is used to store a set of values. We can also say, it will map
ColumnName and relevant ColumnValue.
1.values.put("id", eid.getText().toString());
2.values.put("name", ename.getText().toString());
Example,
This interface provides random read-write access to the result set returned
by a database query.
Example,
1.c.moveToFirst();
2.while(!c.isAfterLast())
3.{
4. //statement
5.c.moveToNext();
6.}
Step 6: Close Cursor and Close Database connectivity
• This function returns long which holds the primary key of the newly
inserted row.
We can create a tableor insert data into the table using execSQL method
db.execSQL(“CREATE TABLE IF NOT EXISTS ABC Username
VARCHAR,password VARCHAR););
db.execSQL(“insert into values ABC (‘admin’,’admin’););
Updating data in the database
updateCountry.put(“country_name”,”united states”);
db.update(“tbl_countries”,updateCountry,”id=?”,new String[]{Long.toString(countryId)});
Deleting data from the database
To delete all the records from a table pass null for the WHERE clause and WHERE
clause argument array.
We can retrieve anything from database using an object of the Cursor class.
We will call a method of this class called rawQuery and it will return a resultset
with the cursor pointing to the table.
We can move the cursor forward and retrieve the data.
1 getColumnCount()
This method return the total number of columns of the table.
2 getColumnIndex(String columnName)
This method returns the index number of a column by specifying the
name of the column
3 getColumnName(int columnIndex)
This method returns the name of the column by specifying the index of
the column
4 getColumnNames()
This method returns the array of all the column names of the table.
5 getCount()
This method returns the total number of rows in the cursor
6 getPosition()
This method returns the current position of the cursor in the table
Transactions in SQLite
• A transaction is a unit of work that is performed against a database.
Transactions are units or sequences of work accomplished in a logical order
• SQLite is a transactional database that all changes and queries are atomic,
consistent, isolated, and durable (ACID).
• SQLite guarantees all the transactions are ACID compliant even if the
transaction is interrupted by a program crash, operation system dump, or
power failure to the computer.
Atomic: a transaction should be atomic. It means that a change cannot be broken
down into smaller ones. When you commit a transaction, either the entire transaction
is applied or not.
Consistent: a transaction must ensure to change the database from one valid state to
another. When a transaction starts and executes a statement to modify data, the
database becomes inconsistent. However, when the transaction is committed or
rolled back, it is important that the transaction must keep the database consistent.
SQLiteDatabase db=getDatabase();
db.beginTransaction();
try
{
//insert/update/delete
//insert/update/delete
db.setTransactionSuccessful();
}
finally
{db.endTransaction();
}
The first Android database we are leaving to search is the browser bookmarks.
MEDIAPLAYER
TELEPHONY AND
MESSAGING
How to send and receive SMS in your Android application.
SMS Telephony
1.Dialer
2.Contacts
3.Messaging-SMS/MMS
4.Settings app-a.Airplane mode b.Network
Selection(auto/manual)c.Call
5.Settings such as call waiting,call forwarding,diverting SIM application
toolkit(SAT)
6.Browser
7.CellBroadcastReceiver
In Android, you can use SmsManager API or devices Built-in SMS application to
send SMS's.
SmsManager API
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage("phoneNo", null, "sms message", null, null);
Android allows applications to view the state of the wireless connections at very low level.
Application can access almost all the information of a wifi connection.
Android provides WifiManager API to manage all aspects of WIFI connectivity. We can
instantiate this class by calling getSystemService method. Its syntax is given below −
WifiManager mainWifiObj;
mainWifiObj = (WifiManager) getSystemService(Context.WIFI_SERVICE);
In order to scan a list of wireless networks, you also need to register your BroadcastReceiver. It
can be registered using registerReceiver method with argument of your receiver class object. Its
syntax is given below −