Opening/starting a specific Android activity passing an intent parameter from the browser











up vote
0
down vote

favorite
1












I am developing an Android application and a Website. What I am trying to do now is that I like to open the specific activity of Android application from the browser when the user click on a link. Please see my scenario below.



This is my android activity class



class SphereViewerActivity : AppCompatActivity(){
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_sphere_viewer)
intent.getStringExtra("image_url")

}
}


As you can see in my code, I am getting the image_url parameter from the browser. Is it possible to open that activity passing the parameter from the Javascript or browser?



I found the solution, it is to have the link like this



<a href="intent://scan/#Intent;scheme=zxing;package=com.google.zxing.client.android;S.browser_fallback_url=http%3A%2F%2Fzxing.org;end"> Take a QR code </a>


But how can I pass intent data as parameter?



I tried adding the app links. not working when I click Test App Links



enter image description here










share|improve this question




























    up vote
    0
    down vote

    favorite
    1












    I am developing an Android application and a Website. What I am trying to do now is that I like to open the specific activity of Android application from the browser when the user click on a link. Please see my scenario below.



    This is my android activity class



    class SphereViewerActivity : AppCompatActivity(){
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_sphere_viewer)
    intent.getStringExtra("image_url")

    }
    }


    As you can see in my code, I am getting the image_url parameter from the browser. Is it possible to open that activity passing the parameter from the Javascript or browser?



    I found the solution, it is to have the link like this



    <a href="intent://scan/#Intent;scheme=zxing;package=com.google.zxing.client.android;S.browser_fallback_url=http%3A%2F%2Fzxing.org;end"> Take a QR code </a>


    But how can I pass intent data as parameter?



    I tried adding the app links. not working when I click Test App Links



    enter image description here










    share|improve this question


























      up vote
      0
      down vote

      favorite
      1









      up vote
      0
      down vote

      favorite
      1






      1





      I am developing an Android application and a Website. What I am trying to do now is that I like to open the specific activity of Android application from the browser when the user click on a link. Please see my scenario below.



      This is my android activity class



      class SphereViewerActivity : AppCompatActivity(){
      override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      setContentView(R.layout.activity_sphere_viewer)
      intent.getStringExtra("image_url")

      }
      }


      As you can see in my code, I am getting the image_url parameter from the browser. Is it possible to open that activity passing the parameter from the Javascript or browser?



      I found the solution, it is to have the link like this



      <a href="intent://scan/#Intent;scheme=zxing;package=com.google.zxing.client.android;S.browser_fallback_url=http%3A%2F%2Fzxing.org;end"> Take a QR code </a>


      But how can I pass intent data as parameter?



      I tried adding the app links. not working when I click Test App Links



      enter image description here










      share|improve this question















      I am developing an Android application and a Website. What I am trying to do now is that I like to open the specific activity of Android application from the browser when the user click on a link. Please see my scenario below.



      This is my android activity class



      class SphereViewerActivity : AppCompatActivity(){
      override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      setContentView(R.layout.activity_sphere_viewer)
      intent.getStringExtra("image_url")

      }
      }


      As you can see in my code, I am getting the image_url parameter from the browser. Is it possible to open that activity passing the parameter from the Javascript or browser?



      I found the solution, it is to have the link like this



      <a href="intent://scan/#Intent;scheme=zxing;package=com.google.zxing.client.android;S.browser_fallback_url=http%3A%2F%2Fzxing.org;end"> Take a QR code </a>


      But how can I pass intent data as parameter?



      I tried adding the app links. not working when I click Test App Links



      enter image description here







      android android-intent kotlin






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 18:41

























      asked Nov 10 at 16:55









      Wai Yan Hein

      2,32043691




      2,32043691
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          You have 4 options to achieve what you want:




          1. Deep Links

          2. Android App Links

          3. Firebase Dynamic Links

          4. Firebase App Indexing


          Refer to this post to see more descriptions about them.



          In simplest approach (Deep Links), you can introduce your Activity as a handler of specific pattern URLs and pass the desired parameters as URL query params.



          AndroidManifest.xml



          <activity android:name=".SphereViewerActivity">

          <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 "myapp://zxing" -->
          <data android:host="zxing" />
          <data android:scheme="myapp" />
          </intent-filter>

          </activity>


          SphereViewerActivity.kt



          class SphereViewerActivity : AppCompatActivity(){
          override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_sphere_viewer)

          if (intent != null && intent.action == Intent.ACTION_VIEW) {
          intent.data?.apply{
          if (getQueryParameter("image_url") != null && getQueryParameter("image_url").isNotEmpty()) {
          val imageUrl = data.getQueryParameter ("image_url") as String
          // do what you want to do with imageUrl
          }
          }
          }
          }
          }


          Your html snippet:



          <a href="myapp://zxing?image_url=some_image_url"> Take a QR code </a>





          share|improve this answer























          • I tried adding app links. Even if I set up with the right details and test the link with the right details, not working. Please, check the question edited please?
            – Wai Yan Hein
            Nov 10 at 18:42










          • Ok, your issue is able to solve with simple deep link. I've updated the answer.
            – aminography
            Nov 10 at 18:49










          • @WaiYanHein: Did you test it?
            – aminography
            Nov 10 at 20:13










          • Man. Thanks so much, That worked,
            – Wai Yan Hein
            Nov 10 at 20:14










          • You're welcome dude :)
            – aminography
            Nov 10 at 20:15











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241234%2fopening-starting-a-specific-android-activity-passing-an-intent-parameter-from-th%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote



          accepted










          You have 4 options to achieve what you want:




          1. Deep Links

          2. Android App Links

          3. Firebase Dynamic Links

          4. Firebase App Indexing


          Refer to this post to see more descriptions about them.



          In simplest approach (Deep Links), you can introduce your Activity as a handler of specific pattern URLs and pass the desired parameters as URL query params.



          AndroidManifest.xml



          <activity android:name=".SphereViewerActivity">

          <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 "myapp://zxing" -->
          <data android:host="zxing" />
          <data android:scheme="myapp" />
          </intent-filter>

          </activity>


          SphereViewerActivity.kt



          class SphereViewerActivity : AppCompatActivity(){
          override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_sphere_viewer)

          if (intent != null && intent.action == Intent.ACTION_VIEW) {
          intent.data?.apply{
          if (getQueryParameter("image_url") != null && getQueryParameter("image_url").isNotEmpty()) {
          val imageUrl = data.getQueryParameter ("image_url") as String
          // do what you want to do with imageUrl
          }
          }
          }
          }
          }


          Your html snippet:



          <a href="myapp://zxing?image_url=some_image_url"> Take a QR code </a>





          share|improve this answer























          • I tried adding app links. Even if I set up with the right details and test the link with the right details, not working. Please, check the question edited please?
            – Wai Yan Hein
            Nov 10 at 18:42










          • Ok, your issue is able to solve with simple deep link. I've updated the answer.
            – aminography
            Nov 10 at 18:49










          • @WaiYanHein: Did you test it?
            – aminography
            Nov 10 at 20:13










          • Man. Thanks so much, That worked,
            – Wai Yan Hein
            Nov 10 at 20:14










          • You're welcome dude :)
            – aminography
            Nov 10 at 20:15















          up vote
          2
          down vote



          accepted










          You have 4 options to achieve what you want:




          1. Deep Links

          2. Android App Links

          3. Firebase Dynamic Links

          4. Firebase App Indexing


          Refer to this post to see more descriptions about them.



          In simplest approach (Deep Links), you can introduce your Activity as a handler of specific pattern URLs and pass the desired parameters as URL query params.



          AndroidManifest.xml



          <activity android:name=".SphereViewerActivity">

          <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 "myapp://zxing" -->
          <data android:host="zxing" />
          <data android:scheme="myapp" />
          </intent-filter>

          </activity>


          SphereViewerActivity.kt



          class SphereViewerActivity : AppCompatActivity(){
          override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_sphere_viewer)

          if (intent != null && intent.action == Intent.ACTION_VIEW) {
          intent.data?.apply{
          if (getQueryParameter("image_url") != null && getQueryParameter("image_url").isNotEmpty()) {
          val imageUrl = data.getQueryParameter ("image_url") as String
          // do what you want to do with imageUrl
          }
          }
          }
          }
          }


          Your html snippet:



          <a href="myapp://zxing?image_url=some_image_url"> Take a QR code </a>





          share|improve this answer























          • I tried adding app links. Even if I set up with the right details and test the link with the right details, not working. Please, check the question edited please?
            – Wai Yan Hein
            Nov 10 at 18:42










          • Ok, your issue is able to solve with simple deep link. I've updated the answer.
            – aminography
            Nov 10 at 18:49










          • @WaiYanHein: Did you test it?
            – aminography
            Nov 10 at 20:13










          • Man. Thanks so much, That worked,
            – Wai Yan Hein
            Nov 10 at 20:14










          • You're welcome dude :)
            – aminography
            Nov 10 at 20:15













          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          You have 4 options to achieve what you want:




          1. Deep Links

          2. Android App Links

          3. Firebase Dynamic Links

          4. Firebase App Indexing


          Refer to this post to see more descriptions about them.



          In simplest approach (Deep Links), you can introduce your Activity as a handler of specific pattern URLs and pass the desired parameters as URL query params.



          AndroidManifest.xml



          <activity android:name=".SphereViewerActivity">

          <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 "myapp://zxing" -->
          <data android:host="zxing" />
          <data android:scheme="myapp" />
          </intent-filter>

          </activity>


          SphereViewerActivity.kt



          class SphereViewerActivity : AppCompatActivity(){
          override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_sphere_viewer)

          if (intent != null && intent.action == Intent.ACTION_VIEW) {
          intent.data?.apply{
          if (getQueryParameter("image_url") != null && getQueryParameter("image_url").isNotEmpty()) {
          val imageUrl = data.getQueryParameter ("image_url") as String
          // do what you want to do with imageUrl
          }
          }
          }
          }
          }


          Your html snippet:



          <a href="myapp://zxing?image_url=some_image_url"> Take a QR code </a>





          share|improve this answer














          You have 4 options to achieve what you want:




          1. Deep Links

          2. Android App Links

          3. Firebase Dynamic Links

          4. Firebase App Indexing


          Refer to this post to see more descriptions about them.



          In simplest approach (Deep Links), you can introduce your Activity as a handler of specific pattern URLs and pass the desired parameters as URL query params.



          AndroidManifest.xml



          <activity android:name=".SphereViewerActivity">

          <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 "myapp://zxing" -->
          <data android:host="zxing" />
          <data android:scheme="myapp" />
          </intent-filter>

          </activity>


          SphereViewerActivity.kt



          class SphereViewerActivity : AppCompatActivity(){
          override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_sphere_viewer)

          if (intent != null && intent.action == Intent.ACTION_VIEW) {
          intent.data?.apply{
          if (getQueryParameter("image_url") != null && getQueryParameter("image_url").isNotEmpty()) {
          val imageUrl = data.getQueryParameter ("image_url") as String
          // do what you want to do with imageUrl
          }
          }
          }
          }
          }


          Your html snippet:



          <a href="myapp://zxing?image_url=some_image_url"> Take a QR code </a>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 10 at 18:57

























          answered Nov 10 at 18:22









          aminography

          2,88011127




          2,88011127












          • I tried adding app links. Even if I set up with the right details and test the link with the right details, not working. Please, check the question edited please?
            – Wai Yan Hein
            Nov 10 at 18:42










          • Ok, your issue is able to solve with simple deep link. I've updated the answer.
            – aminography
            Nov 10 at 18:49










          • @WaiYanHein: Did you test it?
            – aminography
            Nov 10 at 20:13










          • Man. Thanks so much, That worked,
            – Wai Yan Hein
            Nov 10 at 20:14










          • You're welcome dude :)
            – aminography
            Nov 10 at 20:15


















          • I tried adding app links. Even if I set up with the right details and test the link with the right details, not working. Please, check the question edited please?
            – Wai Yan Hein
            Nov 10 at 18:42










          • Ok, your issue is able to solve with simple deep link. I've updated the answer.
            – aminography
            Nov 10 at 18:49










          • @WaiYanHein: Did you test it?
            – aminography
            Nov 10 at 20:13










          • Man. Thanks so much, That worked,
            – Wai Yan Hein
            Nov 10 at 20:14










          • You're welcome dude :)
            – aminography
            Nov 10 at 20:15
















          I tried adding app links. Even if I set up with the right details and test the link with the right details, not working. Please, check the question edited please?
          – Wai Yan Hein
          Nov 10 at 18:42




          I tried adding app links. Even if I set up with the right details and test the link with the right details, not working. Please, check the question edited please?
          – Wai Yan Hein
          Nov 10 at 18:42












          Ok, your issue is able to solve with simple deep link. I've updated the answer.
          – aminography
          Nov 10 at 18:49




          Ok, your issue is able to solve with simple deep link. I've updated the answer.
          – aminography
          Nov 10 at 18:49












          @WaiYanHein: Did you test it?
          – aminography
          Nov 10 at 20:13




          @WaiYanHein: Did you test it?
          – aminography
          Nov 10 at 20:13












          Man. Thanks so much, That worked,
          – Wai Yan Hein
          Nov 10 at 20:14




          Man. Thanks so much, That worked,
          – Wai Yan Hein
          Nov 10 at 20:14












          You're welcome dude :)
          – aminography
          Nov 10 at 20:15




          You're welcome dude :)
          – aminography
          Nov 10 at 20:15


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241234%2fopening-starting-a-specific-android-activity-passing-an-intent-parameter-from-th%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Full-time equivalent

          さくらももこ

          13 indicted, 8 arrested in Calif. drug cartel investigation