Reputation: 1441
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);
Upvotes: -2
Views: 381
Reputation: 447
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.
Upvotes: 1
Reputation: 539
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);
}
}
Upvotes: 0
Reputation: 539
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);
Upvotes: 0