我目前正在尝试实现一个自定义键盘,该键盘可以通过某种方式(可能是通过意图intent)将图片发送到特定应用程序。更具体地说,我正在尝试创建一个自定义键盘上的按键,以便将图片发送到默认的短信应用程序,以便它可以作为MMS消息发送。
为此,我已经修改了示例SoftKeyboard项目。以下是我目前的进展:
private void handleCharacter(int primaryCode, int[] keyCodes) {
if (isInputViewShown()) {
if (mInputView.isShifted()) {
primaryCode = Character.toUpperCase(primaryCode);
}
}
if (isAlphabet(primaryCode) && mPredictionOn) {
mComposing.append((char) primaryCode);
// Send message here
Intent pictureMessageIntent = new Intent(Intent.ACTION_SEND);
pictureMessageIntent.setType("image/png");
Uri uri = Uri.parse("android.resource://" + this.getPackageName() + "/drawable/icon_en_gb");
pictureMessageIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(pictureMessageIntent);
getCurrentInputConnection().setComposingText(mComposing, 1);
updateShiftKeyState(getCurrentInputEditorInfo());
updateCandidates();
} else {
getCurrentInputConnection().commitText(
String.valueOf((char) primaryCode), 1);
}
}
问题是我遇到了一个运行时异常,错误信息如下:
android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
我对安卓自定义键盘不熟悉,但我不确定启动新的 Activity 是否是最好的选择。有没有人有建议?