Unit Iv
Unit Iv
b) Shared Preferences
Store private primitive data in key-value pairs.
b)Internal Storage
Store private data on the device memory.
c) External Storage
Store public data on the shared external storage.
d) Network Connection
Store data on the web with your own network server.
Introduction to SQLite
SQLite
• 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 250kb.
• SQLite supports the data types TEXT, INTEGER,
REAL.
• All other types must be converted into one of
these fields before saving them in the database.
• SQLiteDatabase is available on every Android
device .
• Using an SQLiteDatabase in Android does not
require any database setup or administration.
SQLiteOpenHelper
• To create and upgrade a database in your Android
application we will use a class called
SQLiteOpenHelper.
• In the constructor of your subclass you call
the super() method ofSQLiteOpenHelper,
specifying the database name and the current
database version.
In this class you need to override
the onCreate() and onUpgrade() methods.
bg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
editor=sharedPreferences.edit();
editor.putInt("mykey",1);
constraintLayout.setBackgroundColor(Color.RED);
editor.apply();
editor.commit();
}
});
}
Internal
and
External Storages
Android uses a file system that's similar to disk-based
file systems on other platforms.
<manifest ...>
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" /
>
...
</manifest>
If your app only needs to read the external
storage (but not write to it), then you need to
declare the READ_EXTERNAL_STORAGE
permission.
<manifest ...>
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
/>
...
</manifest>
Telephony APIs
• The android.telephony.TelephonyManager class
provides information about the telephony services
such as subscriber id, sim serial number, phone
network type etc.
• Moreover, you can determine the phone state etc
• Telephony APIs Provides to access the
information about the telephony services on the
device.
• Applications can use the methods in this class
to determine telephony services and states, as
well as to access some types of subscriber
information.
• Applications can also register a listener to
receive notification of telephony state changes.
To call an API for a specific subscription, use
createForSubscriptionId(int)
telephonyManager =
defaultSubTelephonyManager.createForSubscriptionId(subId)
public class MainActivity extends AppCompatActivity
{
TextView textView;
String details="";
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView=findViewById(R.id.tv);
TelephonyManager telephonyManager=(TelephonyManager)
getSystemService(Context.TELEPHONY_SERVICE);
details+=telephonyManager.getDeviceId();
details+=telephonyManager.getImei();
details+=telephonyManager.getDeviceSoftwareVersion();
details+=telephonyManager.getSimOperator();
details+=telephonyManager.getNetworkOperator();
details+=telephonyManager.getSubscriberId();
textView.setText(""+details);