Merge "Shortcut demo: Add a notification with remote input" into nyc-mr1-dev

This commit is contained in:
Makoto Onuki
2016-06-16 17:06:09 +00:00
committed by Android (Google) Code Review
5 changed files with 65 additions and 0 deletions

View File

@@ -39,5 +39,6 @@
<action android:name="com.example.android.pm.shortcutdemo.ADD" /> <action android:name="com.example.android.pm.shortcutdemo.ADD" />
</intent-filter> </intent-filter>
</service> </service>
<receiver android:name="ShortcutReceiver" />
</application> </application>
</manifest> </manifest>

View File

@@ -41,6 +41,12 @@
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:onClick="onDeleteAllPressed"/> android:onClick="onDeleteAllPressed"/>
<Button
android:id="@+id/show_notification"
android:text="@string/show_notification"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="onShowNotificationPressed"/>
<ListView <ListView
android:id="@android:id/list" android:id="@android:id/list"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@@ -44,4 +44,7 @@
<add-resource type="string" name="shortcut_disabled_message2"/> <add-resource type="string" name="shortcut_disabled_message2"/>
<string name="shortcut_disabled_message2">Disabled</string> <string name="shortcut_disabled_message2">Disabled</string>
<add-resource type="string" name="show_notification"/>
<string name="show_notification">Show notification</string>
</resources> </resources>

View File

@@ -16,6 +16,12 @@
package com.example.android.pm.shortcutdemo; package com.example.android.pm.shortcutdemo;
import android.app.Activity; import android.app.Activity;
import android.app.Notification;
import android.app.Notification.Action;
import android.app.Notification.Builder;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.RemoteInput;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@@ -262,6 +268,23 @@ public class ShortcutPublisher extends Activity {
refreshList(); refreshList();
} }
public void onShowNotificationPressed(View v) {
final PendingIntent receiverIntent =
PendingIntent.getBroadcast(this, 0,
new Intent().setComponent(new ComponentName(this, ShortcutReceiver.class)),
PendingIntent.FLAG_UPDATE_CURRENT);
final RemoteInput ri = new RemoteInput.Builder("result").setLabel("Remote input").build();
final Notification.Builder nb = new Builder(this)
.setContentText("Test")
.setContentTitle(getPackageName())
.setSmallIcon(R.drawable.icon_large_2)
.addAction(new Action.Builder(0, "Remote input", receiverIntent)
.addRemoteInput(ri)
.build());
getSystemService(NotificationManager.class).notify(0, nb.build());
}
class MyAdapter extends ShortcutAdapter { class MyAdapter extends ShortcutAdapter {
public MyAdapter(Context context) { public MyAdapter(Context context) {
super(context); super(context);

View File

@@ -0,0 +1,32 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.pm.shortcutdemo;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class ShortcutReceiver extends BroadcastReceiver {
private static final String TAG = "ShortcutReceiver";
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "Received: " + intent);
context.getSystemService(NotificationManager.class).cancelAll();
}
}