Android意图过滤器问题

时间:2013-10-16 10:13:28

标签: android android-intent intentfilter

我创建了一个Intent过滤器,用于在点击指定的链接(例如“http://www.myapp.com/1234”)时打开我的应用程序。当我点击链接时,我被要求打开应用程序,好的,一切正常。然后,我通过在后退按钮中反复单击来退出应用程序,直到所有活动都关闭。但是:

  1. 从启动器再次启动应用程序后,它会收到与之相同的Intent数据 在我点击链接之前。如何避免它?

  2. 当我从链接打开我的应用时,即。来自WhatsApp,正如我在应用程序管理器中看到的,WhatsApp是打开的应用程序!为什么呢?

  3. 这是我当前的清单代码:

        <activity
            android:name="com.x.y.SplashActivity"
            android:label="@string/app_name"
            android:noHistory="true"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <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="@string/app_host"
                    android:pathPrefix="/events/"
                    android:scheme="http" />
            </intent-filter>
        </activity>
    

    和我的onCreate()

        // Retrieve the Intent
        Intent intentUri = getIntent();
    
        // Check URI
        Uri uri = intentUri.getData();
    
        if (uri != null) {
            // Try to extract the data
            // For now, data could be a public event id, so parse it
            List<String> pathSegments = uri.getPathSegments();
    
            // Check validity
            if (pathSegments.size() > 2) {
                // Finally, get the public event id
                String publicEventId = pathSegments.get(2);
    
                // Set poll as responded
                user.setPollEventId(publicEventId);
            }
    
            // Remove the intent to prevent further calls
            setIntent(null);
        }
    
        // Open the main activity normally
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
    

0 个答案:

没有答案