Posts

Showing posts from 2018

20 Simple Content Provider Example

      AndroidManifest.xml <? xml version= "1.0" encoding= "utf-8" ?> < manifest xmlns: android = "http://schemas.android.com/apk/res/android" package= "com.example.aslam.contentproviderexample2" > < uses-permission android :name= "android.permission.READ_CONTACTS" /> < application     android :allowBackup= "true"     android :icon= "@mipmap/ic_launcher"     android :label= "@string/app_name"     android :roundIcon= "@mipmap/ic_launcher_round"     android :supportsRtl= "true"     android :theme= "@style/AppTheme" > < activity android :name= ".MainActivity" > < intent-filter > < action android :name= "android.intent.action.MAIN" /> < category android :name= "android.intent.category.LAUNCHER" /> </ intent-filter >

19 AsynTask Loader

17 Simple Notification Program

Image
Notification Example program: =========================== package com.example.aslam.simplenotification1; import android.app.NotificationManager; import android.support.v4.app.NotificationCompat; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; public class MainActivity extends AppCompatActivity { NotificationCompat.Builder notification ; private static final int uniqueID = 45612 ; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout. activity_main ); notification = new NotificationCompat.Builder( this ); notification .setAutoCancel( true ); } public void notificationClick(View view) { notification .setSmallIcon(R.drawable. ic_launcher_background ); notification .setTicker( "you have received a message" ); notification .setWhen(System. currentTimeMillis ()); notification .

18 SQLite Database Connectivity

activity_main.xml: <?xml version= "1.0" encoding= "UTF-8" ?> < LinearLayout tools:context= ".MainActivity"     android:layout_height= "match_parent"     android:layout_width= "match_parent"     android:orientation= "vertical"     xmlns:tools= "http://schemas.android.com/tools"     xmlns:app= "http://schemas.android.com/apk/res-auto"     xmlns:android= "http://schemas.android.com/apk/res/android" > < EditText android:layout_height= "wrap_content" android:layout_width= "match_parent" android:hint= "Flower Name" android:inputType= "textPersonName" android:ems= "10" android:id= "@+id/name" /> < EditText android:layout_height= "wrap_content" android:layout_width= "match_parent" android:hint= "Flower Color" android:inpu

19 SQLIte SImple Database Example

Image
Algorithm:   Step 1)Create an Android Studio Project named as SQLiteCURD. Step 2) open activity_main.xml and design UI page. Step 3)Create a database Helper class named as DB_Controller which extends SQLiteOpenHelper . It is abstract class so we need to implement the abstract methods 1)onCreate()   2)onUpgrade() and 3)constructor for helper class as follows public class DB_Controller extends SQLiteOpenHelper {    //constructor   public DB_Controller( @androidx.annotation.Nullable Context context, @androidx.annotation.Nullable String name, @androidx.annotation.Nullable SQLiteDatabase.CursorFactory factory, int version)  { super (context, name, factory, version); } @Override   public void onCreate(SQLiteDatabase db) {  } @Override    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {  } }   Step 4) go to MainActivity class and create an object of SQLiteDatabase         Program:   activity_main.xml:

18 SharedPreferences

Image
Android provides many ways of storing data of an application. One of this way is called Shared Preferences. Shared Preferences allow you to save and retrieve data in the form of key,value pair. In order to use shared preferences, you have to call a method getSharedPreferences() that returns a SharedPreference instance pointing to the file that contains the values of preferences. SharedPreferences sharedpreferences =  getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);    The first parameter is the key and the second parameter is the MODE. MODE_PRIVATE By setting this mode, the file can only be accessed using calling application You can save something in the sharedpreferences by using SharedPreferences.Editor class. You will call the edit method of SharedPreference instance and will receive it in an editor object. Its syntax is −   Editor editor = sharedpreferences.edit(); editor.putString("key", "value"); e