Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
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/androidAppShortcuts/ • 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/and roid/content/pm/ShortcutManager.html • https://developer.android.com/guide/topics/u i/shortcuts.html • https://github.com/googlesamples/androidAppShortcuts/ 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 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/u i/notifiers/notifications.html • https://developer.android.com/about/version s/nougat/android7.0.html#notification_enhancements • https://github.com/googlesamples/androidMessagingService • https://github.com/googlesamples/androidActiveNotifications/ Quick Setting Tiles • When you need to it fast basically – 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/googledevelopers/quick-settings-tilese3c22daf93a8#.q1z2hhur8 • https://plus.google.com/u/0/+AndroidDevelo pers/posts/8rGs9FaHMZw?sfc=true • https://developer.android.com/reference/and roid/service/quicksettings/TileService.html • https://github.com/googlecodelabs/androidn-quick-settings Q&A