Programmierung
                                 von Apps
                              Android System Services
Danny Fürniß, 12.06.2012, 1
Die Studierenden
                                  kennen die wichtigsten
                               Android System Services und
                              verstehen, wie diese eingesetzt
                                     werden können.
Danny Fürniß, 12.06.2012, 2
Danny Fürniß, 12.06.2012, 3




                              Bildquelle: http://developer.android.com/guide/basics/what-is-android.html
Was sind System Services?

                              Schnittstellen zur

                              •   Interaktion mit Device Hardware
                              •   Interaktion mit Media
                              •   Interaktion mit dem System
                              •   Interaktion mit anderen Apps
Danny Fürniß, 12.06.2012, 4
Welche gibt es?

                                Context.*_SERVICE

                                     map to

                                android.*Manager
Danny Fürniß, 12.06.2012, 5




                                                    Demo
Danny Fürniß, 12.06.2012, 6




                              Wie greift man darauf zu?
Activity
                              Lifecycle
Danny Fürniß, 12.06.2012, 7




                              Siehe auch „Learning Android“, S. 29
Danny Fürniß, 12.06.2012, 8




                              Wie greift man darauf zu?
Danny Fürniß, 12.06.2012, 9




                              Sensors
Danny Fürniß, 12.06.2012, 10




                               SensorManager




   Demo
Danny Fürniß, 12.06.2012, 11




                               Location
LocationManager
Danny Fürniß, 12.06.2012, 12




                               android.permission.ACCESS_FINE_LOCATION
                               android.permission.ACCESS_COARSE_LOCATION   Demo
Danny Fürniß, 12.06.2012, 13




                               Alarms
Danny Fürniß, 12.06.2012, 14




                               AlarmManager




   Demo
Danny Fürniß, 12.06.2012, 15




                               Notifications
Danny Fürniß, 12.06.2012, 16




                               NotificationManager




   Demo
Danny Fürniß, 12.06.2012, 17




                               AccountManager
Danny Fürniß, 12.06.2012, 18




                               Konten und Synchronisierung
Accounts lesen
Danny Fürniß, 12.06.2012, 19




                               android.permission.GET_ACCOUNTS
                                                                   Demo
Accounts authentifizieren
Danny Fürniß, 12.06.2012, 20




                               android.permission.USE_CREDENTIALS
                               android.permission.ACCOUNT_MANAGER   Demo
Danny Fürniß, 12.06.2012, 21




                               Account Token erneuern




   Demo
Account Token invalidieren
Danny Fürniß, 12.06.2012, 22




                                                            Demo
Accounts authentifizieren
Danny Fürniß, 12.06.2012, 23




                                     http://developer.android.com/training/id-auth/authenticate.html
HS Karlsruhe
                               NotenSpiegel
Danny Fürniß, 12.06.2012, 24




                                       https://play.google.com/store/apps/details?id=de.mdm.notenspiegel
Danny Fürniß, 12.06.2012, 25




                               Custom Account




   Demo
Danny Fürniß, 12.06.2012, 26




                               SyncAdapter
Danny Fürniß, 12.06.2012, 27




                               SyncAdapter




   Demo
SyncAdapter implementieren
                               Benötigt werden:

                               •   ContentProvider
                               •   Account
                               •   Sync Adapter Descriptor
                               •   Class extends AbstractThreadedSyncAdapter
                               •   SyncAdapterService
                               •   android.permission.READ_SYNC_STATS
                               •   android.permission.READ_SYNC_SETTINGS
Danny Fürniß, 12.06.2012, 28




                               •   android.permission.WRITE_SYNC_SETTINGS

                                                                               Demo
Danny Fürniß, 12.06.2012, 29




                               Backup
Danny Fürniß, 12.06.2012, 30




                               BackupManager




   Demo
Konfiguriere BackupAgent

                               <application
                                      android:icon="@drawable/ic_launcher"
                                      android:label="@string/app_name" 
                                      android:backupAgent=".PVABackupAgent">

                                      <meta‐data
                                             android:name="com.google.android.backup.api_key"
                                             android:value=„xyz" />
Danny Fürniß, 12.06.2012, 31




                                                                                                Demo
Implementiere BackupAgent

                               @Override
                               public void onCreate() {
                               super.onCreate();
                                      Log.i(TAG, "Erzeuge BackupHelper für shared preferences");
                                      SharedPreferencesBackupHelper bh = new
                                         SharedPreferencesBackupHelper(this, 
                                         "com.dfuerniss.pva.ss2012.sharedprefs_preferences");
                                      addHelper(BACKUP_KEY, bh);
                               }
