my app/activity (starts a tracking) can be started from another app. In my case the app is called from browser. I added an intent filter for incoming links.
<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="destination"
android:scheme="mwde" />
</intent-filter>
This works fine. My problem is, that when user start the activity again, the onDestroyed function is called, but I don't want that in this case. Is there any way to prevent this?
Try to use this flag in the app manifest
https://developer.android.com/guide/topics/manifest/activity-element#lmode
Related
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"
Although I have gone through related document on google for app indexing
https://developers.google.com/app-indexing/webmasters/details
But still have confusion that If I want to receive incoming data on launcher activity and from there If can take control and start relevant activity/fragment depending on some internal parsing over incoming url.
You have to declare the action, category and data in a separate <intent-filter> tag, not in the same one with launcher specs.
<activity>
<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="your.domain.com"
android:scheme="http" />
</intent-filter>
</activity>
Not quite sure if I understood what your asking, so please correct me if I'm not answering your question.
Only the activity (or activities) that you put the intent filter in will catch an intent and start. Therefore, if you only put the intent filter in one activity, only that activity will start, and not any of the others. You can put multiple intent filters in the same activity to catch multiple intents. You can also use the path segment of the url to send more information to your activity, and parse it in your activity.
Put the following in your manifest under the activity you want to launch (the path is optional):
<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="www.yourwebsite.com" />
</intent-filter>
Use a url like http://www.yourwebsite.com/yourstring to open the app.
Then use getIntent().getData() to get the uri that started the activity. You can then parse the uri to get yourstring.
Add Following Intent filter to Activity you want to open via Deep linking in Manifest.
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Then As per Intent data you get in Activity you can perform your action, too.
I want my service to be accessible as one of the default options of the Share page when the user long-touches the web-link (standard android feature). This is what I wrote in the manifest file :
<service android:name=".ShareLink"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</service>
But it is still not being displayed. What am I doing wrong? P.S. When I do the same thing with the Activity - it works fine.
This is not possible, You will have to write a Dummy Activity to do this.
This is because, ResolverActivity that shows the names or selects the appropriate component to launch gets the list by querying Only Activities that match intent with API PackageManager.queryIntentActivities
This should do it:
<intent-filter
android:label="Open Using My Service">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
</intent-filter>
Is it possible to catch when the link was clicked in Android Service.
I do know that it is impossible to catch onTouch Event in the service. But maybe WebBrowser starting is possible?. Please help! Very Important.
I need to start my Web Based app when the specific link was clicked.
An activity can be registered to be started using a url, which you define in your manifest
<activity android:name=".YourActivity">
<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="yourscheme" />
</intent-filter>
</activity>
Your activity will then be launched if a link looking like yourscheme://something is clicked
I am trying to configure my manifest file to indicate my application can open PDF files. The below configuration works, but it gives some funny behavior with the emulator:
When the "view" action is present, my application is not started on install (when I run from Eclipse, the application gets installed on the emulator, but it does not start automatically).
When application/pdf is present, after running from eclipse the application doesn't show up in my emulator's application menu.
(I don't see either of these issues if my only intents are "main" and "launcher")
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/pdf" />
</intent-filter>
EDIT: Okay, I was a little confused about intents. The solution to my above issues is to have 2 different intent-filters, as shown below.
However, I do have a second question. Android successfully launches my app for PDF files, but when it launches onCreate(bundle) is called and not startActivity(Intent). How should I get the intent data?
<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" />
<data android:mimeType="application/pdf" />
</intent-filter>
In your Activity, you can use getIntent() to get the intent used to start it.
startIntent() is not a callback. Its a method for you to call in order to launch another intent.
When your Activity is launched, you will get your onStart() (and onCreate, just before that), called, and from there you call getIntent() to re