In my android app, I implemented a deep link so that when the user accessed my website, it offers to open it via my mobile app.
<activity
android:name=".MyActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="myhost"
android:pathPrefix="/myprefix"
android:scheme="http" />
<data
android:host="myhost"
android:pathPrefix="/myprefix"
android:scheme="https" />
</intent-filter>
</activity>
Some of the features in my website is not implemented in the mobile. That's why I'm opening the browser for the user whenever they want to access that certain feature.
try {
Uri intentData = Uri.parse(url);
Intent httpIntent = new Intent(Intent.ACTION_VIEW);
httpIntent.setDataAndType(intentData, "text/plain"); //NON-NLS
startActivity(httpIntent);
} catch (Exception e) {
//print error that user has no browser
}
The problem I'm having is that, after opening the browser, chrome is asking the user whether they want to open the url via chrome or my app. I want to avoid that because I'm the one redirected them to the browser.
This thread is the only one I found related to my question, unfortunately it has no answer.
Related
I have a custom ROM and have no default browser except WebView Browser Tester. I have develop my own kind of web browser app(webviewclient activity) and install this in a phone. Now I want that whatever URLs when user click in a phone, my browser application will intercept and load this URL. Here is what I am using in intent_filter
<intent_filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent_filter>
But it is not working and still WebView browser Tester app launch and loading links. Can someone tell me how I can set my app as a default browser App OR use any special intent which can help to launch this activity while clicking on any URL?
Try adding both intent filters
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="http"
android:host="*"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="https"
android:host="*" />
</intent-filter>
For this you have to identify the launching Activity of Browser application, something like this:
Intent intent = new Intent();
intent.setComponent(new ComponentName("/*Pass your browser package*/","com.google.android.browser.BrowserActivity /*And pass Browser Activity*/"));
intent.setAction("android.intent.action.VIEW");
intent.addCategory("android.intent.category.BROWSABLE");
Uri uri = Uri.parse(url);
intent.setData(uri);
try
{
startActivity(intent);
}
catch (Exception e)
{
e.printStackTrace();
}
Answer already available on this link
I'm trying to open an android app when I tap a URL inside an email. It's working well the app is opening, the problem is when I use the "Internet Browser" it opens the android on the browser, that means I will have two instances of the Android app. This doesn't happen using Chrome browser, it only calls the app, it doesn't open on the browser.
I resolved this problem using:
android:launchMode="singleInstance" and android:launchMode="singleTask"
but I'm not able to reach the parameters from the URL tapped to open the app.
URL structure: email://act/parameter1/parameter2
This is my code:
<activity
android:name=".Login"
android:screenOrientation="portrait"
android:exported="true"
android:windowSoftInputMode="stateHidden|adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="act" android:scheme="email" />
</intent-filter>
</activity>
In conclusion, I would like to open the app only with one instance (not on the browser) and be able to reach the parameters, using any browser (Chrome, Internet, Firefox).
Thanks in advance
You didn't post your activity code, but i will try to guess the problem: If your activity is a singleTask you need to handle incomming Intents in onCreate() and in onNewIntent() . This is because Activity will be created only once and each next incoming Intent will be then handled by onNewIntent()
My android app allows to open other website like "http://www.google.com" in a web browser from app. And my code is below.
<activity
android:name=".HomeActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
</activity>
But this gives me a problem. In the email or text message, click any website link, there will be a choice to open from my app. See the picture I posted. If I click on www.google.com in the text message, I will get a choice to open from my app.
I don't want the popup shows my app. How to handle this? Please help. Thanks a lot.
You can't avoid that, unless you specifically know what browser the user wants to use. And you don't know that.
You could have a WebView activity/fragment bundled in your application that will display webpages for you. That way you'd have full control. Here's a guide on WebView
Your app is being displayed in the Complete Action Using chooser because of your intent-filter:
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
and particularly because you've specified just a "scheme" entry, with no specific "host". This would in effect offer any web URL intent to open in your app.
Without understanding what your intended behavior exactly is, you can delete the <data> nodes from your intent-filter to remove your app from the Chooser.
Or alternatively, you might want specific URL's to offer your app in the Chooser, like http://yourserver.com and https://yourserver.com, for this you could alter your intent-filter as follows:
<data android:scheme="http" android:host="yourserver.com" />
If your question is to block URLs of other websites in your android app for download purpose then search for the iConstants.java file in your project and write the following code:
public interface iConstants {
public static final String[] DISABLE_DOWNLOADING = {"URL", };
public static final String WEB_DISABLE = "We cannot allow to download videos form this website.";
}
I am trying to create an URL scheme for my Android application but when i enter the link in the browser it opens the link not the app. So far my code looks like this. The link is formed like this http://myhost.com .
<activity android:name=".activities.OpenSchemeActivity"
android:label="#string/activity_open_scheme"
android:screenOrientation="portrait"
android:exported="true"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="myhost.com"/>
</intent-filter>
</activity>
Does anyone have any idea why is not working?
Sorry to say that it will NOT work directly from the browser's address bar. No way. Only further server redirects or link clicks can lead you to an app picker. As far as I know, browser doesn't handle URL schemes being typed into address bar as something that could require an Intent call.
Request OAuth (when twitter button cliked)
final String TW_CALLBACK_URL_STRING = "http://test.com/callback";
final Uri TW_CALLBACK_URI = Uri.parse(TW_CALLBACK_URL_STRING);
twitter4j.auth.RequestToken twRequestToken =
twitter.getOAuthRequestToken(TW_CALLBACK_URI.toString());
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse(twRequestToken.getAuthorizationURL()));
activity.startActivityForResult(intent, TWITTER_REQUEST_CODE);
Manifest
<activity android:name=".TwitterLinkActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data
android:scheme="http"
android:host="test.com" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Twitter Developer App Settings
Clicking twitter button on my app, Web Browser (chrome android) is opened.
And I log in twitter account and click "accept app" button ("애플리케이션 승인" in below image, UZTest is my test twitter app name.)
I am not native English speaker. So I do not know exactly words in English...
I think browser link to http://test.com/callback?~~~~. And My app catch this url, and start activity.
But my app can not... It just link http://www.test.com in chrome android browser.
I tried change callback url = "myapp://test.com", but only http(or https) is only available. (Twitter Developer)
How can I receive oauth token?
I did sovle it!
Below two value is not same value (?)
final String TW_CALLBACK_URL_STRING = "http://test.com/callback";
Callback URL: http://test.com/callback (OAuth Setting in Twitter Developer)
1 is only use my app. So I change to "myscheme://myhost" in java code and manifest file.
2 is not oauth request callback url (I do not know exactly what.)
Then It works fine.