Danny Fürniß, 12.06.2012, 32




                                                                                             Demo
Fordere Backup an


                               BackupManager bm = new BackupManager(ctx);
                               bm.dataChanged();
Danny Fürniß, 12.06.2012, 33




                                                                            Demo
Danny Fürniß, 12.06.2012, 34




                               ShareActionProvider
Konfiguration des Menüitems

                               <item android:id="@+id/shareAction" 
                                      android:showAsAction="always" 
                                      android:title="ShareAction"
                                      android:actionProviderClass=
                                        "android.widget.ShareActionProvider">
Danny Fürniß, 12.06.2012, 35
ShareActionProvider merken

                               MenuInflater inflater = mode.getMenuInflater();

                               inflater.inflate(R.menu.contextualactions, menu);

                               MenuItem item = menu.findItem(R.id.shareAction);

                               mShareActionProvider = (ShareActionProvider) 
                                      item.getActionProvider();
Danny Fürniß, 12.06.2012, 36
ShareIntent setzen

                               Intent shareIntent = new Intent();

                               shareIntent.setAction(Intent.ACTION_SEND);

                               shareIntent.putExtra(Intent.EXTRA_TEXT, text);

                               shareIntent.setType("text/plain");

                               mShareActionProvider.setShareIntent(shareIntent);
Danny Fürniß, 12.06.2012, 37




                                                                                   Demo
Sharing ohne ActionBar

                               Intent intent = new Intent(Intent.ACTION_SEND);
                               intent.setType("text/plain");
                               intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);

                               intent.putExtra(Intent.EXTRA_SUBJECT, "This is my subject.");
                               intent.putExtra(Intent.EXTRA_TEXT, 
                                      "This is my message text.");

                               startActivity(
                                      Intent.createChooser(intent, "Wähle das Share Target..."));
Danny Fürniß, 12.06.2012, 38




                                                                                               Demo
Danny Fürniß, 12.06.2012, 39




                               Barcode Scanner
Starte Scanner
                               Intent intent = 
                                      new Intent("com.google.zxing.client.android.SCAN");
                               intent.putExtra("SCAN_MODE", "QR_CODE_MODE");

                               final PackageManager packageManager = getPackageManager();
                               List<ResolveInfo> list = 
                                      packageManager.queryIntentActivities(intent, 
                                          PackageManager.MATCH_DEFAULT_ONLY);
                               final boolean isAvailable = list.size() > 0;
                               if (isAvailable) {
                                 startActivityForResult(intent, 0);
                               } else {
                                 Toast.makeText(this, "Keine Barcode‐Scanner App installiert", 
Danny Fürniß, 12.06.2012, 40




                                      Toast.LENGTH_SHORT).show();
                               }

                                                                                             Demo
Empfange Ergebnis
                               public void onActivityResult(int requestCode, int resultCode, 
                                      Intent intent) {
                                 if (requestCode == 0) {
                                   if (resultCode == RESULT_OK) {
                                     String contents = intent.getStringExtra("SCAN_RESULT");
                                     String format = intent.getStringExtra("SCAN_RESULT_FORMAT");

                                        TextView tv = (TextView) findViewById(R.id.qrcodeResult);
                                        tv.setText("Scanresult: " + contents + ", Format: " + 
                                         format);

                                       } else if (resultCode == RESULT_CANCELED) {
Danny Fürniß, 12.06.2012, 41




                                          Toast.makeText(this, "Scanvorgang abgebrochen", 
                                            Toast.LENGTH_SHORT).show();
                                       }
                                   }
                               }                                                                    Demo
Danny Fürniß, 12.06.2012, 42




                               Publishing
Application Publishing
Danny Fürniß, 12.06.2012, 43




                                 http://developer.android.com/guide/publishing/publishing_overview.html
Release vorbereiten
                               • Log Statements entfernen
                               • Verzeichnisse aufräumen
                               • Ressourcen aktualisieren
                               • android:debuggable auf false stellen
                               • Icon und Label für App bereitstellen
                               • Ggf. API Keys für externe Libs einbinden
                               • Ggf. AGBs oder End User License Agreement
                                 (EULA) bereitstellen
Danny Fürniß, 12.06.2012, 44




                               • Ggf. Serveradressen aktualisieren
App versionieren
                               android:versionCode
                                     Integer, maschinenlesbar (für User nicht sichtbar)

                               android:versionName
                                     String, z. B. major.minor.point (keine interne
                                     Verwendung)

                               Zugriff aus App
