Intent.getData() returns the same uri - android

I am trying to open my app through a url which has a query parameter in it that I need to check to proceed to the next screen. Here is what the Android Manifest for that activity looks like:
<activity
android:name=".ContainerActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize"
android:theme="#style/AppTheme.NoActionBar"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"
/>
<data android:scheme="https" />
<data android:host="myapp" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
The app launches fine with the uri https://myapp?groupCode=1234 but the problem is that I am getting the same uri every time (on certain devices) even after I uninstall the app and install it for the first time. Here is where I get the uri
Uri uri = getIntent().getData();
Log.d(TAG, "the uri is "+uri);
The uri is always
https://myapp?groupCode=1234
Really lost on this one. I can only reproduce the issue on a couple of devices a samsung s6 is the one I'm working with now. I've tried little things like
android:allowBackup="false"
android:fullBackupContent="false"
I've also tried to capture the new intent in onNewIntent() but I can't seem to get that to fire for this activity. Idea here was to see if setting the new intent would work, but its just mind blowing to me that this doesn't work after a complete uninstall, reinstall and then opening of the app through a url like https://myapp?groupCode=abcd and still getting back the url https://myapp?groupCode=1234
Please help!
EDIT:
I should add that the device I'm not getting it to work on has been using Hockey to get apks onto the device. The way hockey works is kinda crappy, you basically download the apk and then manually install it on the phone. This phone probably has 100 apks on it by now. Is there any way that there is data being cached somewhere where a new app would capture it? I cannot recreate the issue for devices that have not been using hockey/have a ton of apk files. I don't see why this would matter exactly but I'm basically just trying anything at this point.
I will also add that the onNewIntent() was simply not being called because the activity is destroyed by the time you click on the link.

Related

Android deep link delivered again when I reopen the app

