Content Provider pada Android Pemrograman IV V STIMIK

  • Slides: 34
Download presentation
Content Provider pada Android Pemrograman IV / V STIMIK Bani Saleh Free Powerpoint Templates

Content Provider pada Android Pemrograman IV / V STIMIK Bani Saleh Free Powerpoint Templates Bekasi – 2012 -P 10 Page 1

Definisi • Content Provider adalah mekanisme Android untuk mengakses data yang dimiliki aplikasi lain

Definisi • Content Provider adalah mekanisme Android untuk mengakses data yang dimiliki aplikasi lain Contoh: • melihat daftar alamat dari aplikasi contact • Menampilkan posisi peta dari nilai koordinat milik aplikasi GPS dll Free Powerpoint Templates Page 2

 • Pada umumnya pada content provider menggunakan SQLite sebagai penyimpan data Free Powerpoint

• Pada umumnya pada content provider menggunakan SQLite sebagai penyimpan data Free Powerpoint Templates Page 3

Content Provider yang digunakan (by Default) • Browser menyimpan data seperti bookmarks, browser history

Content Provider yang digunakan (by Default) • Browser menyimpan data seperti bookmarks, browser history • Call. Log data log seperti list panggilan, miss call dll • Contact mengambil data contact • Media. Store data dari media simpan seperti SD Card, video, image dll • Setting menyimpan data setting dan preferense Free Powerpoint Templates Page 4

Content provider dibuat sendiri • Format query URI: <standard_prefix>: //<authority>/<data_path>/<id> Contoh: Content: //com. Buku.

Content provider dibuat sendiri • Format query URI: <standard_prefix>: //<authority>/<data_path>/<id> Contoh: Content: //com. Buku. Provider/buku • Untuk mengambil data secara spesifik misalnya no id 25 maka penulisannya Content: //com. Buku. Provider/buku/25 Free Powerpoint Templates Page 5

Bagian URI • • Standard prefix content: // Authority nama content provider. Datapath pengalamatan

Bagian URI • • Standard prefix content: // Authority nama content provider. Datapath pengalamatan Id data spesifik yang diminta • Uri all. Contacts = Contacts. Contract. Contacts. CONTENT_URI; • Uri. parse("content: //com. content. PBuku/books") Free Powerpoint Templates project. Prov. BS; content. Provider. Buku Page 6

Query string Free Powerpoint Templates Page 7

Query string Free Powerpoint Templates Page 7

