I am trying to get a string from a browser. I used the SEND action in AndroidManifest.xml
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
In MainActivity.java, I have the following code
@Override
public void onResume() {
super.onResume();
Intent receivedIntent=getIntent();
etSearch.setText(getStringFromIntent(receivedIntent));
}
public String getStringFromIntent(Intent receivedIntent) {
String receivedAction = receivedIntent.getAction();
String receivedType = receivedIntent.getType();
if (receivedAction.equals(Intent.ACTION_SEND)) {
if (receivedType.startsWith("text/")) {
String receivedText = receivedIntent
.getStringExtra(Intent.EXTRA_TEXT);
if (receivedText != null) {
return receivedText.trim();
}
}
}
return "";
}
For the first time, I try to make everything work correctly.

When I try to do this, the text is not updated

I thought it was due to onCreate (). So I moved the code to onResume (). Nothing happened.
In accordance with this decision, I added receivedIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);and
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
this.setIntent(intent);
}
There is no effect.
What should I do to renew my intention additionally?
source
share