Merge \"Shortcut demo: Add a notification with remote input\" into nyc-mr1-dev
am: bb325c7686
Change-Id: I3dfdd0fee1d20a6f7498b94c7920a27a7bca07f4
This commit is contained in:
@@ -39,5 +39,6 @@
|
||||
<action android:name="com.example.android.pm.shortcutdemo.ADD" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
<receiver android:name="ShortcutReceiver" />
|
||||
</application>
|
||||
</manifest>
|
||||
|
||||
@@ -41,6 +41,12 @@
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
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
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -44,4 +44,7 @@
|
||||
|
||||
<add-resource type="string" name="shortcut_disabled_message2"/>
|
||||
<string name="shortcut_disabled_message2">Disabled</string>
|
||||
|
||||
<add-resource type="string" name="show_notification"/>
|
||||
<string name="show_notification">Show notification</string>
|
||||
</resources>
|
||||
|
||||
@@ -16,6 +16,12 @@
|
||||
package com.example.android.pm.shortcutdemo;
|
||||
|
||||
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.Context;
|
||||
import android.content.Intent;
|
||||
@@ -262,6 +268,23 @@ public class ShortcutPublisher extends Activity {
|
||||
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 {
|
||||
public MyAdapter(Context context) {
|
||||
super(context);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user