0

「 http://www.myapp.com/1234 」などの指定されたリンクをクリックしたときにアプリケーションを開くインテント フィルターを作成しました。リンクをクリックすると、アプリを開くように求められます。OK、すべてうまくいきます。次に、すべてのアクティビティが閉じるまで戻るボタンを繰り返しクリックして、アプリを終了しました。しかし:

  1. ランチャーからアプリを再度起動すると、リンクをクリックしたときと同じ Intent データを受け取ります。どのようにそれを回避しますか?

  2. リンクからアプリを開くと、つまり. WhatsAppから、アプリマネージャーでわかるように、WhatsAppは開かれたアプリケーションです! なぜ?

これが私の現在のマニフェストコードです:

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

0 に答える 0