4

我按照我在此处找到的示例获取了一个 Web 链接来打开我的应用程序的一个活动。我让它工作,但现在我需要让它检索 url 具有的变量值对。

当我点击这个网址http://www.tapabook.com/tapa/?tapa=578时,它会打开正确的活动,但 getPathSegments() 只检索 1 个段,即“tapa”(而不是“tapa=578” )。有没有办法找回整对?

这是我的清单,以防它阻止我想要的东西

<?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>

这是我活动中的代码,我在其中检查是否从 Intent.ACTION_VIEW 调用它,在这种情况下,检索数据。

   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);
    }

任何帮助,将不胜感激。

4

1 回答 1

1

getEncodedQuery()将为您提供 Uri 的整个查询部分。从文档:

从此 URI 获取编码的查询组件。查询位于查询分隔符 ('?') 之后和片段分隔符 ('#') 之前。此方法将为“ http://www.google.com/search?q=android ”返回“q=android ”。

用那个代替getPathSegments()

于 2013-02-04T01:10:36.037 回答