Java 类android.support.v4.app.RemoteInput 实例源码

项目:airgram    文件:WearReplyReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    ApplicationLoader.postInitApplication();
    Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
    if (remoteInput == null) {
        return;
    }
    CharSequence text = remoteInput.getCharSequence(NotificationsController.EXTRA_VOICE_REPLY);
    if (text == null || text.length() == 0) {
        return;
    }
    long dialog_id = intent.getLongExtra("dialog_id", 0);
    int max_id = intent.getIntExtra("max_id", 0);
    if (dialog_id == 0 || max_id == 0) {
        return;
    }
    SendMessagesHelper.getInstance().sendMessage(text.toString(), dialog_id, null, null, true, null, null, null);
    MessagesController.getInstance().markDialogAsRead(dialog_id, max_id, max_id, 0, true, false);
}
项目:Phoenix-for-VK    文件:SendService.java   
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    String action = intent != null ? intent.getAction() : null;

    if (ACTION_ADD_MESSAGE.equals(action)) {
        int accountId = intent.getExtras().getInt(Extra.ACCOUNT_ID);
        int peerId = intent.getExtras().getInt(Extra.PEER_ID);

        Bundle msg = RemoteInput.getResultsFromIntent(intent);
        if (msg != null) {
            CharSequence body = msg.getCharSequence(Extra.BODY);
            addMessage(accountId, peerId, body);
        }
    } else {
        send();
    }

    return START_NOT_STICKY;
}
项目:airgram    文件:AutoMessageReplyReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    ApplicationLoader.postInitApplication();
    Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
    if (remoteInput == null) {
        return;
    }
    CharSequence text = remoteInput.getCharSequence(NotificationsController.EXTRA_VOICE_REPLY);
    if (text == null || text.length() == 0) {
        return;
    }
    long dialog_id = intent.getLongExtra("dialog_id", 0);
    int max_id = intent.getIntExtra("max_id", 0);
    if (dialog_id == 0 || max_id == 0) {
        return;
    }
    SendMessagesHelper.getInstance().sendMessage(text.toString(), dialog_id, null, null, true, null, null, null);
    MessagesController.getInstance().markDialogAsRead(dialog_id, max_id, max_id, 0, true, false);
}
项目:PlusGram    文件:WearReplyReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    ApplicationLoader.postInitApplication();
    Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
    if (remoteInput == null) {
        return;
    }
    CharSequence text = remoteInput.getCharSequence(NotificationsController.EXTRA_VOICE_REPLY);
    if (text == null || text.length() == 0) {
        return;
    }
    long dialog_id = intent.getLongExtra("dialog_id", 0);
    int max_id = intent.getIntExtra("max_id", 0);
    if (dialog_id == 0 || max_id == 0) {
        return;
    }
    SendMessagesHelper.getInstance().sendMessage(text.toString(), dialog_id, null, null, true, null, null, null);
    MessagesController.getInstance().markDialogAsRead(dialog_id, max_id, max_id, 0, true, false);
}
项目:PlusGram    文件:AutoMessageReplyReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    ApplicationLoader.postInitApplication();
    Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
    if (remoteInput == null) {
        return;
    }
    CharSequence text = remoteInput.getCharSequence(NotificationsController.EXTRA_VOICE_REPLY);
    if (text == null || text.length() == 0) {
        return;
    }
    long dialog_id = intent.getLongExtra("dialog_id", 0);
    int max_id = intent.getIntExtra("max_id", 0);
    if (dialog_id == 0 || max_id == 0) {
        return;
    }
    SendMessagesHelper.getInstance().sendMessage(text.toString(), dialog_id, null, null, true, null, null, null);
    MessagesController.getInstance().markDialogAsRead(dialog_id, max_id, max_id, 0, true, false);
}
项目:Cable-Android    文件:SingleRecipientNotificationBuilder.java   
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()));
}
项目:rview    文件:NotificationsHelper.java   
@TargetApi(Build.VERSION_CODES.N)
private static void createInlineReply(
        Context ctx, NotificationCompat.Builder builder, NotificationEntity entity) {
    RemoteInput remoteInput = new RemoteInput.Builder(Constants.EXTRA_COMMENT)
            .setLabel(ctx.getString(R.string.change_details_review_hint))
            .setAllowFreeFormInput(true)
            .build();
    NotificationCompat.Action action =
            new NotificationCompat.Action.Builder(
                    R.drawable.ic_send,
                    ctx.getString(R.string.action_reply),
                    getReplyPendingIntent(ctx, entity))
            .addRemoteInput(remoteInput)
            .setAllowGeneratedReplies(false)
            .build();
    builder.addAction(action);
}
项目:rview    文件:NotificationReceiver.java   
private void replyToNotification(Context context, Intent intent) {
    Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
    final int changeId = intent.getIntExtra(Constants.EXTRA_LEGACY_CHANGE_ID, -1);
    final String accountId = intent.getStringExtra(Constants.EXTRA_ACCOUNT_HASH);
    final int groupId = intent.getIntExtra(Constants.EXTRA_NOTIFICATION_GROUP_ID, 0);
    if (remoteInput != null && groupId != 0 && changeId >= 0 && accountId != null) {
        final Account account = ModelHelper.getAccountFromHash(context, accountId);
        if (account == null) {
            return;
        }

        CharSequence message = remoteInput.getCharSequence(Constants.EXTRA_COMMENT);
        if (message == null) {
            return;
        }

        performSendReply(context, account, groupId, changeId, message.toString());
    } else {
        // What happens here? Dismiss the notification in case, but don't mark as read
        NotificationsHelper.dismissNotification(context, groupId);
        NotificationEntity.dismissGroupNotifications(context, groupId);
    }
}
项目:android-samples    文件:WearableReplayActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_wearable_replay);

    CharSequence replayString;

    //get the voice replays from the remote input.
    Bundle bundle = RemoteInput.getResultsFromIntent(getIntent());
    if (bundle != null) {
        replayString = bundle.getCharSequence(WearableNotification.REMOTE_INPUT_LABEL);
    } else {
        replayString = "No replay from the response.";
    }

    Toast.makeText(this, replayString, Toast.LENGTH_LONG).show();

    finish();
}
项目:honki_android2    文件:NotiBroadcastReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {

    if (intent != null) {
        Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
        if (remoteInput != null) {
            //入力データを取得
            String value = (String) remoteInput.getCharSequence(KEY_DIRECT_REPLY);
            Toast.makeText(context, value, Toast.LENGTH_SHORT).show();

            //通知に反映して更新
            ArrayList<String> history = new ArrayList<>();
            history.add("コメント:" + value);
            NotiUtils.createNoti(context, history);
        }
    }
}
项目:ButterySlack    文件:MainActivity.java   
@Override
public void onConnect(@Nullable String message) {
    if (message != null) {
        Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
    } else {
        Intent intent = new Intent(this, HomeActivity.class);

        if (getIntent().hasExtra(HomeActivity.EXTRA_CHANNEL_ID))
            intent.putExtra(HomeActivity.EXTRA_CHANNEL_ID, getIntent().getStringExtra(HomeActivity.EXTRA_CHANNEL_ID));

        if (getIntent().hasExtra(HomeActivity.EXTRA_INSTANT_ID))
            intent.putExtra(HomeActivity.EXTRA_INSTANT_ID, getIntent().getStringExtra(HomeActivity.EXTRA_INSTANT_ID));

        Bundle remoteInput = RemoteInput.getResultsFromIntent(getIntent());
        if (remoteInput != null) {
            intent.putExtra(BaseMessageFragment.EXTRA_REPLY, remoteInput.getCharSequence(BaseMessageFragment.EXTRA_REPLY, "").toString());
            Log.d("RemoteInput", remoteInput.getCharSequence(BaseMessageFragment.EXTRA_REPLY, "").toString());
        }

        startActivity(intent);
    }

    finish();
}
项目:qiscus-sdk-android    文件:QiscusPushNotificationClickReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    QiscusComment comment = intent.getParcelableExtra("data");
    Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
    if (remoteInput != null) {
        CharSequence message = remoteInput.getCharSequence(QiscusPushNotificationUtil.KEY_NOTIFICATION_REPLY);
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(
                Context.NOTIFICATION_SERVICE);
        if (notificationManager != null) {
            notificationManager.cancel(comment.getRoomId());
        }
        QiscusComment qiscusComment = QiscusComment.generateMessage((String) message, comment.getRoomId(), comment.getTopicId());
        Qiscus.getChatConfig().getReplyNotificationHandler().onSend(context, qiscusComment);
    } else {
        Qiscus.getChatConfig().getNotificationClickListener().onClick(context, comment);
    }
}
项目:mobile-messaging-sdk-android    文件:InteractiveNotificationHandler.java   
@NonNull
private NotificationCompat.Action createAndroidNotificationAction(NotificationAction notificationAction, PendingIntent pendingIntent) {
    NotificationCompat.Action.Builder builder = new NotificationCompat.Action.Builder(
            notificationAction.getIcon(),
            context.getString(notificationAction.getTitleResourceId()),
            pendingIntent);

    if (notificationAction.hasInput()) {
        RemoteInput.Builder inputBuilder = new RemoteInput.Builder(notificationAction.getId());
        if (notificationAction.getInputLabelResourceId() > 0) {
            inputBuilder.setLabel(context.getString(notificationAction.getInputLabelResourceId()));
        }
        builder.addRemoteInput(inputBuilder.build());
    }

    return builder.build();
}
项目:gadgetbridge_artikcloud    文件:DebugActivity.java   
@Override
public void onReceive(Context context, Intent intent) {
    switch (intent.getAction()) {
        case GBApplication.ACTION_QUIT: {
            finish();
            break;
        }
        case ACTION_REPLY: {
            Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
            CharSequence reply = remoteInput.getCharSequence(EXTRA_REPLY);
            LOG.info("got wearable reply: " + reply);
            GB.toast(context, "got wearable reply: " + reply, Toast.LENGTH_SHORT, GB.INFO);
            break;
        }
        case DeviceService.ACTION_HEARTRATE_MEASUREMENT: {
            int hrValue = intent.getIntExtra(DeviceService.EXTRA_HEART_RATE_VALUE, -1);
            GB.toast(DebugActivity.this, "Heart Rate measured: " + hrValue, Toast.LENGTH_LONG, GB.INFO);
            break;
        }
    }
}
项目:wearbooksource    文件:NotiVoiceActivity.java   
private void fireNotification() {

        RemoteInput remoteInput = new RemoteInput.Builder(MyRemoteInputBroadcastReceiver.VOICE_INPUT_KEY).
                setLabel( getResources().getString( R.string.app_name)).build() ;

        NotificationCompat.Action wearRemoteInputAction =  new NotificationCompat.Action
                .Builder ( R.drawable.ic_launcher, "Speak", remoteInputPendingIntent)
                .addRemoteInput(remoteInput).build() ;


        NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender();
        wearableExtender.addAction(  wearRemoteInputAction) ;

        Notification notification =
                new NotificationCompat.Builder(this)
                        .setContentTitle(getResources().getString(R.string.app_name))
                        .setContentText(getResources().getString(R.string.notification_text))
                        .setSmallIcon(R.drawable.ic_notification)
                        .extend(wearableExtender)
                        .setColor(getResources().getColor(R.color.colorPrimary))
                        .build();

        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
        notificationManager.notify(NOTIFICATION_ID, notification);

    }
