I looked at related SO but they didn't seem to resolve this issue.
The app supports app linking and website has .well-known/assetlinks.json.
When clicking app link in email, say https://staging.xyz.com/v3/info/7vwD2yjW, the
main activity should appear
onCreate() should get URI data from intent.data
main activity should update itself based on URI data
Launching app from a cold start with a valid app link, the intent.data is always null. However if app had been running or in background, URI intent.data is not null in onNewIntent() and works fine.
Not sure what I am missing. It's running on a Galaxy J3 Prime, Android 7.0. Here is the config. Any ideas how to get intent.data URI from cold start?
<activity
android:name=".activity.MainActivity"
android:launchMode="singleInstance"
android:screenOrientation="portrait">
<tools:validation testUrl="https://staging.xyz.com/v3/info/7vwD2yjW" />
<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:scheme="https"
android:host="xyz.com"
android:pathPattern="/.*/share" />
</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:scheme="https"
android:host="xyz.com"
android:pathPattern="/.*/info/.*" />
</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:scheme="https"
android:host="*.xyz.com"
android:pathPattern="/.*/share" />
</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:scheme="https"
android:host="*.xyz.com"
android:pathPattern="/.*/info/.*" />
</intent-filter>
Check out this question . You should override onNewIntent and then handle data from it.
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
// do stuff with intent
}
Turns out this works as-is. There was an exception elsewhere causing launch activity to skip updating from URI data. Posting resolution in case it may be useful to anyone else.
To track down I attached debugger to device process during cold start from app link in Android Studio like so:
adb shell am set-debug-app -w --persistent com.xyz.appname
adb shell am start -a android.intent.action.VIEW -d "https://staging.xyz.com/v3/info/7vwD2yjW" com.xyz.appname
Then Run -> Debug -> select debug config with link
An API call is made, and displays a PopupWindow with busy indicator in the launch activity. The popup was throwing exception:
BadTokenException: Unable to add window -- token null is not valid; is your activity running?
To get popup working, in onCreate() popup is displayed after activity startup cycle completes
activityRootView.post {
handleAppLinkIntent(intent) // show busy popup and do stuff with intent.data
}
Try changing android:launchMode="singleInstance" to android:launchMode="singleTask"
Related
I try to kill the app by swiping from the recent apps but the application is still alive. There is a singleton object that keeps the session information in the Application class. When I restart the app after swiping, this singleton is still kept. So there is still a valid session.
This happens sometimes and not reproducible for each try. It probably(I'm not sure) happens after starting an activity with a Uri
val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse("myapp://someactivity")
startActivity(intent)
Target activity in AndroidManifest.xml:
<activity
android:name="TargetActivity"
android:label="#string/app_name">
<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" />
<data android:scheme="myapp2" />
</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="#string/url_host"
android:pathPrefix="#string/url1"
android:scheme="https" />
<data
android:host="#string/url_host"
android:pathPrefix="#string/url_2"
android:scheme="https" />
</intent-filter>
</activity>
I faced the problem on various Android versions (6, 7, 8).
I want my app to be launched when a link with a specific, custom scheme is clicked on.
But it only works from adb with:
./adb shell a start -a Android.Intent.Action.VIEW -d "ghd://whateversite.com"
It doesn't work when a link is clicked, or the URL is written directly in the browser.
I'm using:
<activity
android:name=".link.LaunchActivity"
android:theme="#android:style/Theme.NoDisplay">
<intent-filter>
<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:scheme="ghd" />
</intent-filter>
</activity>
Set android:host too in the Intent filter
<activity
android:name=".link.LaunchActivity"
android:noHistory="true"
android:theme="#android:style/Theme.NoDisplay">
<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:scheme="ghd" android:host="whateversite.com" />
</intent-filter>
</activity>
Try to remove the autoVerify=true from your <intent-filter/>. As said in the documentation :
When the android:autoVerify attribute is present, installing your app causes the system to attempt to verify all hosts associated with the web URIs in all of your app's intent filters. The system treats your app as the default handler for the specified URI pattern only if it successfully verifies all app link patterns declared in your manifest.
Since you didn't add any host, this might be why it is not working.
I've read a tutorial on how to launch an app from a link on the browser. I've created an activity 'TestLaunch'.
<activity
android:name=".TestMe"
android:label="Test">
<intent-filter>
<data android:scheme="testme.com" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>
</activity>
Then I connected my android phone and clicked 'debug' on Eclipse. The app launched as usual. I openned the browser and typed 'testme.com'. The activity was not started as expected. Is this because the app is not fully installed on the phone or because I am understanding wrongly how the intent filter works?
try this:
<activity
android:name=".TestMe"
android:label="Test">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>
<data android:host="www.testme.com" android:scheme="http"></data>
</intent-filter>
</activity>
I want from the android browser be able to launch my application if it's installed, or launch my website in the other case.
So in order to make it work, I put :
<activity android:name=".MMLogin" android:label="MeetMe" android:theme="#android:style/Theme.NoTitleBar" android:screenOrientation="portrait">
<intent-filter>
<data android:scheme="http" android:host="meet-me.com" android:path="/signin" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
in the Manifest, and I created a dummy link to test; and it's not working.
I've tried with and without: BROWSABLE and DEFAULT
I've tried with meetme://datas and change the scheme; nothing worked.
I used threads on stackoverflow like :
Launch custom android application from android browser
What am I doing wrong, or is there a special thing to do to make it work ?
My application suppports from API 7.
Cheers
I used :
Intent Filter to Launch My Activity when custom URI is clicked, I think what was missing is this block :
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/myapp" />
</intent-filter>
There are many answers in stackoverflow showing how to lauch app from a web browser ,but I am not sure what went wrong with my code, that never seems to be doing the intended.
I am trying to launch my app by a URL from any other app like web browser,initially
my manifest file looks like this
<activity android:name=".Main">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data android:scheme="http" android:host="ebay.com" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
And When I typed http://ebay.com in the browser that never started my app.Obviously,how does the browser know about my app?,then i tried the other way around and added another Activity called MyActivity and altered the manifest file as
<activity android:name=".Main">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MyActivity">
<intent-filter>
<data android:scheme="http" android:host="ebay.com" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
and tried in my Main Activity
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("http://mycityway.com")));
Thus producing the intended result.I can also start another application Activity using this method.
But most of the answers here says that the later is possible.What is the mistake i am doing,I couldn't launch my app from browser.Please guide me.
And When I typed http://ebay.com in the browser that never started my
app.
It gets started when a matching link is clicked not when you type the url in the browser.
Try it by sending yourself an email containing http://ebay.com and click the link in the email application.