android.app.RemoteInput#getResultsFromIntent ( )源码实例Demo

下面列出了android.app.RemoteInput#getResultsFromIntent ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: 365browser   文件: NotificationPlatformBridge.java
@Nullable
static String getNotificationReply(Intent intent) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        // RemoteInput was added in KITKAT_WATCH.
        if (intent.getStringExtra(NotificationConstants.EXTRA_NOTIFICATION_REPLY) != null) {
            // If the notification click went through the job scheduler, we will have set
            // the reply as a standard string extra.
            return intent.getStringExtra(NotificationConstants.EXTRA_NOTIFICATION_REPLY);
        }
        Bundle remoteInputResults = RemoteInput.getResultsFromIntent(intent);
        if (remoteInputResults != null) {
            CharSequence reply =
                    remoteInputResults.getCharSequence(NotificationConstants.KEY_TEXT_REPLY);
            if (reply != null) {
                return reply.toString();
            }
        }
    }
    return null;
}
 
源代码2 项目: wearmouse   文件: KeyboardInputController.java
/**
 * Should be called in the Activity's (or Fragment's) onActivityResult() method that was invoked
 * in response to the Intent returned by {@code getInputIntent}.
 */
public void onActivityResult(Intent data) {
    final Bundle result = RemoteInput.getResultsFromIntent(data);
    if (result != null) {
        CharSequence text = result.getCharSequence(Intent.EXTRA_TEXT);
        if (text != null) {
            for (int i = 0, n = text.length(); i < n; ++i) {
                keyboardHelper.sendChar(text.charAt(i));
            }
        }
    }
}
 
@Nullable
private static String getNotificationReply(Intent intent) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        // RemoteInput was added in KITKAT_WATCH.
        Bundle remoteInputResults = RemoteInput.getResultsFromIntent(intent);
        if (remoteInputResults != null) {
            CharSequence reply =
                    remoteInputResults.getCharSequence(NotificationConstants.KEY_TEXT_REPLY);
            if (reply != null) {
                return reply.toString();
            }
        }
    }
    return null;
}
 
private CharSequence getMessageText(Intent intent) {
    Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
    if (remoteInput != null) {
        return remoteInput.getCharSequence(Compatibility.KEY_TEXT_REPLY);
    }
    return null;
}
 
源代码5 项目: AndroidWearable-Samples   文件: MainActivity.java
@Override
protected void onResume() {
    super.onResume();
    if (getIntent() != null) {
        Bundle inputResults = RemoteInput.getResultsFromIntent(getIntent());
        if (inputResults != null) {
            CharSequence replyText = inputResults.getCharSequence(KEY_REPLY);
            if (replyText != null) {
                Toast.makeText(this, TextUtils.concat(getString(R.string.reply_was), replyText),
                        Toast.LENGTH_LONG).show();
            }
        }
    }
}
 
源代码6 项目: decorator-wechat   文件: MessagingBuilder.java
@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 Bundle getResultsFromIntent(Intent intent) {
    return RemoteInput.getResultsFromIntent(intent);
}