41641

How to receive a URL from my android app after being forwarded from browser.

Question:

When a user visits the browser page for my app I am forwarding them to a url scheme like so:

intent://share?id=123#Intent;package=com.aerstone.mobile;scheme=myapp;launchFlags=268435456;end;

I've tested this and this works fine. Now, when the user visits my app's home page from the browser and have the app installed, the app automatically opens up.

Relevant part from my manifest is:

<activity android:configChanges="keyboardHidden|orientation" android:label="@string/app_name" android:name=".ui.activity.MainActivity" android:launchMode="singleTask" > <!-- add the above launchMode attribute --> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> <!-- add the below additional 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="myapp"/> </intent-filter> </activity>

<strong>Question</strong>

After the app opens up, how can I fetch the URL? I want to fetch the id=123 part of the URL. How can I do this?

Answer1:

Call getIntent().getData() in onCreate(), or getData() on the passed-in Intent to onNewIntent(), depending on whether your activity was already created or not. That will return the Uri representing your URL.

Answer2:

In onCreate()

Uri uri = getIntent().getData(); //Returns the URI that was used. String id = uri.getQueryParameter("id"); //Gives any parameter passed in the URI.

Recommend

  • ActionBar three-dot dropdown opens at the wrong place
  • Access 2007 forms with parameterized RecordSource
  • EditText is covered by Keyboard
  • ConnectivityManager.CONNECTIVITY_ACTION deprecated
  • Android custom URI scheme incorrectly encoded when type in browser
  • Failed to find version-tag string. File must be updated
  • Alamofire and Reachability.swift not working on xCode8-beta5
  • Installing Perl6 and Panda on Ubuntu 15.10. Problems with bootstrap.pl
  • Can my PDF ping my server when it is opened?
  • HTML5 video only works in IE. The other browsers shows the black screen
  • Why must we declare a variable name when adding a method to a struct in Golang?
  • Python ImageIO Gif Set Delay Between Frames
  • xcode don't localize specific strings
  • How do I configure context broker accept post requests from my remote sensor?
  • Installed module is empty
  • Textfile Structure (tables)
  • chrome.tabs.executeScript only fires when the Developer Console is open
  • Swift: Switch statement fallthrough behavior
  • Android full screen on only one activity?
  • Meteor helpers not available in Angular template
  • The plugin 'org.apache.maven.plugins:maven-jboss-as-plugin' does not exist or no valid ver
  • java.lang.NoClassDefFoundError: com.parse.Parse$Configuration$Builder on below Lollipop versions
  • What is Eclipse's Declaration View used for?
  • req.body is undefined - nodejs
  • swift auto completion not working in Xcode6-Beta
  • Accessing IRQ description array within a module and displaying action names
  • Sony Xperia Z Tablet not found by adb
  • How to recover from a Spring Social ExpiredAuthorizationException
  • Excel - Autoshape get it's name from cell (value)
  • ILMerge & Keep Assembly Name
  • Can I make an Android app that runs a web view in Chrome 39?
  • Which linear programming package should I use for high numbers of constraints and “warm starts” [clo
  • Updated Ionic CLI but shows previous version (Windows)
  • Large data - storage and query
  • How can I estimate amount of memory left with calling System.gc()?
  • Jquery - Jquery Wysiwyg return html as a string
  • WOWZA + RTMP + HTML5 Playback?
  • SVN: Merging two branches together
  • Hits per day in Google Big Query
  • Append folder name and increment by 1 using batch script