Presentation is loading. Please wait.

Presentation is loading. Please wait.

Cosc 4735 Nougat API 24+ additions.

Similar presentations


Presentation on theme: "Cosc 4735 Nougat API 24+ additions."— Presentation transcript:

1 Cosc 4735 Nougat API 24+ additions

2 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.

3 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" /> </activity> </application> </manifest>

4 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="   <shortcut     android:shortcutId="compose"                 <intent       android:action="android.intent.action.VIEW"       android:targetPackage="com.example.myapplication"       android:targetClass="com.example.myapplication.ComposeActivity" />   </shortcut>   <!-- Specify more shortcuts here. --> </shortcuts>

5 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(" .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);

6 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.

7 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. 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.

8 References (shortcuts)

9 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.

10 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>

11 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.

12 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.

13 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.

14 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.

15 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" 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.

16 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.

17 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):

18 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"));

19 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.

20 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.

21 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.

22 References (notifications)

23 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.

24 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.

25 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!

26 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.

27 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).

28 Androidmanifest.xml Declare the Quick Setting service <service
android:name=".QuickSettingsTapService" 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>

29 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.

30 References (Quick Settings)

31 Q A &


Download ppt "Cosc 4735 Nougat API 24+ additions."

Similar presentations


Ads by Google