android system services
DESCRIPTION
Unterlage zur Android Vorlesung "Programmierung von Apps" an der Hochschule Karlsruhe. Die Studierenden kennen die wichtigsten Android System Services und verstehen, wie diese eingesetzt werden können.TRANSCRIPT
![Page 1: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/1.jpg)
Dann
y Für
niß,
12.
06.2
012,
1
Programmierungvon Apps
Android System Services
![Page 2: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/2.jpg)
Dann
y Für
niß,
12.
06.2
012,
2
Die Studierenden kennen die wichtigsten
Android System Services und verstehen, wie diese eingesetzt
werden können.
![Page 3: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/3.jpg)
Dann
y Für
niß,
12.
06.2
012,
3
Bildquelle: http://developer.android.com/guide/basics/what-is-android.html
![Page 4: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/4.jpg)
Dann
y Für
niß,
12.
06.2
012,
4
Was sind System Services?
Schnittstellen zur
• Interaktion mit Device Hardware• Interaktion mit Media• Interaktion mit dem System• Interaktion mit anderen Apps
![Page 5: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/5.jpg)
Dann
y Für
niß,
12.
06.2
012,
5
Welche gibt es?
Demo
Context.*_SERVICE
map to
android.*Manager
![Page 6: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/6.jpg)
Dann
y Für
niß,
12.
06.2
012,
6
Wie greift man darauf zu?
![Page 7: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/7.jpg)
Dann
y Für
niß,
12.
06.2
012,
7
Siehe auch „Learning Android“, S. 29
ActivityLifecycle
![Page 8: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/8.jpg)
Dann
y Für
niß,
12.
06.2
012,
8
Wie greift man darauf zu?
![Page 9: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/9.jpg)
Dann
y Für
niß,
12.
06.2
012,
9
Sensors
![Page 10: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/10.jpg)
Dann
y Für
niß,
12.
06.2
012,
10
SensorManager
Demo
![Page 11: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/11.jpg)
Dann
y Für
niß,
12.
06.2
012,
11
Location
![Page 12: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/12.jpg)
Dann
y Für
niß,
12.
06.2
012,
12
LocationManager
Demoandroid.permission.ACCESS_FINE_LOCATIONandroid.permission.ACCESS_COARSE_LOCATION
![Page 13: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/13.jpg)
Dann
y Für
niß,
12.
06.2
012,
13
Alarms
![Page 14: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/14.jpg)
Dann
y Für
niß,
12.
06.2
012,
14
AlarmManager
Demo
![Page 15: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/15.jpg)
Dann
y Für
niß,
12.
06.2
012,
15
Notifications
![Page 16: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/16.jpg)
Dann
y Für
niß,
12.
06.2
012,
16
NotificationManager
Demo
![Page 17: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/17.jpg)
Dann
y Für
niß,
12.
06.2
012,
17
AccountManager
![Page 18: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/18.jpg)
Dann
y Für
niß,
12.
06.2
012,
18
Konten und Synchronisierung
![Page 19: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/19.jpg)
Dann
y Für
niß,
12.
06.2
012,
19
Accounts lesen
Demoandroid.permission.GET_ACCOUNTS
![Page 20: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/20.jpg)
Dann
y Für
niß,
12.
06.2
012,
20
Accounts authentifizieren
Demoandroid.permission.USE_CREDENTIALSandroid.permission.ACCOUNT_MANAGER
![Page 21: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/21.jpg)
Dann
y Für
niß,
12.
06.2
012,
21
Account Token erneuern
Demo
![Page 22: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/22.jpg)
Dann
y Für
niß,
12.
06.2
012,
22
Account Token invalidieren
Demo
![Page 23: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/23.jpg)
Dann
y Für
niß,
12.
06.2
012,
23
Accounts authentifizieren
http://developer.android.com/training/id-auth/authenticate.html
![Page 24: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/24.jpg)
Dann
y Für
niß,
12.
06.2
012,
24
HS Karlsruhe NotenSpiegel
https://play.google.com/store/apps/details?id=de.mdm.notenspiegel
![Page 25: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/25.jpg)
Dann
y Für
niß,
12.
06.2
012,
25
Custom Account
Demo
![Page 26: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/26.jpg)
Dann
y Für
niß,
12.
06.2
012,
26
SyncAdapter
![Page 27: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/27.jpg)
Dann
y Für
niß,
12.
06.2
012,
27
SyncAdapter
Demo
![Page 28: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/28.jpg)
Dann
y Für
niß,
12.
06.2
012,
28
SyncAdapter implementieren
Demo
Benötigt werden:
• ContentProvider• Account• Sync Adapter Descriptor• Class extends AbstractThreadedSyncAdapter• SyncAdapterService• android.permission.READ_SYNC_STATS• android.permission.READ_SYNC_SETTINGS• android.permission.WRITE_SYNC_SETTINGS
![Page 29: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/29.jpg)
Dann
y Für
niß,
12.
06.2
012,
29
Backup
![Page 30: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/30.jpg)
Dann
y Für
niß,
12.
06.2
012,
30
BackupManager
Demo
![Page 31: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/31.jpg)
Dann
y Für
niß,
12.
06.2
012,
31
Konfiguriere BackupAgent
Demo
<applicationandroid:icon="@drawable/ic_launcher"android:label="@string/app_name" android:backupAgent=".PVABackupAgent">
<meta‐dataandroid:name="com.google.android.backup.api_key"android:value=„xyz" />
![Page 32: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/32.jpg)
Dann
y Für
niß,
12.
06.2
012,
32
Implementiere BackupAgent
Demo
@Overridepublic 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);}
![Page 33: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/33.jpg)
Dann
y Für
niß,
12.
06.2
012,
33
Fordere Backup an
Demo
BackupManager bm = new BackupManager(ctx);bm.dataChanged();
![Page 34: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/34.jpg)
Dann
y Für
niß,
12.
06.2
012,
34
ShareActionProvider
![Page 35: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/35.jpg)
Dann
y Für
niß,
12.
06.2
012,
35
Konfiguration des Menüitems
<item android:id="@+id/shareAction" android:showAsAction="always" android:title="ShareAction"android:actionProviderClass=
"android.widget.ShareActionProvider">
![Page 36: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/36.jpg)
Dann
y Für
niß,
12.
06.2
012,
36
ShareActionProvider merken
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.contextualactions, menu);
MenuItem item = menu.findItem(R.id.shareAction);
mShareActionProvider = (ShareActionProvider) item.getActionProvider();
![Page 37: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/37.jpg)
Dann
y Für
niß,
12.
06.2
012,
37
ShareIntent setzen
Demo
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, text);
shareIntent.setType("text/plain");
mShareActionProvider.setShareIntent(shareIntent);
![Page 38: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/38.jpg)
Dann
y Für
niß,
12.
06.2
012,
38
Sharing ohne ActionBar
Demo
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..."));
![Page 39: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/39.jpg)
Dann
y Für
niß,
12.
06.2
012,
39
Barcode Scanner
![Page 40: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/40.jpg)
Dann
y Für
niß,
12.
06.2
012,
40
Starte Scanner
Demo
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", Toast.LENGTH_SHORT).show();
}
![Page 41: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/41.jpg)
Dann
y Für
niß,
12.
06.2
012,
41
Empfange Ergebnis
Demo
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) {Toast.makeText(this, "Scanvorgang abgebrochen",
Toast.LENGTH_SHORT).show();}
}}
![Page 42: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/42.jpg)
Dann
y Für
niß,
12.
06.2
012,
42
Publishing
![Page 43: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/43.jpg)
Dann
y Für
niß,
12.
06.2
012,
43
Application Publishing
http://developer.android.com/guide/publishing/publishing_overview.html
![Page 44: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/44.jpg)
Dann
y Für
niß,
12.
06.2
012,
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• Ggf. Serveradressen aktualisieren
![Page 45: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/45.jpg)
Dann
y Für
niß,
12.
06.2
012,
45
App versionieren
android:versionCodeInteger, maschinenlesbar (für User nicht sichtbar)
android:versionNameString, z. B. major.minor.point (keine interne Verwendung)
Zugriff aus AppPackageManager#getPackageInfo()
![Page 46: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/46.jpg)
Dann
y Für
niß,
12.
06.2
012,
46
Release durchführen
• Release Version bauen• APK signieren• App testen• App veröffentlichen
![Page 47: Android System Services](https://reader033.vdocuments.pub/reader033/viewer/2022042513/554f563eb4c905b9508b50c1/html5/thumbnails/47.jpg)
Dann
y Für
niß,
12.
06.2
012,
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.