项目:qksms    文件:RemoteMessagingReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
    Bundle bundle = intent.getExtras();
    if (remoteInput != null && bundle != null) {
        if (intent.getAction().equals(ACTION_REPLY)) {

            Message message = new Message(
                    remoteInput.getCharSequence(EXTRA_VOICE_REPLY).toString(),
                    new String[]{bundle.getString(EXTRA_ADDRESS)}
            );

            Transaction sendTransaction = new Transaction(context, SmsHelper.getSendSettings(context));
            sendTransaction.sendNewMessage(message, bundle.getLong(EXTRA_THREAD_ID));

            Intent i = new Intent(context, MarkReadService.class);
            i.putExtra(EXTRA_THREAD_ID, bundle.getLong(EXTRA_THREAD_ID));
            context.startService(i);
        }
    }
}
项目:qksms    文件:RemoteMessagingReceiver.java   
public static NotificationCompat.Action getReplyAction(Context context, String address, long threadId) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    Intent replyIntent = new Intent(ACTION_REPLY).setClass(context, RemoteMessagingReceiver.class);
    replyIntent.putExtra(EXTRA_ADDRESS, address);
    replyIntent.putExtra(EXTRA_THREAD_ID, threadId);

    Set<String> defaultResponses = new HashSet<>(Arrays.asList(context.getResources().getStringArray(R.array.qk_responses)));
    Set<String> responseSet = prefs.getStringSet(SettingsFragment.QK_RESPONSES, defaultResponses);
    ArrayList<String> responses = new ArrayList<>();
    responses.addAll(responseSet);
    Collections.sort(responses);

    PendingIntent replyPI = PendingIntent.getBroadcast(context, 0, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY)
            .setLabel(context.getString(R.string.reply))
            .setChoices(responses.toArray(new String[responses.size()]))
            .build();

    return new NotificationCompat.Action.Builder(
            R.drawable.ic_reply,
            context.getString(R.string.reply), replyPI)
            .addRemoteInput(remoteInput)
            .build();
}
项目:phonegap-plugin-push    文件:PushHandlerActivity.java   
/**
 * Takes the pushBundle extras from the intent,
 * and sends it through to the PushPlugin for processing.
 */
