I created a android app, which has webview to load pages.
In my app, home page is EditText and Button, if user enters a URL in textbox then enters button, webview will loads the webpage. This works fine.
If user clicks URL in WhatsApp, mobile has options to open that URL in browsers.
I added the following code in my manifest file, to list my app along with browsers to open URLs
<intent-filter>
<action android:name="redacted.MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>
Now, my app name is also available as option to open the URLs. When I select my app to open the URL, it doesn't paste the url in edit text.
What I need to add more.
In your main activity you need to describe how will onCreate behave when application is opened from an intent.
Reference link:- Link
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Get the intent that started this activity
Intent intent = getIntent();
Uri data = intent.getData();
// Figure out what to do based on the intent type
if (intent.getType().indexOf("image/") != -1) {
// Handle intents with image data ...
} else if (intent.getType().equals("text/plain")) {
// Handle intents with text ...
}
}
Related
My app is a WebView Application and I've setup URL Intent Filters so when a link with the domain "riftacademy.org" is clicked, it opens my app.
Now I'm trying to implement deep-linking into the WebView application...
I saw something similar in the thread here How to enable deep-linking in WebView on Android app?
But unlike the above which uses a custom URI Scheme to open the application, I'd like to implement deep-linking in my WebView using my domain name "riftacademy.org"
In this scenario, when a link such as https://riftacademy.org/login or https://riftacademy.org/register is clicked, it should open the app and go to the pages that match the links. But in this case, it opens the app but only loads the homepage riftacademy.org...
I want the WebView app to be able to load links after the app has been opened, similar to how YouTube and Facebook handle links
Can Deep-Linking be achieved in WebView using Domain Names?
A snippet of where I'm guessing may be needed to edit
newWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW);
browserIntent.setData(Uri.parse(url));
startActivity(browserIntent);
return true;
}
});
return true;
}
});
Thanks in advance
So I've been able to solve this with the help of Ron from https://webintoapp.com ... This was achieved using URI Intent Filters and placing the following code in the MainActivity.java and AndroidManifest.xml
I added this to the OnCreate Method in my MainActivity.java... The website name should be added just after the else{mWebView.loadUrL
SetWebView(mWebView);
Intent intent = getIntent();
Uri data = intent.getData();
if(data != null) {
//Load the deep-link url:
String url = intent.getDataString();
mWebView.loadUrl(url);
}
else
{
mWebView.loadUrl("https://riftacademy.org/");
}
And this to my MainActivity.xml... The android:host should be the website URL as well
<activity android:name=".MainActivity">
<intent-filter android:label="The Title">
<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="riftacademy.org" />
</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="http"
android:host="riftacademy.org" />
This would enable the WebView App to load all kinds of links as long as the links starts with the default URL of the website
https://example.com/public/change_phone?email_recovery_code=F08fjfU39Ea6RSlDzM8ZZJFVwyjAE
<activity android:name=".view.activity.sign_in_new_number.SignInNewNumberActivity">
<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="example.com"
android:pathPrefix="/public/change_phone"/>
</intent-filter>
</activity>
I used the manifest setting's like above but it does not work for Gmail app, the URL does not redirect me on my app just open's the link in Gmail app
if splash screen is the first screen in your app..then use this on onCreate() of your splash activity :
First get the url you are getting through deep linking
Intent intent = getIntent();
Uri data = intent.getData();
if (!isTaskRoot()) {//this will resume your app from last loaded screen if you pressed home button earlier
Log.e("splashfin", "hello");
if (data != null) {
//open that activity through your url or do what ever you want
}else{}
}else{
if(data!=null){
//open that activity through your url or do what ever you want
}
}
What I am trying to achieve is to open Activity automatically when URL is clicked on a browser, notes app or messenger.
So I have this URL format:
http://testsite.com/code/AB1234
In AndroidManifest.xml, I have set Intent filter for Activity:
<activity android:name=".HomeActivity">
<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="testsite.com"
android:pathPrefix="/code"
android:scheme="http" />
</intent-filter>
</activity>
In HomeActivity, just getting code from URL and showing it on Toast:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
String code = getIntent().getData().getLastPathSegment();
Toast.makeText(this, code, Toast.LENGTH_LONG).show();
}
When I click on link, system is showing my application and browser application on application chooser. I know that this URL can be handled browser also. I would like to know how to make my intent filter to have priority if it is possible.
Is it possible to open my app automatically? If yes how to make it? How I should change my intent filter?
If you have control over the link, the easiest way to achieve what you want is to set unique scheme for your app.
<data android:host="testsite.com"
android:pathPrefix="/code"
android:scheme="myapp" />
Now i have one edit text and one button. i am copy the download link from the browser and paste it to the edit text it perfectly work. but i want to need if user using any browser and they click the download link the file will be download via my app.
First you have to have intent filter in your download activity inside manifest like this
<activity
android:name="Downloader">
<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="domain.com"
android:scheme="http" />
</intent-filter>
</activity>
Then inside your "Download" activity's onCreate handle data:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
}
You can download file using uri
I'm trying to pass data to my activity, but unfortunately I'm still unsuccessful. What I am trying to accomplish is to select a file in the file browser, share it and pass the data to my activity.
Inside my manifest I added an intent filter:
<activity android:name=".MyActivity" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="*/*"/>
</intent-filter>
</activity>
Inside my Java file i'm trying to get the data:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.myactivity);
Intent intent = getIntent();
Uri data = intent.getData();
if (data != null) {
// process the data
} else {
// no data received
}
}
When I select a file from My Files and share it, my app is visible in the list, when i click it it launches my activity, but intent.getData(); always returns null.
Am i missing something? Thanks.
you can get the data from the example given below:
Use an with a element. For example, to handle all links to twitter.com, you'd put this inside your in your AndroidManifest.xml:
<intent-filter>
<data android:scheme="http" android:host="twitter.com"/>
<action android:name="android.intent.action.VIEW" />
</intent-filter>
Then, when the user clicks on a link to twitter in the browser, they will be asked what application to use in order to complete the action: the browser or your application.
Of course, if you want to provide tight integration between your website and your app, you can define your own scheme:
<intent-filter>
<data android:scheme="my.special.scheme" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>
Then, in your web app you can put links like:
<a href="my.special.scheme://other/parameters/here">
And when the user clicks it, your app will be launched automatically (because it will probably be the only one that can handle my.special.scheme:// type of uris). The only downside to this is that if the user doesn't have the app installed, they'll get a nasty error. And I'm not sure there's any way to check.
Edit: To answer your question, you can use getIntent().getData() which returns a Uri object. You can then use Uri.* methods to extract the data you need. For example, let's say the user clicked on a link to http://twitter.com/status/1234:
strong textUri data = getIntent().getData();
String scheme = data.getScheme(); // "http"
String host = data.getHost(); // "twitter.com"
List<String> params = data.getPathSegments();
String first = params.get(0); // "status"
String second = params.get(1); // "1234"
You can do the above anywhere in your Activity, but you're probably going to want to do it in onCreate(). You can also use params.size() to get the number of path segments ienter code heren the Uri. Look to javadoc or the android developer website for other Uri methods you can use to extract specific parts.
Launch custom android application from android browser