下面列出了android.app.RemoteInput#addResultsToIntent ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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();
}
}
@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();
}
}
static void addResultsToIntent(RemoteInputCompatBase.RemoteInput[] remoteInputs,
Intent intent, Bundle results) {
RemoteInput.addResultsToIntent(fromCompat(remoteInputs), intent, results);
}