4

I followed the example I found here to get a web link to open one of my app's activities. I got it to work, but now I need to have it retrieve the variable-value pair the url has.

When I click on this url http://www.tapabook.com/tapa/?tapa=578 it opens the right activity, but getPathSegments() only retrieves 1 segment, which is "tapa" (instead of "tapa=578"). Is there a way to retrieve the whole pair?

Here's my manifest, in case there's some problem with it preventing what I want

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.alberovalley.tappabook"
android:versionCode="1"
android:versionName="1.0" android:installLocation="auto">

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/Theme.Sherlock.Light.DarkActionBar" 
    android:name="com.alberovalley.tappabook.Tappabook">

    <activity
        android:name="com.alberovalley.tappabook.actividad.LoginA"
        android:configChanges="orientation"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity 
        android:name="com.alberovalley.tappabook.actividad.MenuFA" 
        android:label="@string/app_name">
    </activity>
    <activity
        android:name="com.alberovalley.tappabook.actividad.ListaTapasFA"            
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name="com.alberovalley.tappabook.actividad.DetalleTapaFA"
        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:host="tapabook.com"
               android:pathPrefix="/tapa/"
               android:scheme="http" />
           <data
               android:host="www.tapabook.com"
               android:pathPrefix="/tapa/"
               android:scheme="http" />
        </intent-filter>
    </activity>

</application>

</manifest>

Here's the code from my activity where I check if it's being called from the Intent.ACTION_VIEW and, in said case, retrieve the data.

   Intent i = getIntent();
    final String action = i.getAction();
    Log.d(CData.LOGTAG, "acción del intent " + action);
    if (Intent.ACTION_VIEW.equals(action)) {
        final List<String> segments = i.getData().getPathSegments();
        Log.d(CData.LOGTAG, "Contenido nº segmentos URL interceptada " + segments.size());
        if (segments.size() > 0) {
            Log.d(CData.LOGTAG, "Contenido de la URL interceptada [" + segments.get(0) + "]");
            idTapa = Long.parseLong( segments.get(0) );
        }
    }else{
        idTapa = i.getExtras().getLong(TapaDao.ID, -1);
        Log.d(CData.LOGTAG, "DetalleTapaFA.onCreate idTapa = " + idTapa);
    }

Any help would be appreciated.

Community
  • 1
  • 1
Frank
  • 2,777
  • 5
  • 18
  • 30

1 Answers1

1

getEncodedQuery() will give you the entire query part of the Uri. From the docs:

Gets the encoded query component from this URI. The query comes after the query separator ('?') and before the fragment separator ('#'). This method would return "q=android" for "http://www.google.com/search?q=android".

Use that instead of getPathSegments()

cottonBallPaws
  • 21,220
  • 37
  • 123
  • 171
  • Now,My Url is "https://www.alo7.com/global/audio/album/introduction?albumId=64&sourceUrl=https://parent-voice-media-player.beta.saybot.net/#/introReading?showAll=false&uuid=119796d0-e825-0135-de25-0c4de9bf6bbe", Then,How to solve get the right query? – Longalei Jul 03 '19 at 07:13