Java Code Examples for android.app.RemoteInput#addResultsToIntent()

The following examples show how to use android.app.RemoteInput#addResultsToIntent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KakaoTalkListener.java    From KakaoBot with GNU General Public License v3.0 6 votes vote down vote up
public static void send(String room, String message) throws IllegalArgumentException { // @author ManDongI
    Notification.Action session = null;

    for(Session i : sessions) {
        if(i.room.equals(room)) {
            session = i.session;

            break;
        }
    }

    if(session == null) {
        throw new IllegalArgumentException("Can't find the room");
    }

    Intent sendIntent = new Intent();
    Bundle msg = new Bundle();
    for (RemoteInput inputable : session.getRemoteInputs()) msg.putCharSequence(inputable.getResultKey(), message);
    RemoteInput.addResultsToIntent(session.getRemoteInputs(), sendIntent, msg);

    try {
        session.actionIntent.send(context, 0, sendIntent);
    } catch (PendingIntent.CanceledException e) {
        e.printStackTrace();
    }
}
 
Example 2
Source File: MessagingBuilder.java    From decorator-wechat with Apache License 2.0 4 votes vote down vote up
@Override public void onReceive(final Context context, final Intent proxy) {
	final PendingIntent reply_action = proxy.getParcelableExtra(EXTRA_REPLY_ACTION);
	final String result_key = proxy.getStringExtra(EXTRA_RESULT_KEY), reply_prefix = proxy.getStringExtra(EXTRA_REPLY_PREFIX);
	final Uri data = proxy.getData(); final Bundle results = RemoteInput.getResultsFromIntent(proxy);
	final CharSequence input = results != null ? results.getCharSequence(result_key) : null;
	if (data == null || reply_action == null || result_key == null || input == null) return;	// Should never happen

	final String key = data.getSchemeSpecificPart(), original_key = proxy.getStringExtra(EXTRA_ORIGINAL_KEY);
	if (BuildConfig.DEBUG && "debug".equals(input.toString())) {
		final Conversation conversation = mController.getConversation(proxy.getIntExtra(EXTRA_CONVERSATION_ID, 0));
		if (conversation != null) showDebugNotification(conversation, "Type: " + conversation.typeToString());
		mController.recastNotification(original_key != null ? original_key : key, null);
		return;
	}
	final CharSequence text;
	if (reply_prefix != null) {
		text = reply_prefix + input;
		results.putCharSequence(result_key, text);
		RemoteInput.addResultsToIntent(new RemoteInput[]{ new RemoteInput.Builder(result_key).build() }, proxy, results);
	} else text = input;
	final ArrayList<CharSequence> history = SDK_INT >= N ? proxy.getCharSequenceArrayListExtra(EXTRA_REMOTE_INPUT_HISTORY) : null;
	try {
		final Intent input_data = addTargetPackageAndWakeUp(reply_action);
		input_data.setClipData(proxy.getClipData());

		reply_action.send(mContext, 0, input_data, (pendingIntent, intent, _result_code, _result_data, _result_extras) -> {
			if (BuildConfig.DEBUG) Log.d(TAG, "Reply sent: " + intent.toUri(0));
			if (SDK_INT >= N) {
				final Bundle addition = new Bundle(); final CharSequence[] inputs;
				final boolean to_current_user = Process.myUserHandle().equals(pendingIntent.getCreatorUserHandle());
				if (to_current_user && context.getPackageManager().queryBroadcastReceivers(intent, 0).isEmpty()) {
					inputs = new CharSequence[] { context.getString(R.string.wechat_with_no_reply_receiver) };
				} else if (history != null) {
					history.add(0, text);
					inputs = history.toArray(new CharSequence[0]);
				} else inputs = new CharSequence[] { text };
				addition.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, inputs);
				mController.recastNotification(original_key != null ? original_key : key, addition);
			}
			markRead(key);
		}, null);
	} catch (final PendingIntent.CanceledException e) {
		Log.w(TAG, "Reply action is already cancelled: " + key);
		abortBroadcast();
	}
}
 
Example 3
Source File: RemoteInputCompatApi20.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
static void addResultsToIntent(RemoteInputCompatBase.RemoteInput[] remoteInputs,
        Intent intent, Bundle results) {
    RemoteInput.addResultsToIntent(fromCompat(remoteInputs), intent, results);
}