'How to receive website url from other apps, such as Google
I'm a new developer. Can someone help me on how to receive website URLs from other apps? My app is currently my default browser, but my problem is that, I don't know how to receive the website URL.
Here's the preview of the app.
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
if ("text/plain".equals(type)) {
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText != null) {
// Update UI to reflect text being shared
webview1.loadUrl(action);
}
}
}
I try to use the code above but it doesn't work.
Also, I don't know how to detect when a user clicks the 'done' or 'go' button in the edittext on the status bar above (see the pic).
I tried this code, but my app keeps closing:
edittext.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) {
//do what you want on the press of 'done'
submit.performClick();
}
return false;
}
});
Please help me.
Edit: I already added an intent filter:
<activity
android:name=".ReceiveUrlActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name"
android:windowSoftInputMode="stateHidden" >
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http"/>
<data android:scheme="https"/>
</intent-filter>
</activity>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
