Cosc 4735 Nougat API 24+ additions.

Slides:



Advertisements
Similar presentations
Application Fundamentals Android Development. Announcements Posting in D2L Tutorials.
Advertisements

Android 02: Activities David Meredith
All About Android Introduction to Android 1. Creating a New App “These aren’t the droids we’re looking for.” Obi-wan Kenobi 1. Bring up Eclipse. 2. Click.
The Android Activity Lifecycle. Slide 2 Introduction Working with the Android logging system Rotation and multiple layouts Understanding the Android activity.
Application Fundamentals. See: developer.android.com/guide/developing/building/index.html.
Android 101 Application Fundamentals January 29, 2010.
Android Life Cycle CS328 Dick Steflik. Life Cycle The steps that an application goes through from starting to finishing Slightly different than normal.
Cosc 5/4730 Android SMS. A note first Depending on the API level, an import changes because of a deprecated API 3 uses – import android.telephony.gsm.SmsManager;
Android Development (Basics)
Emerging Platform#4: Android Bina Ramamurthy.  Android is an Operating system.  Android is an emerging platform for mobile devices.  Initially developed.
CS378 - Mobile Computing What's Next?. Fragments Added in Android 3.0, a release aimed at tablets A fragment is a portion of the UI in an Activity multiple.
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
CS5103 Software Engineering Lecture 08 Android Development II.
© Keren Kalif Intro to Android Development Written by Keren Kalif, Edited by Liron Blecher Contains slides from Google I/O presentation.
Favorite Twitter® Searches App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
Cosc 5/4730 Introduction: Threads, Android Activities, and MVC.
Homescreen Widgets Demystified Pearl AndroidTO // Oct 26, 2010.
Cosc 5/4730 Broadcast Receiver. Broadcast receiver A broadcast receiver (short receiver) – is an Android component which allows you to register for system.
DUE Hello World on the Android Platform.
Activities and Intents. Activities Activity is a window that contains the user interface of your application,typically an application has one or more.
Cosc 5/4730 Android App Widgets. App Widgets App Widgets are miniature application views that can be embedded in other applications (such as the Home.
Cosc 5/4730 Android Communications Intents, callbacks, and setters.
Cosc 5/4735 Voice Actions Voice Interactions (API 23+)
Intents and Broadcast Receivers Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution.
Services. What is a Service? A Service is not a separate process. A Service is not a thread. A Service itself is actually very simple, providing two main.
The Ingredients of Android Applications. A simple application in a process In a classical programming environment, the OS would load the program code.
Lab7 – Appendix.
Google VR (gvr) CardBoard and DayDream With OpenGL
Android Application -Architecture.
Android Programming - Features
Mobile Applications (Android Programming)
Intents and Broadcast Receivers
Lecture 2: Android Concepts
Mobile Application Development BSCS-7 Lecture # 2
Android Application Development 1 6 May 2018
Project Objectives Publish to a remote server
Activity and Fragment.
Broadcast receivers.
CS371m - Mobile Computing Services and Broadcast Receivers
Basic Activities and Intents
Activities, Fragments, and Events
Mobile Application Development BSCS-7 Lecture # 6
MAD.
Notifications and Services
Activities and Intents
Mobile Application Development Chapter 4 [Android Navigation and Interface Design] IT448-Fall 2017 IT448- Fall2017.
The Android Activity Lifecycle
Broadcast Receivers A Android Component where you can register for system or application events, receive and react to broadcast intent. Each broadcast.
ANDROID UI – FRAGMENTS UNIT II.
Firebase Cloud messaging A primer
Android Programming Lecture 9
Developing Android Services
CS5103 Software Engineering
Android Notifications (Part 2) Plus Alarms and BroadcastReceivers
Application Fundamentals
CIS 470 Mobile App Development
Android Topics Android Activity Lifecycle and Experiment Toast
Activities and Intents
HNDIT2417 Mobile Application Development
CIS 470 Mobile App Development
Activities and Intents
Android Developer Fundamentals V2 Lesson 5
Emerging Platform#3 Android & Programming an App
Activities and Intents
Application Fundamentals
Lecture 2: Android Concepts
Activities, Fragments, and Intents
Mobile Programming Broadcast Receivers.
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

Cosc 4735 Nougat API 24+ additions

App Shortcuts If your app targets Android 7.1 (API level 25) or higher you can define shortcuts to specific actions in your app. These shortcuts can be displayed in a supported launcher. Shortcuts let your users quickly start common or recommended tasks within your app. These can be both static and dynamic shortcuts. These shortcuts can also be “pinned” to the desktop as separate icons.

Static shortcuts Static shortcuts don’t change, so all the work is done in the xml files for the AndroidManifest.xml file. Find the activity with the MAIN intent and category LAUNCHER and add the two lines in blue: <manifest … > <application ... > <activity android:name="Main" … > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts" /> </activity> </application> </manifest>

Static shortcuts (2) In the shortcuts xml file, we then create the number of enters needed. We need a id, icon, label, and intent (either to launcher an activity or custom Intent) <shortcuts xmlns:android="http://schemas.android.com/apk/res/android">   <shortcut     android:shortcutId="compose"     android:icon="@drawable/compose_icon"     android:shortcutShortLabel="@string/compose_shortcut_short_label1"     android:shortcutLongLabel="@string/compose_shortcut_long_label1"     <intent       android:action="android.intent.action.VIEW"       android:targetPackage="com.example.myapplication"       android:targetClass="com.example.myapplication.ComposeActivity" />   </shortcut>   <!-- Specify more shortcuts here. --> </shortcuts>

Dynamic Shortcuts We need to create the shortcut first, then add it. Shortcutinfo is done via a builder. Shortcutinfo item = new ShortcutInfo.Builder(this,"id1") .setShortLabel("Web Site") .setLongLabel("Cosc 4735 Web site") .setIcon(Icon.createWithResource(this, R.drawable.bookmark)) .setIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.cs.uwyo.edu/~seker/courses/4735/"))) .build(); Then add it via ShortcutManager.class is android, not a class I created. mShortcutManager = getSystemService(ShortcutManager.class); mShortcutManager.addDynamicShortcuts(Arrays.asList(item)); Or if we used a List<ShortcutInfo> myList mShortcutManager.setDynamicShortcuts(myList);

ShortcutManager We can query for size (ie number of dynamic shortcuts) Get a List of all the dynamic shortcuts getDynamicShortcuts() Or just ones that were pinned via getPinnedShortcuts() We can also remove and disable/enable shortcuts as well. We will need to know the ID of the shortcut.

Demo Code AppShortCutsDemo is a simple demo of it Shows static and dynamic short cuts. Google’s appShortcuts is more complex where you can add more shortcuts in the app. https://github.com/googlesamples/android-AppShortcuts/ At the time of this was written, there were a couple of errors in the code for the static shortcuts. And while it compiles, doesn’t actually work.

References (shortcuts) https://developer.android.com/reference/android/content/pm/ShortcutManager.html https://developer.android.com/guide/topics/ui/shortcuts.html https://github.com/googlesamples/android-AppShortcuts/

Multi-window support On phones and tablets, split screen Where you can drag a divider between the two apps. On android TV it’s PiP.

Manifest file. Each activity now has android:resizeableActivity="false" or "true" default is true You can set a minwidth and minheight in a <layout> tag between <activity> </activity>

Mode You have new methods New override as well isInMultiWindowMode() isInPictureInPictureMode() New override as well @Override public void onMultiWindowModeChanged(boolean isInMultiWindowMode) { super.onMultiWindowModeChanged(isInMultiWindowMode); //make changes as needed here. } This appears to be called after onCreate and before onStart.

Lastly a note. It appears when the app goes into multi window mode (or the divider is used to change the size) The app is killed (through onDestroy) and restarted started.

Demo code MultiWindowDemo Runs the set of onCreate to onDestroy so you can see what's going on. Also use is methods to see what mode it's in.

Notifications additions Notifications have added compatibility with android auto (which still works on wear). Allows for remoteinput Has the notification been read Has the notification been deleted How many notifications are there.

Android Auto Add this to your androidmanifest.xml inside the between <application> tags, before the <activity> <meta-data android:name= "com.google.android.gms.car.application" android:resource="@xml/automotive_app_desc"/> Where the xml file has the following lines: <?xml version="1.0" encoding="utf-8"?> <automotiveApp> <uses name="notification"/> </automotiveApp> Then Ensure that Message notifications are extended using NotificationCompat.Builder.extend(new CarExtender()...) This is just part of the notification build.

Notifying the app about notifications. For read and delete Basically the same idea Create an pentingintent Put the message id in the intent. Have a broadcast receiver The pentingintent will be sent to the receiver and you know which notification it was, based on the id number.

Read example The Pendingintent PendingIntent.getBroadcast(getActivity().getApplicationContext(), NotificationNum, new Intent() .addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES) .setAction("edu.cs4730.notification3.ACTION_MESSAGE_READ") .putExtra("conversation_id", NotificationNum), PendingIntent.FLAG_UPDATE_CURRENT); Then as the notificaiton is being build .setContentIntent(readPendingIntent) Delete uses .setDeleteIntent(DeletePendingIntent):

Read example (2) Either declare a broadcast receiver static or dynamic private BroadcastReceiver mReadReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.d(TAG, "onReceiveRead"); int conversationId = intent.getIntExtra(CONVERSATION_ID, -1); if (conversationId != -1) { //now you know, do what? } } }; In onResume registerReceiver(mReadReceiver, new IntentFilter("edu.cs4730.notification3.ACTION_MESSAGE_READ"));

remoteInput basically the same idea, but far more complex Build a RemoteInput for receiving voice input in a Car Notification or text input on devices that support text input (like devices on Android N and above). Building a Pending Intent for the reply action to trigger Build an Android N compatible Remote Input enabled action. Create the UnreadConversation builderand populate it with the participant name, read and reply intents. Then in the notification builder, add it with the extend (and carextender() for compatilibity). This is best all seen in the example code, instead of here.

remoteInput (2) Again, we need broadcast receiver for the reply and the intentfilter (like read) In the receiver we can get the reply message from the remoteinput intent and the message id Finally, we need to update the notification that we have received it, so we build a simple notification, using the same id number.

Example notificationDemo3 Show how to setup a read, delete, and reply for notifcations. You may need to review notifications to under some of what is going on.

References (notifications) https://developer.android.com/guide/topics/ui/notifiers/notifications.html https://developer.android.com/about/versions/nougat/android-7.0.html#notification_enhancements https://github.com/googlesamples/android-MessagingService https://github.com/googlesamples/android-ActiveNotifications/

Quick Setting Tiles When you need to it fast basically Three types Even when the screen is locked! Three types Tap Dialog Launch an activity.

TileService Extend a tileservice Then you can override onTileAdded() called when tile is added. onStartListening() when tile is visible onStopListening () when tile is no longer visible. onTileRemoved() when tile is removed. onClick() when the tile is tapped.

TileService (2) onClick, etc We can now update the tile Tile tile = getQsTile(); tile.setIcon(Icon.createWithResource(this, R.drawable.cooltile_on)); tile.setLabel("Cool tile"); tile.setContentDescription("cool tile is On"); tile.setState(Tile.STATE_ACTIVE); // colored white //Tile.STATE_INACTIVE will color it gray. tile.updateTile(); //required to update the tile!

TileService (3) Each time on the methods is called, it will bind to the service. You can NOT guarantee the service was running before or values were keep. In the test code, it uses a preference to store a value.

Dialog and Activity To show a dialog, create a dialog and then use the builtin method, showDialog( …dialog…) To start an activity Create the intent for the activity and use startActivityAndCollapse(intent).

Androidmanifest.xml Declare the Quick Setting service <service android:name=".QuickSettingsTapService" android:icon="@drawable/cooltile_off" android:label="Cool Tile Tap" android:permission= "android.permission.BIND_QUICK_SETTINGS_TILE"> <intent-filter> <action android:name="android.service.quicksettings.action.QS_TILE" /> </intent-filter> </service>

icon The icon should be a 24x24 vector graphic solid color Since it only works on API 24+ you can use the vector graphic builder built into studio for the graphics. 3rd party can't use SVG for animated graphics. Maybe in API 26.

References (Quick Settings) https://medium.com/google-developers/quick-settings-tiles-e3c22daf93a8#.q1z2hhur8 https://plus.google.com/u/0/+AndroidDevelopers/posts/8rGs9FaHMZw?sfc=true https://developer.android.com/reference/android/service/quicksettings/TileService.html https://github.com/googlecodelabs/android-n-quick-settings

Q A &