I am trying to use android.intent.action.PROCESS_TEXT to update text in any app's input field when the user opts to do so. The problem is that within some apps the change is not applied despite the fact that I can confirm that the action was triggered, the text was parsed, and my method completed successfully.
I have the following in my manifest:
<activity
android:name=".ProcessTextDefaultActivity"
android:label="@string/menuitem_process_text_default">
<intent-filter>
<action android:name="android.intent.action.PROCESS_TEXT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
And the following relevant method:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (isProcessTextActionCompatible()) return;
boolean isReadOnly = getIntent()
.getBooleanExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, false);
CharSequence inputText = getIntent()
.getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT);
String outputText = inputText.toString();
// Replace characters in string as needed
for (Map.Entry<String, String> entry : dictionary.entrySet()) {
outputText = outputText.replace(entry.getKey(), entry.getValue());
}
if (isReadOnly) {
// Custom method to copy the input to the user clipboard
copyString(outputText);
return;
}
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_PROCESS_TEXT, outputText);
setResult(RESULT_OK, intent);
finish();
}
from Android: Replacing text in field with "Intent.putExtra()" fails in Messenger app
No comments:
Post a Comment