public class main. Activity extends List. Activity { /** Called when the activity is

public class main. Activity extends List. Activity { /** Called when the activity is first created. */ @Override public void on. Create(Bundle saved. Instance. State) { super. on. Create(saved. Instance. State); set. Content. View(R. layout. main); Uri all. Contacts = Contacts. Contract. Contacts. CONTENT_URI; String[] projection = new String[] {Contacts. Contract. Contacts. _ID, Contacts. Contract. Contacts. DISPLAY_NAME, Contacts. Contract. Contacts. HAS_PHONE_NUMBER}; Cursor c = managed. Query( Free Powerpoint Templates Page 8

Application view Android Contact view Free Powerpoint Templates Page 9

Application view Android Contact view Free Powerpoint Templates Page 9

Free Powerpoint Templates Page 10

Free Powerpoint Templates Page 10

 • Untuk mengakses data ditambahkan permission Free Powerpoint Templates Page 11

• Untuk mengakses data ditambahkan permission Free Powerpoint Templates Page 11

Android Multimedia • Android menyediakan fungsi multimedia yang komprehensip • Pengolahan image, record, voice,

Android Multimedia • Android menyediakan fungsi multimedia yang komprehensip • Pengolahan image, record, voice, play music Free Powerpoint Templates Page 12

Tipe media yang didukung Free Powerpoint Templates Page 13

Tipe media yang didukung Free Powerpoint Templates Page 13

Permission • Aplikasi yang merekam berbagai tipe media meminta settingan permission pada Android. Manifest.

Permission • Aplikasi yang merekam berbagai tipe media meminta settingan permission pada Android. Manifest. Misal: • <uses-permission android: name=”android. permission. RECORD_AUDIO”/> • <uses-permission android: name=”android. permission. RECORD_VIDEO”/> Free Powerpoint Templates Page 14

Audio Player • Trend mobile device. Tidak sekedar untuk telpon. • Penggunaan multimedia •

Audio Player • Trend mobile device. Tidak sekedar untuk telpon. • Penggunaan multimedia • Aspek hiburan Free Powerpoint Templates Page 15

open. CORE • Android mendukung multimedia sistem multimedia open source yang disebut Open. CORE.

open. CORE • Android mendukung multimedia sistem multimedia open source yang disebut Open. CORE. • Java open source, platform multimedia yang mendukung format-format multimedia • see: file: ///home/adam/android-sdklinux_x 86/docs/guide/appendix/media-formats. html Free Powerpoint Templates Page 16

Arsitektur Open. CORE Free Powerpoint Templates Page 17

Arsitektur Open. CORE Free Powerpoint Templates Page 17

Audio Player • Letakkan file mp 3 dalam folder res/raw • Buatlah instance Media.

Audio Player • Letakkan file mp 3 dalam folder res/raw • Buatlah instance Media. Player dan link ke file mp 3 kemudian panggil dengan Media. Player. create(). player = Media. Player. create(this, R. raw. bird); • Call Media. Player method, prepare() dan start() Free Powerpoint Templates Page 18

Main. xml <? xml version="1. 0" encoding="utf-8"? > <Linear. Layout xmlns: android="http: //schemas. android.

Main. xml <? xml version="1. 0" encoding="utf-8"? > <Linear. Layout xmlns: android="http: //schemas. android. com/apk/res/android" android: orientation="vertical" android: layout_width="fill_parent" android: layout_height="fill_parent"> <Text. View android: layout_width="fill_parent" android: layout_height="wrap_content" android: text="@string/hello" /> <Button android: layout_width="fill_parent" android: layout_height="wrap_content" android: id="@+id/bird" android: text="Bird"></Button> <Button android: layout_width="fill_parent" android: layout_height="wrap_content" android: id="@+id/frog" android: text="Frog"></Button> <Button android: layout_width="fill_parent" android: layout_height="wrap_content" android: id="@+id/cat" android: text="Cat"></Button> </Linear. Layout> Free Powerpoint Templates Page 19

Audio. java Paket import import android. app. Activity; android. media. Media. Player; android. os.

Audio. java Paket import import android. app. Activity; android. media. Media. Player; android. os. Bundle; android. view. Key. Event; android. view. View. On. Click. Listener; android. widget. Button; android. widget. Toast; Free Powerpoint Templates Page 20

Audio. java Toast. make. Text(this, is. Playing+" Frogs", Toast. LENGTH_LONG). show(); player = Media.

Audio. java Toast. make. Text(this, is. Playing+" Frogs", Toast. LENGTH_LONG). show(); player = Media. Player. create(this, R. raw. frogs); }else if (arg==3){ Toast. make. Text(this, is. Playing+" Cat", Toast. LENGTH_LONG). show(); player = Media. Player. create(this, R. raw. cat); Free Powerpoint Templates Page 21

Susunan file Free Powerpoint Templates Page 22

Susunan file Free Powerpoint Templates Page 22

Free Powerpoint Templates Page 23

Free Powerpoint Templates Page 23

Pengolahan grafik pada Android • Secara lokal gambar diletakkan pada folder res/drawable • Diakses

Pengolahan grafik pada Android • Secara lokal gambar diletakkan pada folder res/drawable • Diakses melalui resources identifier seperti R. drawable. gambarku • get. Pixel() and set. Pixel() Free Powerpoint Templates Page 24

Membentuk gambar 2 dimensi sederhana dengan program Paket yang diperlukan • import android. graphics.

Membentuk gambar 2 dimensi sederhana dengan program Paket yang diperlukan • import android. graphics. Canvas; • import android. graphics. drawable. Shape. Drawable; • import android. graphics. drawable. shapes. Rect. Shape; (project= gambarsederhana) Free Powerpoint Templates Page 25

Membentuk gambar 2 dimensi sederhana private Shape. Drawable m. Drawable = new Shape. Drawable();

Membentuk gambar 2 dimensi sederhana private Shape. Drawable m. Drawable = new Shape. Drawable(); //create view public Simple. View(Context context) { super(context); set. Focusable(true); this. m. Drawable = new Shape. Drawable(new Rect. Shape()); //MEMBUAT OBJEK SEGIEMPAT this. m. Drawable. get. Paint(). set. Color(0 x. FFFF 0000); } Free Powerpoint Templates Page 26

Membentuk gambar 2 dimensi sederhana @Override protected void on. Draw(Canvas canvas) { int x

Membentuk gambar 2 dimensi sederhana @Override protected void on. Draw(Canvas canvas) { int x = 150; //POSISI TERHADAP LAYAR, SUMBU X int y = 10; // POSISI TERHADAP LAYAR, SUMBU Y int width = 300; //RESOLUSI LEBAR int height = 350; //RESOLUSI TINGGI this. m. Drawable. set. Bounds(x, y, x + width, y + height); this. m. Drawable. draw(canvas); y += height + 5; } Free Powerpoint Templates Page 27

Hasil Free Powerpoint Templates Page 28

Hasil Free Powerpoint Templates Page 28

Menggambar dengan XML • Lebih sederhana • Mudah dimodifikasi pada file XML • Mudah

Menggambar dengan XML • Lebih sederhana • Mudah dimodifikasi pada file XML • Mudah ditambahkan dengan menambahkan file XML (project: Gambardg. XML) Free Powerpoint Templates Page 29

Komponen pembentuk • File Layout untuk menampilkan urutan gambar xmllayout. xml • File gambar

Komponen pembentuk • File Layout untuk menampilkan urutan gambar xmllayout. xml • File gambar pada format xml yang disimpan pada folder drawable gambar 1. xml, gambar 2. xml, gambar 3. xml, kotak. xml, garis. xml • File Java untuk memproses aplikasi create. Gambar. XML. java Free Powerpoint Templates Page 30

Objek yang ditampilkan File yang memanggil Free Powerpoint Templates Page 31

Objek yang ditampilkan File yang memanggil Free Powerpoint Templates Page 31

Free Powerpoint Templates Page 32

Free Powerpoint Templates Page 32

referensi 1. wei Meng Lee, “Beginning Android Application Development”, 2011 2. Satya Komatineni, Dave

referensi 1. wei Meng Lee, “Beginning Android Application Development”, 2011 2. Satya Komatineni, Dave Mac. Lean, “ Pro Android 4”, 3. Adam AB, “Modul Praktikum Mobile Computing”, 2011 4. project. Prov. BS; content. Provider. Buku, gabardengan. XML, belajaraudio Free Powerpoint Templates Page 33

Pekerjaan Rumah • Kerjakan file project content provider “project. Content. Prov. BS. zip” •

Pekerjaan Rumah • Kerjakan file project content provider “project. Content. Prov. BS. zip” • Kerjakan file “content. Provider. Buku. zip” dan buatlah aplikasi yang menampilkan data dari project database tersebut (content. Provider. Buku) Free Powerpoint Templates Page 34