Programming with Android: Data management. Dipartimento di Scienze dell Informazione Università di Bologna



Similar documents
App Development for Smart Devices. Lec #4: Files, Saving State, and Preferences

Android Persistency: Files

Chapter 2 Getting Started

Android Introduction. Hello Mihail L. Sichitiu 1

MMI 2: Mobile Human- Computer Interaction Android

getsharedpreferences() - Use this if you need multiple preferences files identified by name, which you specify with the first parameter.

Programming with Android: System Architecture. Dipartimento di Scienze dell Informazione Università di Bologna

Admin. Mobile Software Development Framework: Android Activity, View/ViewGroup, External Resources. Recap: TinyOS. Recap: J2ME Framework

Programming with Android: SDK install and initial setup. Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna

Now that we have the Android SDK, Eclipse and Phones all ready to go we can jump into actual Android development.

How to develop your own app

How to build your first Android Application in Windows

Developing Android Apps: Part 1

Android Application Development: Hands- On. Dr. Jogesh K. Muppala

ECWM511 MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction to Android

Programming with Android: SDK install and initial setup. Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna

Android Development. Marc Mc Loughlin

Mobile Application Development

Creating a List UI with Android. Michele Schimd

ANDROID APPS DEVELOPMENT FOR MOBILE GAME

Introduction to Android SDK Jordi Linares

Android App Development. Rameel Sethi

Laboratorio di Applicazioni Mobili (LAM 2014) Luciano Bononi

Tutorial #1. Android Application Development Advanced Hello World App

@ME (About) Marcelo Cyreno. Skype: marcelocyreno Linkedin: marcelocyreno Mail:

Android Programming Basics

Persistent Data Storage. Akhilesh Tyagi

Towards an Internet of Things: Android meets NFC. Dipartimento di Scienze dell Informazione Università di Bologna

Introduction to NaviGenie SDK Client API for Android

Android Environment SDK

directory to "d:\myproject\android". Hereafter, I shall denote the android installed directory as

Hello World. by Elliot Khazon

AdFalcon Android SDK Developer's Guide. AdFalcon Mobile Ad Network Product of Noqoush Mobile Media Group

CSE476 Mobile Application Development. Yard. Doç. Dr. Tacha Serif Department of Computer Engineering Yeditepe University

2. Click the download button for your operating system (Windows, Mac, or Linux).

Android Bootcamp. Elaborado (com adaptações) a partir dos tutoriais:

App Development for Android. Prabhaker Matet

ELET4133: Embedded Systems. Topic 15 Sensors

Advantages. manage port forwarding, set breakpoints, and view thread and process information directly

An Android-based Instant Message Application

Developing apps for Android OS: Develop an app for interfacing Arduino with Android OS for home automation

Programming Mobile Applications with Android

Android Environment SDK

Android Java Live and In Action

Saindo da zona de conforto resolvi aprender Android! by Daniel Baccin

Developing an Android App. CSC207 Fall 2014

ANDROID APPLICATION FOR FILE STORAGE AND RETRIEVAL OVER SECURED AND DISTRIBUTED FILE SERVERS SOWMYA KUKKADAPU B.E., OSMANIA UNIVERSITY, 2010 A REPORT

Android Apps Development Boot Camp. Ming Chow Lecturer, Tufts University DAC 2011 Monday, June 6, 2011

Lab 1 (Reading Sensors & The Android API) Week 3

Using Extensions or Cordova Plugins in your RhoMobile Application Darryn

Android Framework. How to use and extend it

Android Basics. Xin Yang

4. The Android System

Frameworks & Android. Programmeertechnieken, Tim Cocx

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

Android Programming. An Introduction. The Android Community and David Read. For the CDJDN April 21, 2011

ITG Software Engineering

Getting Started: Creating a Simple App

Android-Entwicklung. Michael secure Stapelberg

INTRODUCTION TO ANDROID CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 11 02/15/2011

Android Programming. Android App. Høgskolen i Telemark Telemark University College. Cuong Nguyen,

Android For Java Developers. Marko Gargenta Marakana

Lecture 1 Introduction to Android

Android Application Development. Yevheniy Dzezhyts

Developing Android Applications: Case Study of Course Design

Advertiser Campaign SDK Your How-to Guide

Mobile Solutions for Data Collection. Sarah Croft and Laura Pierik

Hadoop MapReduce Tutorial - Reduce Comp variability in Data Stamps

Mocean Android SDK Developer Guide

Android Application Development. Daniel Switkin Senior Software Engineer, Google Inc.

Android ( ) Frank Ducrest

Università Degli Studi di Parma. Distributed Systems Group. Android Development. Lecture 2 Android Platform. Marco Picone

