I'm trying to open a specific url with my app instead of browser. I have it working correctly except if my app is already open, the url doesn't open to the page specified.
My manifest file is as follows:
<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="myapp"/>
<data android:scheme="http"/>
</intent-filter>
And I'm getting the intent data as:
Intent intent = getIntent();
Uri data = intent.getData();
But getIntent() returns the intent that started my activity, what if my url click didn't start my activity and the activity had already been created, how do I get the intent for whatever is resuming the app (so my specific path link). Is that even possible???
I am targeting Android 4.2.2
how do I get the intent for whatever is resuming the app (so my specific path link)
Override onNewIntent() and use the Intent passed into it.
Related
I'm making an app that takes an URL to X domain, makes a get with Jsoup, scraps some content, and the present that content. I've already done that with an EditText on my app, but what i want now is that the app can be selected as an app to open the url from other apps(You know, when the app shows an URL, you click, and then a prompt asks which app would you want to use), and then pass that url as the parameter of the EditText, doesn't matter if directly start execution, or if just paste the url on the EditText.
want now is that the app can be selected as an app to open the url
from other apps
Add intent-filter with BROWSABLE category in AndroidManifest:
<activity ...>
<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" />
<data android:scheme="https" />
</intent-filter>
</activity>
pass that url as the parameter of the EditText, doesn't matter if
directly start execution, or if just paste the url on the EditText
Call getIntent().getData() in BROWSABLE Activity to get provided Uri to open or show in EditText :
// prepare URL
Uri dataUri = getIntent().getData();
URL webUrl = new URL(dataUri.getScheme(),
dataUri.getHost(),
dataUri.getPath());
Hello friends i want to open my application when particular type of url is being called in browser (Predefined format)
following is rout on server
Redirect::to('intent://com.customlymade.activit/#Intent;scheme=customlymade;package=com.customlymade.activity;end');
and following is the intent filter i am using in my manifest file
<intent-filter>
<data
android:host="com.customlymade.activity"
android:scheme="customlymade" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
But Nothing is working Please help.
I guess, that the redirect is executed automatically. Chrome in android has a security feature, that starting an activity can only be done after a user action (like clicking on a link). See chapter "See also" at https://developer.chrome.com/multidevice/android/intents
And Chrome doesn’t launch an external app for a given Intent URI in the following cases.
When the Intent URI is redirected from a typed in URL.
When the Intent URI is initiated without user gesture.
This question already has answers here:
How to implement my very own URI scheme on Android
(5 answers)
Closed 7 years ago.
I want to make an android app that can be used as a default application for opening a certain kind of link (like if I click http://facebook.com it will show me suggested app to open that link, browser or facebook's app)
These are called Implicit Intents
Assume you want to open your app on web link click with link "myApp://someapp"
then in your App Manifest
<activity android:name="MyActivity">
<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="myApp" android:host="path" />
</intent-filter>
</activity>
Whenever you click the above link, it will suggest to open your app.
If you want to developed application that allow the other application to complete the action using your application, for example in your case you want to handle the any of url user click, your application will be listed for complete the action. You have to create the activity that will handle the deep linking. For that you need to add some attributes to your handle activity in your android manifest. see below example
The following XML snippet shows how you might specify an intent filter in your manifest for deep linking. The URIs that start with “http”
<activity
android:name="com.example.android.BrowseActivity"
>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "http://www.example.com/gizmos” -->
<data android:scheme="http"
android:host="www.example.com"
android:pathPrefix="/gizmos" />
<!-- note that the leading "/" is required for pathPrefix-->
<!-- Accepts URIs that begin with custom url "example://gizmos” -->
<data android:scheme="com.example.android"
android:host="gizmos" />
</intent-filter>
</activity>
Once you've added intent filters with URIs for activity content to your app manifest, Android is able to route any Intent that has matching URIs to your app at runtime.
Once the system starts your activity(BrowseActivity) through an intent filter, you can use data provided by the Intent to determine what you need to render. Call the getData() and getAction() methods to retrieve the data and action associated with the incoming Intent. You can call these methods at any time during the lifecycle of the activity, but you should generally do so during early callbacks such as onCreate() or onStart().
Here’s a snippet that shows how to retrieve data from an Intent inside BrowseActivity:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
}
Let me know if you need more help on this point thank you.
i have create an activity in an application com.example.one which calls another activity in application com.example.two.
In the activity two manifest i have declared the following intent-filter
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
</intent-filter>
However on calling this activity with action - Intent.ACTION_VIEW or even with android.intent.action.VIEW directly invokes the browser rather than a Intent chooser that i have put.
Intent ii=new Intent(Intent.ACTION_VIEW);
ii.setData(Uri.parse("http://www.google.com"));
startActivity(Intent.createChooser(ii,"done"));
kindly update why i am not getting the intent chooser for browser and my activity.
thanks
Probably you need to include another browsable category with intent filter.
<category android:name="android.intent.category.BROWSABLE" />
Clear the browser defaults settings, than try to invoke your
method, it should ask for the action to choose the available apps,
with this time only and always, here you go with it.
To clear go to the settings -> Apps -> browsers [Chrome, Firefox or any other if installed]
than to each browser press button 'Clear defaults'.
I am trying to read (first time - new to me) a gmail attachment (.gcsb extension) in my app. The intent filter looks like this:
<intent-filter>
<action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>
<data android:pathPattern="*.gcsb"></data>
<data android:mimeType="application/*"></data>
</intent-filter>
and that appears to get the 'download' and 'preview' buttons to appear next to the attachment in gmail (without that filter, the buttons do not appear).
In the activity (onCreate() / onRestart()) I do:
....
Intent intent = getIntent();
if (!Intent.ACTION_VIEW.equals(intent.getAction())) {
// Deal with the file from gmail here
}
....
to check if it is gmail that has caused this to start the activity or not.
However intent.getAction() always resolves to android.intent.action.MAIN, so it never does anything. There is another intent filter in the activity:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
being for the app launch, but I don't understand why I never see the android.intent.action.VIEW from gmail?
The answer appears to be that the activity was set to be 'single instance' for various reasons. This means that whilst it is brought to the foreground again, it comes back with the intent it was originally started with, not the one created by gmail.
Removing the 'single instance' attribute allowed the correct intent to be used.