private boolean processPushBundle(boolean isPushPluginActive, Intent intent) {
    Bundle extras = getIntent().getExtras();
    Bundle remoteInput = null;

    if (extras != null) {
        Bundle originalExtras = extras.getBundle(PUSH_BUNDLE);

        originalExtras.putBoolean(FOREGROUND, false);
        originalExtras.putBoolean(COLDSTART, !isPushPluginActive);
        originalExtras.putBoolean(DISMISSED, extras.getBoolean(DISMISSED));
        originalExtras.putString(ACTION_CALLBACK, extras.getString(CALLBACK));
        originalExtras.remove(NO_CACHE);

        remoteInput = RemoteInput.getResultsFromIntent(intent);
        if (remoteInput != null) {
            String inputString = remoteInput.getCharSequence(INLINE_REPLY).toString();
            Log.d(LOG_TAG, "response: " + inputString);
            originalExtras.putString(INLINE_REPLY, inputString);
        }

        PushPlugin.sendExtras(originalExtras);
    }
    return remoteInput == null;
}
项目:Capitolo6    文件:ActionsPresets.java   
@Override
public void apply(Context context, NotificationCompat.Builder builder,
        NotificationCompat.WearableExtender wearableOptions) {
    RemoteInput remoteInput = new RemoteInput.Builder(NotificationUtil.EXTRA_REPLY)
            .setLabel(context.getString(R.string.example_reply_answer_label))
            .setChoices(new String[] { context.getString(R.string.yes),
                    context.getString(R.string.no), context.getString(R.string.maybe) })
            .build();
    NotificationCompat.Action action = new NotificationCompat.Action.Builder(
            R.drawable.ic_full_reply,
            context.getString(R.string.example_reply_action),
            NotificationUtil.getExamplePendingIntent(context,
                    R.string.example_reply_action_clicked))
            .addRemoteInput(remoteInput)
            .build();
    wearableOptions.addAction(action);
}
项目:Capitolo6    文件:ActionsPresets.java   
@Override
public void apply(Context context, NotificationCompat.Builder builder,
        NotificationCompat.WearableExtender wearableOptions) {
    NotificationCompat.Action phoneAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_full_action,
            context.getString(R.string.phone_action),
            NotificationUtil.getExamplePendingIntent(context,
                    R.string.phone_action_clicked))
            .build();
    builder.addAction(phoneAction);

    RemoteInput remoteInput = new RemoteInput.Builder(NotificationUtil.EXTRA_REPLY)
            .setLabel(context.getString(R.string.example_reply_label))
            .build();

    NotificationCompat.Action wearableAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_full_reply,
            context.getString(R.string.wearable_action),
            NotificationUtil.getExamplePendingIntent(context,
                    R.string.wearable_action_clicked))
            .addRemoteInput(remoteInput)
            .build();
    wearableOptions.addAction(wearableAction);
}
项目:Capitolo6    文件:NotificationIntentReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(ACTION_EXAMPLE)) {
        if (mEnableMessages) {
            String message = intent.getStringExtra(NotificationUtil.EXTRA_MESSAGE);
            Bundle remoteInputResults = RemoteInput.getResultsFromIntent(intent);
            CharSequence replyMessage = null;
            if (remoteInputResults != null) {
                replyMessage = remoteInputResults.getCharSequence(NotificationUtil.EXTRA_REPLY);
            }
            if (replyMessage != null) {
                message = message + ": \"" + replyMessage + "\"";
            }
            Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
        }
    } else if (intent.getAction().equals(ACTION_ENABLE_MESSAGES)) {
        mEnableMessages = true;
    } else if (intent.getAction().equals(ACTION_DISABLE_MESSAGES)) {
        mEnableMessages = false;
    }
}
项目:AcDisplay    文件:Action.java   
/**
 * {@inheritDoc}
 */
