Special Android keyboard for sending images

I'm currently trying to implement a custom keyboard that sends an image (perhaps with intent?) To a specific application. In particular, I am trying to create a key on a user keyboard that will send an image to the default messaging application so that it can be sent as MMS.

I modified the SoftKeyboard project to do this. Here is what I still have:

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);
    }
}

The problem is that I get a runtime exception that says:

android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

I am not familiar with Android custom keyboards, but I'm not sure that creating a new activity is the best idea. Anyone have any suggestions?

+4
3

, . Android , .

:

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

+3

, - FLAFG_ACTIVITY_NEW_TASK . . , (, , ).

+1

:

pictureMessageIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

uri, :

// To get images from uri
pictureMessageIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 

:

startActivity(pictureMessageIntent);
0

All Articles