Photo credit: Kalexanderson / Foter.com / C C BY-NC-S A Android 4.1+ @mobileLarson @_openKnowledge Lars Röwekamp | CIO New Technologies
May 10, 2015
Ph
oto
cre
dit:
Ka
lexa
nd
ers
on
/ F
ote
r.co
m /
CC
BY
-NC
-SA
Android 4.1+ @mobileLarson @_openKnowledge
Lars Röwekamp | CIO New Technologies
Photo credit: Kalexanderson / Foter.com / CC BY-NC-SA
Agenda
NotificationsNavigationFragments
Connectivity
... and Stuff
Photo credit: Kalexanderson / Foter.com / CC BY-NC-SA
Notifications
Notifications Android 4.1+ - Noteworthy ...
MTC2013
Was bisher geschah ...
‣Notifications zum Informieren über Änderungen innerhalb der App‣Notification Area und Drawer als „Medium“ zur Darstellung der Änderungsinformation
Notifications Android 4.1+ - Noteworthy ...
MTC2013
Notifications Android 4.1+ - Noteworthy ...
MTC2013
Seit Jelly Bean können Notifications ...
‣... variabel in ihrer Größe sein‣... auf- und zugeklappt werden‣... verschiedene Aktionen anstoßen‣... eine Priorität besitzten
Notifications Android 4.1+ - Noteworthy ...
MTC2013
Notification Basis Layout
Notifications Android 4.1+ - Noteworthy ...
MTC2013
Notification Expanded Layout
‣Inbox‣BigPicture‣BigText‣Custom Layout
‣Expanded Style‣Compressed Style
Notifications Android 4.1+ - Noteworthy ...
MTC2013
Notification Expanded Layout
Notifications Android 4.1+ - Noteworthy ...
MTC2013
Notification Actions
Notifications Android 4.1+ - Noteworthy ...
MTC2013
Notification Actions
‣Darstellung als Button‣bis zu 3 Actions direkt anzeigbar‣alternativ „more“ Icon für Overflow
‣Pending Intents zur Starten der Aktion
Notifications Android 4.1+ - Noteworthy ...
MTC2013
Notification Priorities
Notifications Android 4.1+ - Noteworthy ...
MTC2013
Notification Stacking
Notifications Android 4.1+ - Noteworthy ...
MTC2013
Notification Stacking & Expanded Layout
Notifications Android 4.1+ - Noteworthy ...
MTC2013
BTW: Notification Best Practices
Notifications Android 4.1+ - Noteworthy ...
MTC2013
BTW: Kids, don‘t try this athome!
Notifications Android 4.1+ - Noteworthy ...
MTC2013
// Intent to call if notification is selectedIntent intent = new Intent(this, MyActivity.class);PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
// Build up notification with some dummy actionsNotification notification = new Notification.Builder(this) .setContentTitle("New Message from " + "@mobileLarson") .setContentText("Hi, what‘s up?") .setSmallIcon(R.drawable.new_msg_icon) .setContentIntent(pIntent) .addAction(R.drawable.answer_icon, "Answer", pIntent) .addAction(R.drawable.more_icon, "More", pIntent).build();
// Set notification flag(s)notification.flags = Notification.FLAG_AUTO_CANCEL;
// Retrieve notification service and send notificationNotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);notificationManager.notify(0, notification);
Notifications Android 4.1+ - Noteworthy ...
MTC2013
// Intent to call if notification is selectedIntent intent = new Intent(this, MyActivity.class);PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
// Build up expandable notification with some dummy actionsNotification notification = new Notification.Builder(this) .setContentTitle("New Message from " + "@mobileLarson") .setContentText("Hi, what‘s up?") .setSmallIcon(R.drawable.new_msg_icon) .setContentIntent(pIntent) .addAction(R.drawable.answer_icon, "Answer", pIntent) .addAction(R.drawable.more_icon, "More", pIntent) .setStyle(new Notification.BigTextStyle().bigText("...")) .build();
... oder BigPictureStyle bzw. InboxStyle
oder BigPictureStyle bzw. InboxStyle
Notifications Android 4.1+ - Noteworthy ...
MTC2013
Notifications Android 4.1+ - Noteworthy ...
MTC2013
Eigentlich ganz einfach, aber ...
‣... was ist mit Notification Stacking? ‣... was ist mit Abwärtskompabilität?‣... was ist mit Navigation?
Notifications Android 4.1+ - Noteworthy ...
MTC2013
Notifications & Stacking
‣eindeutige noteID als Hinweis für den Notification Manager verwenden, dass er die selbe Notification-Darstellung nutzen soll
‣notificationManager.notify(noteID, notification)
Notifications Android 4.1+ - Noteworthy ...
MTC2013
Notifications & Abwärtskompabilität
‣NotificationCompat‣NotificationCompat.Builder
‣Action Buttons erscheinen erst ab V4.1+
Notifications Android 4.1+ - Noteworthy ...
MTC2013
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.notification_icon) .setContentTitle("Event Tracker") .setContentText("Events Received");
// Sets and configure the specific styleNotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();inboxStyle.setBigContentTitle("Event tracker details:") .addLine("first line") .addLine("second line") .addLine("third line") .setSummeryText("+3 more");
// Moves the big view style object into the notification object.mBuilder.setStyle(inBoxStyle);Notification notification = mBuilder.build(); ...
Notifications Android 4.1+ - Noteworthy ...
MTC2013
Notifications & Navigation
‣dazu gleich mehr ...
Photo credit: Kalexanderson / Foter.com / CC BY-NC-SA
Navigation
Navigation Android 4.1+ - Noteworthy ...
MTC2013
Was bisher geschah ...
‣Android 4.0 führt Unterscheidung zwischen „Back vs. Up“ Navigation ein
Navigation Android 4.1+ - Noteworthy ...
MTC2013
Back vs. Up Navigation
Navigation Android 4.1+ - Noteworthy ...
MTC2013
Navigation Android 4.1+ - Noteworthy ...
MTC2013
Navigation Android 4.1+ - Noteworthy ...
MTC2013
Navigation Android 4.1+ - Noteworthy ...
MTC2013
Navigation Android 4.1+ - Noteworthy ...
MTC2013
Navigation Android 4.1+ - Noteworthy ...
MTC2013
Deep Dive
Navigation Android 4.1+ - Noteworthy ...
MTC2013
@Override
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); ...
}
Step 1: Enable „Up Navigation“ Step 1: Enable „Up Navigation“
Navigation Android 4.1+ - Noteworthy ...
MTC2013
@Overridepublic boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) {
// app icon in action bar clicked: go home case android.R.id.home: Intent i = new Intent(this, MainActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); return true;
default: return super.onOptionsItemSelected(item); } }
Step 2: Realize „Up Navigation“ Step 2: Realize „Up Navigation“
Navigation Android 4.1+ - Noteworthy ...
MTC2013
Eigentlich ganz einfach, aber ...
‣... ziemlich viel Aufwand, oder? ‣... was ist mit „deep dive“ Intents?
Navigation Android 4.1+ - Noteworthy ...
MTC2013
Navigation & „Deep Dive“ Intents
‣Einsprung von außen „mitten“ in die App‣Navigation Stack wird künstlich aufgebaut a.k.a. Synthetic Back Stack
‣Was ist mit dem fehlenden Kontext? „Music Details“ navigiert zurück zur „Music Liste“, aber zu welcher?
Navigation Android 4.1+ - Noteworthy ...
MTC2013
Deep Dive
Navigation Android 4.1+ - Noteworthy ...
MTC2013
<activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> ... </intent-filter></activity>
<activity android:name=".ResultActivity" android:parentActivityName=".MainActivity"> <meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".MainActivity"/></activity>
Step 1: Enable „Up Navigation“ Step 1: Enable „Up Navigation“
Navigation Android 4.1+ - Noteworthy ...
MTC2013
@Overridepublic boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) {
// app icon in action bar clicked: go home case android.R.id.home: Intent i = new Intent(this, MainActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); return true;
default: return super.onOptionsItemSelected(item); } }
Step 2: Realize „Up Navigation“ Step 2: Realize „Up Navigation“
Navigation Android 4.1+ - Noteworthy ...
MTC2013
@Override
public void onPrepareNavigateUpTaskStack( TaskStackBuilder builder) {
// retrieve intent for manipulation int position = ...; Intent intent = builder.getIntentAt(position);
// manipulate intent intent.putExtra(INTENT_SPECIFIC_INFO, specificInfo); ...}
Step 3: Manipulate Intent Data Step 3: Manipulate Intent Data
Photo credit: Kalexanderson / Foter.com / CC BY-NC-SA
Fragments
Fragments Android 4.1+ - Noteworthy ...
MTC2013
Was bisher geschah ...
‣Android 4.0 führt Fragments als Konzept zur Modularisierung ein‣Wiederverwendbare Blöcke zur Gestaltung von „Multi-Pane“ Layouts
Fragments Android 4.1+ - Noteworthy ...
MTC2013
Fragments Android 4.1+ - Noteworthy ...
MTC2013
Fragments 1x1
‣UI Fragments als Building Blocks‣UI Activity Layout als Block Assembler‣UI Activity Class als Block Assembler Logic
‣UI Resources als Switch
Fragments Android 4.1+ - Noteworthy ...
MTC2013
Fragments Android 4.1+ - Noteworthy ...
MTC2013
Fragments im Detail
‣Activity Modul a.k.a. Sub Activity‣inkl. eigener UI‣inkl. eigenem Lifecycle
‣benötigt immer eine umliegende Activity‣Lifecycle passt sich dem Activity-Lifecycle an
Fragments Android 4.1+ - Noteworthy ...
MTC2013
Fragments Android 4.1+ - Noteworthy ...
MTC2013
in Aktion ‣ Starte MainActivity‣ Screensize Smartphone‣ Orientierung Portrait
‣ Layout aus res/layout‣ Fragment A
‣ Bei Selektion schicke Intent „Details“
‣ Zeige DetailsActivity in Fragment B
1)Standardlayout
1)
Fragments Android 4.1+ - Noteworthy ...
MTC2013
in Aktion
‣ Starte DetailActivity‣ Screensize Smartphone‣ Orientierung Portrait
‣ Layout aus res/layout‣ Fragment B
1)Standardlayout
1)
Fragments Android 4.1+ - Noteworthy ...
MTC2013
in Aktion‣ Starte MainActivity‣ Screensize Tablet‣ Orientierung Landscape
‣ Layout aus /res/layout-sw600dp
‣ Fragment A und B
‣ Bei Selektion aktualisiere B
1)Layout für: smalest witdh 600dp = 10“ Tablet
1)
Fragments Android 4.1+ - Noteworthy ...
MTC2013
Fragment Main Player
‣Fragment XML‣Fragment Class
‣FragmentManager‣FragmentTransaction
Fragments Android 4.1+ - Noteworthy ...
MTC2013
Fragments
‣Soweit alles klar, aber wie kann ich ein Fragment innerhalb eines anderen Fragments platzieren?
Fragments Android 4.1+ - Noteworthy ...
MTC2013
Nested Fragments
‣Verschachtelte Fragments‣dynamisch via FragmentManager hinzufügen, aktualisieren, löschen
‣können nicht statisch via XML Layout angegeben werden!
Fragments Android 4.1+ - Noteworthy ...
MTC2013
Nested Fragments
Fragments Android 4.1+ - Noteworthy ...
MTC2013
...@Overridepublic void onClick(View v) { Fragment nestedFragment = new NestedFrag(); FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); transaction.add(getId(), nestedFragment, "parent").commit();}...
Notifications Android 4.1+ - Noteworthy ...
MTC2013
Photo credit: Kalexanderson / Foter.com / CC BY-NC-SA
Connectivity
MTC2013
Was bisher geschah ...
‣Einführung vereinfachter Connectivity zwischen zwei Android Devices in Android 4.0
‣via NFC a.k.a. Android Beam ‣via WiFi a.k.a. WiFi Direct
Connectivity Android 4.1+ - Noteworthy ...
MTC2013
Android Beam
‣Datenaustausch zwischen zwei „NFC-Devices“‣Beam API liefert UI und NFC Support‣Game Score, Chat Data, Contacts, Apps ...‣Kleine Datenmengen via NFC‣Große Datenmengen via Bluetooth‣Apps via Google Play
Connectivity Android 4.1+ - Noteworthy ...
MTC2013
Android Beam Transfer für „große“ Daten
‣Transfer via Bluetooth oder Alternativen‣Transparente Verbindung im Hintergrund
‣Aktivieren via ‣setBeamPushUris oder‣NfcAdapter.CreateBeamUrisCallback
Connectivity Android 4.1+ - Noteworthy ...
„static“ content „static“ content
„dynamic“ content „dynamic“ content
MTC2013
WiFi Direct
‣P2P-Verbindung zu „Nearby-Devices“ via WiFi‣Kein Internet oder Tethering notwendig
‣WifiP2PManager als Main Player‣Peer Discovery, Request & Connecting
Connectivity Android 4.1+ - Noteworthy ...
MTC2013
WiFi Direct Service Discovery
‣Finden & Filtern von „Nearby Device“ Services ‣Basiert auf Android Network Service Discovery
‣Main Player WifiP2pManager - Service ...‣anbieten: addLocalService‣nutzen: addServiceRequest & discoverService
Connectivity Android 4.1+ - Noteworthy ...
Photo credit: Kalexanderson / Foter.com / CC BY-NC-SA
ConnectivitySome Stuff
Some Stuff Android 4.1+ - Noteworthy ...
MTC2013
‣Developer Options‣Security Enhancements ‣Performance Improvements
Some Stuff Android 4.1+ - Noteworthy ...
MTC2013
Developer Options
‣SEVEN is the magic number‣Take Bug Report ‣Power Menu Bug Reports‣Verify App over USB‣Simulate secondary Display‣...
„7x die Builde-No anklicken,
um Dev Options zu aktivieren.“
Some Stuff Android 4.1+ - Noteworthy ...
MTC2013
Developer Options
‣SEVEN is the magic number‣Take Bug Report ‣Power Menu Bug Reports‣Verify App over USB‣Simulate secondary Display‣...
Screenshot, Device State Info Dump, eMail-Report
Some Stuff Android 4.1+ - Noteworthy ...
MTC2013
Developer Options
‣SEVEN is the magic number‣Take Bug Report ‣Power Menu Bug Reports‣Verify App over USB‣Simulate secondary Display‣...
Power Menu Option für Bug
Reports
Some Stuff Android 4.1+ - Noteworthy ...
MTC2013
Developer Options
‣SEVEN is the magic number‣Take Bug Report ‣Power Menu Bug Reports‣Verify App over USB‣Simulate secondary Display‣...
App Check für USB
ausschalten
Some Stuff Android 4.1+ - Noteworthy ...
MTC2013
Developer Options
‣SEVEN is the magic number‣Take Bug Report ‣Power Menu Bug Reports‣Verify App over USB‣Simulate secondary Display‣...
Power Menu Option für Bug
Reports
Some Stuff Android 4.1+ - Noteworthy ...
MTC2013
Security Enhancements
‣Application Verification‣Premium SMS Control‣Always-on VPN‣Improved Permission Display‣Content Provider Defaults‣...
Application Scan vor der Installation
Some Stuff Android 4.1+ - Noteworthy ...
MTC2013
Security Enhancements
‣Application Verification‣Premium SMS Control‣Always-on VPN‣Improved Permission Display‣Content Provider Defaults‣...
Notification falls
Premium SMS
Some Stuff Android 4.1+ - Noteworthy ...
MTC2013
Security Enhancements
‣Application Verification‣Premium SMS Control‣Always-on VPN‣Improved Permission Display‣Content Provider Defaults‣...
Net Traffic nur bei VPN erlaubt
Some Stuff Android 4.1+ - Noteworthy ...
MTC2013
Security Enhancements
‣Application Verification‣Premium SMS Control‣Always-on VPN‣Improved Permission Display‣Content Provider Defaults‣...
Gruppierung und
bessere Info
Some Stuff Android 4.1+ - Noteworthy ...
MTC2013
Security Enhancements
‣Application Verification‣Premium SMS Control‣Always-on VPN‣Improved Permission Display‣Content Provider Defaults‣...
NOT exported
Some Stuff Android 4.1+ - Noteworthy ...
MTC2013
Performance Improvements
‣vsync Timing‣Tripple Buffering‣Reduced Touch Latency‣CPI Input Boost ‣Optimized Drawing‣...
Deutlich verbesserte Performance
und Ergonomie
Ph
oto
cre
dit:
Ka
lexa
nd
ers
on
/ F
ote
r.co
m /
CC
BY
-NC
-SA
Android 4.1+ @mobileLarson @_openKnowledge
Lars Röwekamp | CIO New Technologies