-2

I have my own custom keyboard so using the keyboard's inputs method I am getting a whole text from edit text whether it is from my own app or even from a third-party app. Everything working properly expects all Microsoft applications. They provide me only just limited character text. So how do I achieve this in Ms apps too? This is my code to get a text through the keyboard.

        ExtractedTextRequest extractedTextRequest = new ExtractedTextRequest();
        ExtractedText extractedText = getCurrentInputConnection().getExtractedText(extractedTextRequest, 0);

        wordReadAloud = ((String) extractedText.text);
        CharSequence textBeforeCursor = getCurrentInputConnection().getTextBeforeCursor(wordReadAloud.length(), 0);
Pravin Suthar
  • 1,403
  • 1
  • 14
  • 25
  • 2
    Is not died but how can we help you if you have provided only 4 lines of code? How do you "get text from 3rd party app"? Using an AccessibilityService? Using an Xposed Module (requiring Root Permissions)? And other questions for many things....You just write something like "I cannot do X, please help" without providing nothing...... – emandt Mar 17 '21 at 15:04

3 Answers3

1

A simple answer to this question is that you can not do it. Android architecture does not allow you to take the components(String, images, media, etc.) from another app if the developer of that app does not intend to share those things. So create your own content.

Aakash Sharma
  • 427
  • 1
  • 6
  • 15
  • But I got the full text from other app expect all ms's app. I have my own custom keyboard so I can get text using the above code. Just a problem with Ms's apps. They gave us some limited text. – Pravin Suthar Mar 24 '21 at 06:28
0

you can send using these code please vote after solve your issue

        Intent sendIntent = new Intent(Intent.ACTION_SEND);
        sendIntent.setType("text/plain");
        sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
        Intent shareIntent = Intent.createChooser(sendIntent, "Your Post IS Ready to share");
        context.startActivity(shareIntent);
axar
  • 539
  • 2
  • 17
0

first, you have set in manifest file in which activity or first activity you want to get data

reference URL - https://developer.android.com/training/sharing/receive

first, I have to try this example after that I have to share you with code so please after
complete understand then vote don't get the wrong vote without your testing...

<intent-filter>
            <action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="image/*" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="text/plain" />
        </intent-filter>

after that get intent data in the activity...

    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();

    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if ("text/plain".equals(type)) {
            handleSendText(intent); // Handle text being sent
        } else if (type.startsWith("image/")) {
            handleSendImage(intent); // Handle single image being sent
        }
    } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
        if (type.startsWith("image/")) {
          //  handleSendMultipleImages(intent); // Handle multiple images being sent
        }
    } else {
        // Handle other intents, such as being started from the home screen
    }

}


void handleSendText(Intent intent) {
    String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
    if (sharedText != null) {
        // Update UI to reflect text being shared
        Log.e("textData", "handleSendText: "+sharedText);
    }
}

void handleSendImage(Intent intent) {
    Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
    if (imageUri != null) {
        // Update UI to reflect image being shared
        Log.e("ImageData", "handleSendImage: "+imageUri);
    }
}
axar
  • 539
  • 2
  • 17