use of android.support.v4.app.RemoteInput in project cw-omnibus by commonsguy.
the class MainActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent i = new Intent(this, VoiceReceiver.class);
PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
RemoteInput remoteInput = new RemoteInput.Builder(VoiceReceiver.EXTRA_SPEECH).setLabel(getString(R.string.talk)).setChoices(getResources().getStringArray(R.array.replies)).build();
NotificationCompat.Action wearAction = new NotificationCompat.Action.Builder(android.R.drawable.ic_btn_speak_now, getString(R.string.talk), pi).addRemoteInput(remoteInput).build();
NotificationCompat.WearableExtender wearExtender = new NotificationCompat.WearableExtender().addAction(wearAction);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setSmallIcon(android.R.drawable.stat_sys_download_done).setContentTitle(getString(R.string.title)).setContentText(getString(R.string.talk)).extend(wearExtender);
NotificationManagerCompat.from(this).notify(NOTIFY_ID, builder.build());
finish();
}
use of android.support.v4.app.RemoteInput in project cw-omnibus by commonsguy.
the class MainActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent i = new Intent(this, RemoteInputReceiver.class);
PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
RemoteInput remoteInput = new RemoteInput.Builder(RemoteInputReceiver.EXTRA_INPUT).setLabel(getString(R.string.talk)).build();
NotificationCompat.Action remoteAction = new NotificationCompat.Action.Builder(android.R.drawable.ic_btn_speak_now, getString(R.string.talk), pi).addRemoteInput(remoteInput).build();
NotificationCompat.Builder builder = RemoteInputReceiver.buildNotificationBase(this).addAction(remoteAction);
NotificationManagerCompat.from(this).notify(RemoteInputReceiver.NOTIFY_ID, builder.build());
finish();
}
use of android.support.v4.app.RemoteInput in project Signal-Android by WhisperSystems.
the class SingleRecipientNotificationBuilder method addAndroidAutoAction.
public void addAndroidAutoAction(@NonNull PendingIntent androidAutoReplyIntent, @NonNull PendingIntent androidAutoHeardIntent, long timestamp) {
if (mContentTitle == null || mContentText == null)
return;
RemoteInput remoteInput = new RemoteInput.Builder(AndroidAutoReplyReceiver.VOICE_REPLY_KEY).setLabel(context.getString(R.string.MessageNotifier_reply)).build();
NotificationCompat.CarExtender.UnreadConversation.Builder unreadConversationBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder(mContentTitle.toString()).addMessage(mContentText.toString()).setLatestTimestamp(timestamp).setReadPendingIntent(androidAutoHeardIntent).setReplyAction(androidAutoReplyIntent, remoteInput);
extend(new NotificationCompat.CarExtender().setUnreadConversation(unreadConversationBuilder.build()));
}
use of android.support.v4.app.RemoteInput in project Talon-for-Twitter by klinker24.
the class NotificationUtils method sendTestNotification.
public static void sendTestNotification(Context context) {
if (!TEST_NOTIFICATION) {
return;
}
AppSettings settings = AppSettings.getInstance(context);
SharedPreferences sharedPrefs = context.getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
Intent markRead = new Intent(context, MarkReadService.class);
PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0);
String shortText = "Test Talon";
String longText = "Here is a test for Talon's notifications";
Intent resultIntent = new Intent(context, RedirectToMentions.class);
PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);
NotificationCompat.Builder mBuilder;
Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class);
mBuilder = new NotificationCompat.Builder(context).setContentTitle(shortText).setContentText(longText).setSmallIcon(R.drawable.ic_stat_icon).setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher)).setContentIntent(resultPendingIntent).setAutoCancel(true).setTicker(shortText).setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)).setPriority(NotificationCompat.PRIORITY_HIGH);
// Pebble notification
if (sharedPrefs.getBoolean("pebble_notification", false)) {
sendAlertToPebble(context, shortText, shortText);
}
// Light Flow notification
sendToLightFlow(context, shortText, shortText);
if (settings.vibrate) {
mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
}
if (settings.sound) {
try {
mBuilder.setSound(Uri.parse(settings.ringtone));
} catch (Exception e) {
e.printStackTrace();
mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
}
}
if (settings.led)
mBuilder.setLights(0xFFFFFF, 1000, 1000);
// Get an instance of the NotificationManager service
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
Intent reply = new Intent(context, NotificationCompose.class);
MentionsDataSource data = MentionsDataSource.getInstance(context);
PendingIntent replyPending = PendingIntent.getActivity(context, 0, reply, 0);
RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel("@" + "lukeklinker" + " ").build();
// Create the notification action
NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(R.drawable.ic_action_reply_dark, context.getResources().getString(R.string.noti_reply), replyPending).addRemoteInput(remoteInput).build();
NotificationCompat.Action.Builder action = new NotificationCompat.Action.Builder(R.drawable.ic_action_read_dark, context.getResources().getString(R.string.mark_read), readPending);
mBuilder.addAction(replyAction);
mBuilder.addAction(action.build());
// Build the notification and issues it with notification manager.
notificationManager.notify(1, mBuilder.build());
// if we want to wake the screen on a new message
if (settings.wakeScreen) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
wakeLock.acquire(5000);
}
}
use of android.support.v4.app.RemoteInput in project phonegap-plugin-push by phonegap.
the class GCMIntentService method createActions.
private void createActions(Bundle extras, NotificationCompat.Builder mBuilder, Resources resources, String packageName, int notId) {
Log.d(LOG_TAG, "create actions: with in-line");
String actions = extras.getString(ACTIONS);
if (actions != null) {
try {
JSONArray actionsArray = new JSONArray(actions);
ArrayList<NotificationCompat.Action> wActions = new ArrayList<NotificationCompat.Action>();
for (int i = 0; i < actionsArray.length(); i++) {
int min = 1;
int max = 2000000000;
Random random = new Random();
int uniquePendingIntentRequestCode = random.nextInt((max - min) + 1) + min;
Log.d(LOG_TAG, "adding action");
JSONObject action = actionsArray.getJSONObject(i);
Log.d(LOG_TAG, "adding callback = " + action.getString(CALLBACK));
boolean foreground = action.optBoolean(FOREGROUND, true);
boolean inline = action.optBoolean("inline", false);
Intent intent = null;
PendingIntent pIntent = null;
if (inline) {
Log.d(LOG_TAG, "Version: " + android.os.Build.VERSION.SDK_INT + " = " + android.os.Build.VERSION_CODES.M);
if (android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.M) {
Log.d(LOG_TAG, "push activity");
intent = new Intent(this, PushHandlerActivity.class);
} else {
Log.d(LOG_TAG, "push receiver");
intent = new Intent(this, BackgroundActionButtonHandler.class);
}
updateIntent(intent, action.getString(CALLBACK), extras, foreground, notId);
if (android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.M) {
Log.d(LOG_TAG, "push activity for notId " + notId);
pIntent = PendingIntent.getActivity(this, uniquePendingIntentRequestCode, intent, PendingIntent.FLAG_ONE_SHOT);
} else {
Log.d(LOG_TAG, "push receiver for notId " + notId);
pIntent = PendingIntent.getBroadcast(this, uniquePendingIntentRequestCode, intent, PendingIntent.FLAG_ONE_SHOT);
}
} else if (foreground) {
intent = new Intent(this, PushHandlerActivity.class);
updateIntent(intent, action.getString(CALLBACK), extras, foreground, notId);
pIntent = PendingIntent.getActivity(this, uniquePendingIntentRequestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
} else {
intent = new Intent(this, BackgroundActionButtonHandler.class);
updateIntent(intent, action.getString(CALLBACK), extras, foreground, notId);
pIntent = PendingIntent.getBroadcast(this, uniquePendingIntentRequestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
NotificationCompat.Action.Builder actionBuilder = new NotificationCompat.Action.Builder(resources.getIdentifier(action.optString(ICON, ""), DRAWABLE, packageName), action.getString(TITLE), pIntent);
RemoteInput remoteInput = null;
if (inline) {
Log.d(LOG_TAG, "create remote input");
String replyLabel = "Enter your reply here";
remoteInput = new RemoteInput.Builder(INLINE_REPLY).setLabel(replyLabel).build();
actionBuilder.addRemoteInput(remoteInput);
}
NotificationCompat.Action wAction = actionBuilder.build();
wActions.add(actionBuilder.build());
if (inline) {
mBuilder.addAction(wAction);
} else {
mBuilder.addAction(resources.getIdentifier(action.optString(ICON, ""), DRAWABLE, packageName), action.getString(TITLE), pIntent);
}
wAction = null;
pIntent = null;
}
mBuilder.extend(new WearableExtender().addActions(wActions));
wActions.clear();
} catch (JSONException e) {
// nope
}
}
}
Aggregations