@Nullable
@Override
public Action[] makeFor(@NonNull Notification notification) {
    Notification.Action[] src = notification.actions;

    if (src == null) {
        return null;
    }

    final int length = src.length;
    final Action[] dst = new Action[src.length];
    for (int i = 0; i < length; i++) {
        RemoteInput[] remoteInputs = getRemoteInputs(src[i]);
        dst[i] = new Action(src[i].icon, src[i].title, src[i].actionIntent, remoteInputs);
    }

    return dst;
}
项目:AcDisplay    文件:RemoteInputUtils.java   
@TargetApi(Build.VERSION_CODES.KITKAT_WATCH)
@Nullable
public static RemoteInput[] toCompat(@Nullable android.app.RemoteInput[] srcArray) {
    if (srcArray == null) return null;
    RemoteInput[] result = new RemoteInput[srcArray.length];
    try {
        Constructor constructor = RemoteInput.class.getDeclaredConstructor(
                String.class, CharSequence.class, CharSequence[].class,
                boolean.class, Bundle.class);
        constructor.setAccessible(true);
        for (int i = 0; i < srcArray.length; i++) {
            android.app.RemoteInput src = srcArray[i];
            result[i] = (RemoteInput) constructor.newInstance(
                    src.getResultKey(), src.getLabel(), src.getChoices(),
                    src.getAllowFreeFormInput(), src.getExtras());
        }
    } catch (NoSuchMethodException
            | InvocationTargetException
            | InstantiationException
            | IllegalAccessException e) {
        Log.e(TAG, "Failed to create the remote inputs!");
        return null;
    }
    return result;
}
项目:AcDisplay    文件:NotifyWidget.java   
@Override
public void onActionClick(@NonNull NotificationActions na,
                          @NonNull View view, final @NonNull Action action,
                          @NonNull RemoteInput remoteInput,
                          @NonNull CharSequence text) {
    final Intent intent = new Intent();
    final Bundle bundle = new Bundle();
    bundle.putCharSequence(remoteInput.getResultKey(), text);
    RemoteInput.addResultsToIntent(action.remoteInputs, intent, bundle);
    mFragment.unlock(
            new Runnable() {
                @Override
                public void run() {
                    // TODO: Cancel pending finish if sending pending intent
                    // has failed.
                    PendingIntent pi = action.intent;
                    Activity activity = mFragment.getActivity();
                    PendingIntentUtils.sendPendingIntent(pi, activity, intent);
                }
            }, false);
}
项目:OpenHAB_Room_Flipper    文件:WearNotificationActions.java   
private NotificationCompat.Action getPersonReplyMessageAction(int conversationId) {
    // Create intent for action
    Intent intent = new Intent(ACTION_RESPONSE);
    intent.putExtra(WEAR_NOTIFICATION_CONVERSATION_ID_KEY, conversationId);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, intent,
            PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT);

    //A simple, non-limited, voice input without pre-defined input patterns.
    RemoteInput remoteInput = new RemoteInput.Builder(WEAR_PERSON_REPLY)
            .setLabel("Listening...")
            .setAllowFreeFormInput(true)
            .build();

    //Create action
    return new NotificationCompat.Action.Builder(R.drawable.ic_white_reply,
            "Reply", pendingIntent)
            .addRemoteInput(remoteInput)
            .build();
}
项目:OpenHAB_Room_Flipper    文件:WearNotificationActions.java   
private NotificationCompat.Action getGroupMessageAction() {
    // Create intent for action
    Intent intent = new Intent(ACTION_RESPONSE);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, intent,
            PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT);

    String[] replyChoices = mContext.getResources().getStringArray(R.array.wear_reply_choices);

    //A simple, non-limited, voice input without pre-defined input patterns.
    RemoteInput remoteInput = new RemoteInput.Builder(WEAR_GROUP_MESSAGE)
            .setLabel("Select or speak")
            .setChoices(replyChoices)
            .build();

    //Create action
    return new NotificationCompat.Action.Builder(R.drawable.ic_message_members_white,
            "Message", pendingIntent)
            .addRemoteInput(remoteInput)
            .build();
}
项目:AndroidWearable-Samples    文件:ActionsPresets.java   
@Override
public void apply(Context context, NotificationCompat.Builder builder,
        NotificationCompat.WearableExtender wearableOptions) {
    RemoteInput remoteInput = new RemoteInput.Builder(NotificationUtil.EXTRA_REPLY)
            .setLabel(context.getString(R.string.example_reply_answer_label))
            .setChoices(new String[] { context.getString(R.string.yes),
                    context.getString(R.string.no), context.getString(R.string.maybe) })
            .build();
    NotificationCompat.Action action = new NotificationCompat.Action.Builder(
            R.drawable.ic_full_reply,
            context.getString(R.string.example_reply_action),
            NotificationUtil.getExamplePendingIntent(context,
                    R.string.example_reply_action_clicked))
            .addRemoteInput(remoteInput)
            .build();
    wearableOptions.addAction(action);
}
项目:AndroidWearable-Samples    文件:ActionsPresets.java   
@Override
public void apply(Context context, NotificationCompat.Builder builder,
        NotificationCompat.WearableExtender wearableOptions) {
    NotificationCompat.Action phoneAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_full_action,
            context.getString(R.string.phone_action),
            NotificationUtil.getExamplePendingIntent(context,
                    R.string.phone_action_clicked))
            .build();
    builder.addAction(phoneAction);

    RemoteInput remoteInput = new RemoteInput.Builder(NotificationUtil.EXTRA_REPLY)
            .setLabel(context.getString(R.string.example_reply_label))
            .build();

    NotificationCompat.Action wearableAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_full_reply,
            context.getString(R.string.wearable_action),
            NotificationUtil.getExamplePendingIntent(context,
                    R.string.wearable_action_clicked))
            .addRemoteInput(remoteInput)
            .build();
    wearableOptions.addAction(wearableAction);
}
项目:AndroidWearable-Samples    文件:NotificationIntentReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(ACTION_EXAMPLE)) {
        if (mEnableMessages) {
            String message = intent.getStringExtra(NotificationUtil.EXTRA_MESSAGE);
            Bundle remoteInputResults = RemoteInput.getResultsFromIntent(intent);
            CharSequence replyMessage = null;
            if (remoteInputResults != null) {
                replyMessage = remoteInputResults.getCharSequence(NotificationUtil.EXTRA_REPLY);
            }
            if (replyMessage != null) {
                message = message + ": \"" + replyMessage + "\"";
            }
            Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
        }
    } else if (intent.getAction().equals(ACTION_ENABLE_MESSAGES)) {
        mEnableMessages = true;
    } else if (intent.getAction().equals(ACTION_DISABLE_MESSAGES)) {
        mEnableMessages = false;
    }
}
项目:AndroidWearable-Samples    文件:ResponderService.java   
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (null == intent || null == intent.getAction()) {
        return Service.START_STICKY;
    }
    String action = intent.getAction();
    if (action.equals(ACTION_RESPONSE)) {
        Bundle remoteInputResults = RemoteInput.getResultsFromIntent(intent);
        CharSequence replyMessage = "";
        if (remoteInputResults != null) {
            replyMessage = remoteInputResults.getCharSequence(EXTRA_REPLY);
        }
        processIncoming(replyMessage.toString());
    } else if (action.equals(MainActivity.ACTION_GET_CONVERSATION)) {
        broadcastMessage(mCompleteConversation.toString());
    }
    return Service.START_STICKY;
}
项目:AndroidWearable-Samples    文件:ResponderService.java   
private void showNotification() {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Sent: " + mLastResponse);
    }
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setContentTitle(getString(R.string.eliza))
            .setContentText(mLastResponse)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.bg_eliza))
            .setSmallIcon(R.drawable.bg_eliza)
            .setPriority(NotificationCompat.PRIORITY_MIN);

    Intent intent = new Intent(ACTION_RESPONSE);
    PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent,
            PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT);
    Notification notification = builder
            .extend(new NotificationCompat.WearableExtender()
                    .addAction(new NotificationCompat.Action.Builder(
                            R.drawable.ic_full_reply, getString(R.string.reply), pendingIntent)
                            .addRemoteInput(new RemoteInput.Builder(EXTRA_REPLY)
                                    .setLabel(getString(R.string.reply))
                                    .build())
                            .build()))
            .build();
    NotificationManagerCompat.from(this).notify(0, notification);
}
项目:muzei    文件:NewWallpaperNotificationReceiver.java   
private void triggerUserCommandFromRemoteInput(final Context context, Intent intent) {
    Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
    if (remoteInput == null) {
        return;
    }
    final String selectedCommand = remoteInput.getCharSequence(EXTRA_USER_COMMAND).toString();
    final PendingResult pendingResult = goAsync();
    final LiveData<Source> sourceLiveData = MuzeiDatabase.getInstance(context).sourceDao().getCurrentSource();
    sourceLiveData.observeForever(new Observer<Source>() {
        @Override
        public void onChanged(@Nullable final Source selectedSource) {
            sourceLiveData.removeObserver(this);
            if (selectedSource != null) {
                for (UserCommand action : selectedSource.commands) {
                    if (TextUtils.equals(selectedCommand, action.getTitle())) {
                        SourceManager.sendAction(context, action.getId());
                        break;
                    }
                    pendingResult.finish();
                }
            }
        }
    });
}
项目:Pugnotification    文件:Wear.java   
public Wear remoteInput(@DrawableRes int icon, String title, PendingIntent pendingIntent) {
    if (icon <= 0) {
        throw new IllegalArgumentException("Resource ID Icon Should Not Be Less Than Or Equal To Zero!");
    }

    if (title == null) {
        throw new IllegalArgumentException("Title Must Not Be Null!");
    }

    if (pendingIntent == null) {
        throw new IllegalArgumentException("PendingIntent Must Not Be Null!");
    }

    this.remoteInput = new RemoteInput.Builder(PugNotification.mSingleton.mContext.getString(R.string.pugnotification_key_voice_reply))
            .setLabel(PugNotification.mSingleton.mContext.getString(R.string.pugnotification_label_voice_reply))
            .setChoices(PugNotification.mSingleton.mContext.getResources().getStringArray(R.array.pugnotification_reply_choices))
            .build();
    wearableExtender.addAction(new NotificationCompat.Action.Builder(icon,
            title, pendingIntent)
            .addRemoteInput(remoteInput)
            .build());
    return this;
}
项目:AndroidWearNotifications    文件:ActionsPresets.java   
@Override
public void apply(Context context, NotificationCompat.Builder builder) {
    RemoteInput remoteInput = new RemoteInput.Builder(NotificationUtil.EXTRA_REPLY)
            .setLabel(context.getString(R.string.example_reply_answer_label))
            .setChoices(new String[] { context.getString(R.string.yes),
                    context.getString(R.string.no), context.getString(R.string.maybe) })
            .build();
    NotificationCompat.Action action = new NotificationCompat.Action.Builder(
            R.drawable.ic_full_reply,
            context.getString(R.string.example_reply_action),
            NotificationUtil.getExamplePendingIntent(context,
                    R.string.example_reply_action_clicked))
            .addRemoteInput(remoteInput)
            .build();
    builder.addAction(action);
}
项目:android-Notifications    文件:ActionsPresets.java   
@Override
public void apply(Context context, NotificationCompat.Builder builder,
        NotificationCompat.WearableExtender wearableOptions) {
    RemoteInput remoteInput = new RemoteInput.Builder(NotificationUtil.EXTRA_REPLY)
            .setLabel(context.getString(R.string.example_reply_answer_label))
            .setChoices(new String[] { context.getString(R.string.yes),
                    context.getString(R.string.no), context.getString(R.string.maybe) })
            .build();
    NotificationCompat.Action action = new NotificationCompat.Action.Builder(
            R.drawable.ic_full_reply,
            context.getString(R.string.example_reply_action),
            NotificationUtil.getExamplePendingIntent(context,
                    R.string.example_reply_action_clicked))
            .addRemoteInput(remoteInput)
            .build();
    wearableOptions.addAction(action);
}
项目:android-Notifications    文件:ActionsPresets.java   
@Override
public void apply(Context context, NotificationCompat.Builder builder,
        NotificationCompat.WearableExtender wearableOptions) {
    NotificationCompat.Action phoneAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_full_action,
            context.getString(R.string.phone_action),
            NotificationUtil.getExamplePendingIntent(context,
                    R.string.phone_action_clicked))
            .build();
    builder.addAction(phoneAction);

    RemoteInput remoteInput = new RemoteInput.Builder(NotificationUtil.EXTRA_REPLY)
            .setLabel(context.getString(R.string.example_reply_label))
            .build();

    NotificationCompat.Action wearableAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_full_reply,
            context.getString(R.string.wearable_action),
            NotificationUtil.getExamplePendingIntent(context,
                    R.string.wearable_action_clicked))
            .addRemoteInput(remoteInput)
            .build();
    wearableOptions.addAction(wearableAction);
}
项目:android-Notifications    文件:NotificationIntentReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(ACTION_EXAMPLE)) {
        if (mEnableMessages) {
            String message = intent.getStringExtra(NotificationUtil.EXTRA_MESSAGE);
            Bundle remoteInputResults = RemoteInput.getResultsFromIntent(intent);
            CharSequence replyMessage = null;
            if (remoteInputResults != null) {
                replyMessage = remoteInputResults.getCharSequence(NotificationUtil.EXTRA_REPLY);
            }
            if (replyMessage != null) {
                message = message + ": \"" + replyMessage + "\"";
            }
            Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
        }
    } else if (intent.getAction().equals(ACTION_ENABLE_MESSAGES)) {
        mEnableMessages = true;
    } else if (intent.getAction().equals(ACTION_DISABLE_MESSAGES)) {
        mEnableMessages = false;
    }
}
项目:wear    文件:NotificationUtils.java   
public static void showNotificationWithInputForPrimaryAction(Context context) {
    Intent intent = new Intent(ACTION_TEST);
    PendingIntent pendingIntent =
            PendingIntent.getActivity(context, 0, intent, 0);

    RemoteInput remoteInput = new RemoteInput.Builder(ACTION_EXTRA)
            .setLabel(context.getString(R.string.action_label))
            .setChoices(context.getResources().getStringArray(R.array.input_choices))
            .build();

    NotificationCompat.Action action =
            new NotificationCompat.Action.Builder(R.drawable.ic_launcher,
                    "Action", pendingIntent)
                    .addRemoteInput(remoteInput)
                    .build();

    NotificationManagerCompat.from(context).notify(getNewID(),
            new NotificationCompat.Builder(context)
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentTitle(context.getString(R.string.action_title))
                    .setContentText(context.getString(R.string.action_text))
                    .setContentIntent(pendingIntent)
                    .extend(new WearableExtender().addAction(action))
                    .build());
}
项目:wear    文件:NotificationUtils.java   
public static void showNotificationWithInputForSecondaryAction(Context context) {
    Intent intent = new Intent(ACTION_TEST);
    PendingIntent pendingIntent =
            PendingIntent.getActivity(context, 0, intent, 0);

    RemoteInput remoteInput = new RemoteInput.Builder(ACTION_EXTRA)
            .setLabel(context.getString(R.string.action_label))
            .build();

    NotificationCompat.Action action =
            new NotificationCompat.Action.Builder(R.drawable.ic_launcher,
                    "Action", pendingIntent)
                    .addRemoteInput(remoteInput)
                    .build();

    NotificationManagerCompat.from(context).notify(getNewID(),
            new NotificationCompat.Builder(context)
                    .setContentTitle(context.getString(R.string.action_title))
                    .extend(new WearableExtender().addAction(action))
                    .build());
}
项目:wearable    文件:VoiceNotiActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_voice_noti);

    //note android developer page, shows this in a separate method, but not necessary.

    Bundle remoteInput = RemoteInput.getResultsFromIntent( getIntent());
    if (remoteInput != null) {
        info = remoteInput.getCharSequence(EXTRA_VOICE_REPLY).toString();
    } else {
        info = "No voice reponse.";
    } 
    logger = (TextView) findViewById(R.id.logger);
    logger.setText(info);
}