Mobile App Sensor Documentation (English Version)

Developer Guide. Android Printing Framework. ISB Vietnam Co., Ltd. (IVC) Page i

How to Create an Android Application using Eclipse on Windows 7

Continuous Integration Part 2

Sending and Receiving Data via Bluetooth with an Android Device

Introduction to Android. CSG250 Wireless Networks Fall, 2008

Android Studio Application Development

Jordan Jozwiak November 13, 2011

Network/Socket Programming in Java. Rajkumar Buyya

Android Application Development - Exam Sample

Network Programming. CS 282 Principles of Operating Systems II Systems Programming for Android

Sterling Web. Localization Guide. Release 9.0. March 2010

The interactive HTTP proxy WebScarab Installation and basic use

Transcription:

Programming with Android: Data management Luca Bedogni Marco Di Felice Dipartimento di Scienze dell Informazione Università di Bologna

Data: outline Data Management in Android Preferences Text Files XML Files SQLite Database Content Provider

Managing Data Preferences: Key/Value pairs of data Direct File I/O: Read/write files onboard or on SD cards. Remember to req permission for writing, for instance, on SD card uest Database Tables: SQL Lite Application Direct Access: Read only access from res assets/raw directories Increase functionality: Content Providers: expose data to other applications Services: background processes that run detached from any view

Preference system Preferences are a convenient way to store configuration parameters Structured with a key-value mode Preferences Preference TAG Preference TAG Preference TAG Preference TAG Preference VALUE Preference VALUE Preference VALUE Preference VALUE

Preferences types Preferences could be either private or shared Shared means that other applications could potentially read such preferences Private means that they could be restricted at Application level Activity level

Shared preferences Preferences types getsharedpreferences(string name, Context.MODE_WORLD_READABLE); getsharedpreferences(string name, Context.MODE_WORLD_WRITABLE); Private at application level getsharedpreferences(string name, Context.MODE_PRIVATE); Private at activity level getpreferences(int mode);

Preference example public void oncreate(bundle savedinstancestate) { } Super.onCreate(savedInstanceState); setcontentview(r.layout.main); SharedPreferences pref = getsharedpreferences(my_tag, Context.MODE_PRIVATE); String mydata = pref.getstring(my_key, No pref ); TextView myview = (TextView)findViewById(R.id.myTextView); myview.settext(mydata);

Preferences editor How to edit preferences? You need to a SharedPreferences.Editor SharedPreferences.Editor editor = pref.edit(); editor.putstring("mydata", et.gettext().tostring()); editor.commit(); Be sure to commit operations at the end

Preferences screens Could be defined via XML Some specializations to ease the process CheckBoxPreference EditTextPreference ListPreference RingtonePreference Create a class that extends PreferenceActivity and call addpreferencesfromresource(r.xml.mypreferences);

The Android FileSystem Linux architecture User privileges Quite limited Onboard data Application's reserved data External data SD card (/mnt/sdcard)

File I/O Onboard Write to a designated place for each application Where? /data/data/<package>/files How? Use standard java I/O classes SD card Where? Environment.getExternalStorageDirectory() How? Use standard java I/O classes Permissions? android.permission.write_external_storage

Raw Text Files: how? Raw Text File Place it under res/raw/ directory Fill it with the text you like Populate a TextView with it s content inside the code TextView tv = (TextView)findViewById(R.id.tv_main); tv.settext(streamtostring(r.raw.myfile));

streamtostring() private String streamtostring(int id) { InputStream file = getresources().openrawresource(id); StringBuffer data = new StringBuffer(); DataInputStream dataio = new DataInputStream(file); String line = null; try { while ((line = dataio.readline())!= null) data.append(line + "\n"); dataio.close(); file.close(); } catch (IOException e) { } return data.tostring(); }

XML Files: how? XML File Place it under res/xml/ directory Start the file with <?xml version= 1.0 encoding= utf-8?> Add whatever you want with <mytag>value</mytag>

XML Files: example We want to visualize all the grades of this class Our XML file is like this: <student name= Student s name class= Laboratorio di Applicazioni Mobili year= 2012 grade= 30L />

XML Files: code example XmlResourceParser grades = getresources().getxml(r.xml.myxmlfile); LinearLayout ll = (LinearLayout)findViewById(R.id.myLL); int tag = -1; while (tag!= XmlResourceParser.END_DOCUMENT) { if (tag == XmlResourceParser.START_TAG) { } String name = grades.getname(); if (name.equals("student")) { } } TextView tv = new TextView(this); LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); tv.setlayoutparams(lp); String towrite = grades.getattributevalue(null, "name") + ; tv.settext(towrite); ll.addview(tv); try { tag = grades.next(); } catch (Exception e) { }