I use deep links in my app.
This is my activity in manifest
<activity
android:name=".ui.MainActivity"
android:exported="true"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar.Launcher">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="app.mydomain.com"
android:pathPrefix="/prefix"
android:scheme="https" />
</intent-filter>
</activity>
And this is how I get deep link
Uri uri = getIntent().getData();
After I'm done with handling deep link and some other logic in MainActivity, I navigate user to other activity, and finish MainActivity.
The problem is, in certain scenario, I got deep link delivered over and over again. This is scenario whet problem happens:
At moment I click link, my app is not in memory or closed by tap on system back button.
After link handled in my app, I close app with system back button.
Then I open app by clicking on it's preview (not launcher icon) in menu with all in memory apps (opens by clicking on one system button on my phone). And deep link is delivered again.
The problem is, when link delivered I can't identify, is it this particular problematic case scenario, and I should ignore the link, or is user actually clicked the link, and I should handle it.
Saving the link in static variable to check if is it the same link would be not good, cause user may click the same link again to review the same data.
The problem also persists with Firebase Dynamic Links.
My phone runs on Android 12 (api level 31), Samsung S21
Found a solution, thanks to this answer
I check if activity was launched from history using this method, and if true, then I ignore deep link
private boolean isActivityLaunchedFromHistory() {
return getIntent().getFlags() ==
(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
}

Android app defaults - two handling activities, setting default activity

I'm doing something like custom browser with 2 options: View or Download page. Manifest file looks something like this:
<activity android:name=".ViewActivity" .... >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
<data android:scheme="https" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
<activity android:name=".DownloadActivity" .... >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
<data android:scheme="https" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
When I open URL I can select what to do. Everything works fine until I select DownloadActivity and confirm with ALWAYS -> it sets app defaults (Open by default). And next time when I click on link, URL is handled by ViewActivity (just because it is first declared in Manifest file - I tried to swap activities in manifest).
Can you help me how to fix it a set the default Activity (not Application) for opening URL? And when I set Download as ALWAYS so it will be always downloading and if I set View as ALWAYS it will be always Viewed. Is it possible? Or is there any other possible solution?
Thanks
I'm not 100% sure, but I think it is a limitation of how android stores "default" (by clicking on ALWAYS) and dispatches url to intent filter.
Android stores just which application should be open by clicking on ALWAYS, and not which Activity, because Activities can be renamed, deleted etc. So imagine you as the android system has to lookup how to open http://foo.com for an app. You have to look at the in the internal lookup table for the "default" (by clicking on ALWAYS) and then determine that the app with the package com.example.myapp should be open.
Now imagine that rather than just the package name of the app you would store the concrete Activity com.example.myapp.DownloadActivity. That would be dangerous as hell, because DownloadActivity could have been renamed, deleted or even just the intent filter could has been removed from DownloadActivity between setting DownloadActivity as "default" and an update of your app that has introduced that change.
The only thing the android operating system gets notified is when an app has been installed or uninstalled, but not if an activity of an app has been renamed or deleted etc.
Hence is not possible for android to guarantee that it can keep the mapping from http://foo.com to com.example.myapp.DownloadActivity up to date.
Therefore, Android is just launching the app with package com.example.myapp for `http://foo.com and then let the app dispatch it internally to the first Intent filter that matches from your apps manifest.
As already said, I'm not 100% sure, but to me it seems reasonable ...

Air for Android share youtube video via my app?

Having spent two days banging my head against my desk, I've decided to ask for some help...
I'm trying to share videos and other links to my air for android app that I am developing with Flash CS6. I have added to following to my manifest file:
<![CDATA[
<manifest>
<application>
<activity android:name=".ui.MyActivity" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
I know that this is supposed to trigger the activity ".ui.MyActivity" when the SEND intent is invoked. I have also added the following code to my AS code:
NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, onAppInvoke);
function onAppInvoke(event:InvokeEvent):void {
Status_txt.text = event.arguments.toString()
Status_txt.text += event
}
But i really haven't had much luck. The best result i've obtained is the opening of my app but the event.arguments array is empty. Other results include the foce closing of my app whenever other share with it or the failing of my app to compile.
Does anyone have any advice?
Thanks in advance!
Smollett

Reading a custom file launched using Box

We have developed an Android app which is used for rendering files of our custom file type (.vds). I am able to launch my app for all the files (.vds file) which are stored on local storage, but if the files is stored on Box and I try to access them using the Box Android App then I am facing issues. I have created the following intent filter:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:host="*" />
<data android:pathPattern=".*\\.vds" />
The problem is that in the corresponding activity I am able to get the intent, but if I try to read the URI (as our rendering logic is based upon file location) it gives me a path which doesn't exists on the SD card. What happens if we try to open a file using Box Android Native App? Where is the file downloaded and how should the downloaded file be accessed?
This may solve ur problem. Add the bellow intent filter.
<activity android:name=".Activity"
android:screenOrientation="portrait"
android:label="#string/app_name">
<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"/>
<action android:name="android.intent.action.EDIT"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:pathPattern="*.snowdragon"/>
<data android:mimeType="text/snowdragon"/>
</intent-filter>
</activity>
As noted above I've run into the same problem. While I've not found what I would consider to be The Right Solution(TM) I do have a couple of things to add that might be useful to others:
First, I've discovered that if I download the file in Box (not the same as mark for offline) then clicking the item in either the download result dialog or in the subsequent notification that appears at the bottom of the app works. Once you've dismissed that notification however, there does not seem to be a way to get back to the downloaded file from within Box.
Second, and let me qualify this by saying that I've not looked very closely at it yet but I think one could use the filename info in the intents for non-existent files to retrieve the file via the Box API, either directly from the cloud or possibly via API call to retrieve offline items. I'm wondering if this is actually what Box is trying to get us to do with these bogus file paths, considering that they are so blatantly bogus:
12-04 10:09:29.318: INFO/ActivityManager(607): START u0
{act=android.intent.action.VIEW dat=file:///non_existent_dummy_folder/foo.abcdef typ=application/abcdef cmp=com.foo.bar/.app.FooViewer}

Android: using intent filter to launch app doesn't work

I know this question is asked and answered many times on SO, but I just couldn't get it to work. Here is my manifest file (I have 3 activities, I'm showing the only one that I want to be displayed when associated):
<activity
android:name=".MyActivity"
android:label="#string/app_name"
android:theme="#style/HoloDarkTheme" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.ACTION_SEND" />
<action android:name="android.intent.action.EXTRA_TEXT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.action.BROWSABLE" />
<category android:name="android.intent.action.DEFAULT" />
<data android:scheme="http" />
<data android:host="example.com" />
</intent-filter>
</activity>
When I launch a browser and go to "example.com", my app isn't launched. Is there something wrong with the above XML?
Not sure if relevant, but this activity uses MediaPlayer to play videos. Also, I'm using SDK version 11.
I figured it out. It's simply a case of typo. Instead of this,
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.action.BROWSABLE" />
<category android:name="android.intent.action.DEFAULT" />
I needed to replace "android.intent.action" with "android.intent.category" in the last two lines:
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
I'm adding this answer here because this thread is one of the top hits when googling "intent filter to launch app from http not working". I suppose the root cause for me could also be considered a typo, but I'm going to call it an "Android documentation defect".
There's a line way toward the bottom of this page that breaks down a URI as:
<scheme>://<host>:<port>/<path>
This breakdown indicates that the "://", ":" and "/" will be added for me so I used the following data in my intent-filter:
<data android:scheme="http" />
<data android:host="my.school.edu" />
<data android:path="thingy" />
I then sent myself an SMS with the following text: "my.school.edu/thingy", which was recognized by my SMS client (Hangouts) as a web address, so it made it clickable. However, clicking on it just gave me a choice of browsers, my app was a no-show.
So I removed the host and the path, and my app launched for any link (or at least every one I tried). I put the host back in and it still worked. Put the path back and we're back to not working. On a whim I decided to prepend a slash to the path:
<data android:path="/thingy" />
...et voilĂ ! There's my app in amongst the browsers! So the error in my view is Android's doc that suggests that the slash is inserted automagically. :) It apparently is not.
More Info: I'm using the HTTP scheme because that's what gets made clickable in SMS and email messages, giving me a free ride to that point.
And note that if you specify a unique host (and path), and the user selects "Always" when choosing your app from the list, future taps on your link will bypass that choice dialog and go straight to your app, which is nice.
Make sure you have the internet permission in your manifest.
I doubt that you can override the http scheme to point back to your app.

Categories

Resources