Danny Fürniß, 12.06.2012, 45




                                      PackageManager#getPackageInfo()
Release durchführen

                               •   Release Version bauen
                               •   APK signieren
                               •   App testen
                               •   App veröffentlichen
Danny Fürniß, 12.06.2012, 46
Portions of this presentation
                               are modifications based on
                               work created and shared by
                               Google and used according
                                   to terms described in
                                the Creative Commons 3.0
                                    Attribution License.
Danny Fürniß, 12.06.2012, 47

Weitere ähnliche Inhalte

PPTX
Overview of Android binder IPC implementation
PDF
Android Persistence and Networking
PDF
Android User Interface
PDF
Android Application Framework
PDF
2024 Trend Updates: What Really Works In SEO & Content Marketing
PDF
Storytelling For The Web: Integrate Storytelling in your Design Process
PDF
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
PDF
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
Overview of Android binder IPC implementation
Android Persistence and Networking
Android User Interface
Android Application Framework
2024 Trend Updates: What Really Works In SEO & Content Marketing
Storytelling For The Web: Integrate Storytelling in your Design Process
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
Anzeige

Android System Services

  • 1. Programmierung von Apps Android System Services Danny Fürniß, 12.06.2012, 1
  • 2. Die Studierenden kennen die wichtigsten Android System Services und verstehen, wie diese eingesetzt werden können. Danny Fürniß, 12.06.2012, 2
  • 3. Danny Fürniß, 12.06.2012, 3 Bildquelle: http://developer.android.com/guide/basics/what-is-android.html
  • 4. Was sind System Services? Schnittstellen zur • Interaktion mit Device Hardware • Interaktion mit Media • Interaktion mit dem System • Interaktion mit anderen Apps Danny Fürniß, 12.06.2012, 4
  • 5. Welche gibt es? Context.*_SERVICE map to android.*Manager Danny Fürniß, 12.06.2012, 5 Demo
  • 6. Danny Fürniß, 12.06.2012, 6 Wie greift man darauf zu?
  • 7. Activity Lifecycle Danny Fürniß, 12.06.2012, 7 Siehe auch „Learning Android“, S. 29
  • 8. Danny Fürniß, 12.06.2012, 8 Wie greift man darauf zu?
  • 10. Danny Fürniß, 12.06.2012, 10 SensorManager Demo
  • 12. LocationManager Danny Fürniß, 12.06.2012, 12 android.permission.ACCESS_FINE_LOCATION android.permission.ACCESS_COARSE_LOCATION Demo
  • 14. Danny Fürniß, 12.06.2012, 14 AlarmManager Demo
  • 15. Danny Fürniß, 12.06.2012, 15 Notifications
  • 16. Danny Fürniß, 12.06.2012, 16 NotificationManager Demo
  • 17. Danny Fürniß, 12.06.2012, 17 AccountManager
  • 18. Danny Fürniß, 12.06.2012, 18 Konten und Synchronisierung
  • 19. Accounts lesen Danny Fürniß, 12.06.2012, 19 android.permission.GET_ACCOUNTS Demo
  • 20. Accounts authentifizieren Danny Fürniß, 12.06.2012, 20 android.permission.USE_CREDENTIALS android.permission.ACCOUNT_MANAGER Demo
  • 21. Danny Fürniß, 12.06.2012, 21 Account Token erneuern Demo
  • 22. Account Token invalidieren Danny Fürniß, 12.06.2012, 22 Demo
  • 23. Accounts authentifizieren Danny Fürniß, 12.06.2012, 23 http://developer.android.com/training/id-auth/authenticate.html
  • 24. HS Karlsruhe NotenSpiegel Danny Fürniß, 12.06.2012, 24 https://play.google.com/store/apps/details?id=de.mdm.notenspiegel
  • 25. Danny Fürniß, 12.06.2012, 25 Custom Account Demo
  • 26. Danny Fürniß, 12.06.2012, 26 SyncAdapter
  • 27. Danny Fürniß, 12.06.2012, 27 SyncAdapter Demo
  • 28. SyncAdapter implementieren Benötigt werden: • ContentProvider • Account • Sync Adapter Descriptor • Class extends AbstractThreadedSyncAdapter • SyncAdapterService • android.permission.READ_SYNC_STATS • android.permission.READ_SYNC_SETTINGS Danny Fürniß, 12.06.2012, 28 • android.permission.WRITE_SYNC_SETTINGS Demo
  • 30. Danny Fürniß, 12.06.2012, 30 BackupManager Demo
  • 31. Konfiguriere BackupAgent <application android:icon="@drawable/ic_launcher" android:label="@string/app_name"  android:backupAgent=".PVABackupAgent"> <meta‐data android:name="com.google.android.backup.api_key" android:value=„xyz" /> Danny Fürniß, 12.06.2012, 31 Demo
  • 32. Implementiere BackupAgent @Override public void onCreate() { super.onCreate(); Log.i(TAG, "Erzeuge BackupHelper für shared preferences"); SharedPreferencesBackupHelper bh = new SharedPreferencesBackupHelper(this,  "com.dfuerniss.pva.ss2012.sharedprefs_preferences"); addHelper(BACKUP_KEY, bh); } Danny Fürniß, 12.06.2012, 32 Demo
  • 33. Fordere Backup an BackupManager bm = new BackupManager(ctx); bm.dataChanged(); Danny Fürniß, 12.06.2012, 33 Demo
  • 34. Danny Fürniß, 12.06.2012, 34 ShareActionProvider
  • 35. Konfiguration des Menüitems <item android:id="@+id/shareAction"  android:showAsAction="always"  android:title="ShareAction" android:actionProviderClass= "android.widget.ShareActionProvider"> Danny Fürniß, 12.06.2012, 35
  • 36. ShareActionProvider merken MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.contextualactions, menu); MenuItem item = menu.findItem(R.id.shareAction); mShareActionProvider = (ShareActionProvider)  item.getActionProvider(); Danny Fürniß, 12.06.2012, 36
  • 37. ShareIntent setzen Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_TEXT, text); shareIntent.setType("text/plain"); mShareActionProvider.setShareIntent(shareIntent); Danny Fürniß, 12.06.2012, 37 Demo
  • 38. Sharing ohne ActionBar Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); intent.putExtra(Intent.EXTRA_SUBJECT, "This is my subject."); intent.putExtra(Intent.EXTRA_TEXT,  "This is my message text."); startActivity( Intent.createChooser(intent, "Wähle das Share Target...")); Danny Fürniß, 12.06.2012, 38 Demo
  • 39. Danny Fürniß, 12.06.2012, 39 Barcode Scanner
  • 40. Starte Scanner Intent intent =  new Intent("com.google.zxing.client.android.SCAN"); intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); final PackageManager packageManager = getPackageManager(); List<ResolveInfo> list =  packageManager.queryIntentActivities(intent,  PackageManager.MATCH_DEFAULT_ONLY); final boolean isAvailable = list.size() > 0; if (isAvailable) { startActivityForResult(intent, 0); } else { Toast.makeText(this, "Keine Barcode‐Scanner App installiert",  Danny Fürniß, 12.06.2012, 40 Toast.LENGTH_SHORT).show(); } Demo
  • 41. Empfange Ergebnis public void onActivityResult(int requestCode, int resultCode,  Intent intent) { if (requestCode == 0) { if (resultCode == RESULT_OK) { String contents = intent.getStringExtra("SCAN_RESULT"); String format = intent.getStringExtra("SCAN_RESULT_FORMAT"); TextView tv = (TextView) findViewById(R.id.qrcodeResult); tv.setText("Scanresult: " + contents + ", Format: " +  format); } else if (resultCode == RESULT_CANCELED) { Danny Fürniß, 12.06.2012, 41 Toast.makeText(this, "Scanvorgang abgebrochen",  Toast.LENGTH_SHORT).show(); } } } Demo
  • 43. Application Publishing Danny Fürniß, 12.06.2012, 43 http://developer.android.com/guide/publishing/publishing_overview.html
  • 44. Release vorbereiten • Log Statements entfernen • Verzeichnisse aufräumen • Ressourcen aktualisieren • android:debuggable auf false stellen • Icon und Label für App bereitstellen • Ggf. API Keys für externe Libs einbinden • Ggf. AGBs oder End User License Agreement (EULA) bereitstellen Danny Fürniß, 12.06.2012, 44 • Ggf. Serveradressen aktualisieren
  • 45. App versionieren android:versionCode Integer, maschinenlesbar (für User nicht sichtbar) android:versionName String, z. B. major.minor.point (keine interne Verwendung) Zugriff aus App Danny Fürniß, 12.06.2012, 45 PackageManager#getPackageInfo()
  • 46. Release durchführen • Release Version bauen • APK signieren • App testen • App veröffentlichen Danny Fürniß, 12.06.2012, 46
  • 47. Portions of this presentation are modifications based on work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License. Danny Fürniß, 12.06.2012, 47