1

Android でhttps://mobikul.com/use-safariviewcontroller-callback-url-objective-c/を達成しようとしています。iOS の例では「sourceApplication」がチェックされており、SFSafariViewController がアプリケーションにリダイレクトされることのみを許可しています。 (おそらく、アプリによってインスタンス化された SFSafariViewController です...しかし、それは別の質問です!)。

Android でパリティを達成するのに問題があります。私のアプリでは、HTML からBrowserActivityにリダイレクトする Chrome カスタム タブを開きます。Chrome /電話のブラウザは、正しいURLスキーマを入力するだけでリダイレクトできることCallbackActivityがわかりました。これは悪いニュースです! マニフェストにホワイトリスト メカニズムが必要なようで、アプリケーションから開かれた Chrome カスタム タブのみが自分のアクティビティにリダイレクトされ、他のユーザーは許可されません。アプリケーションからのリダイレクト機能が壊れるため、マニフェストで設定できません。どうすればこれを達成できますか?CallbackActivityandroid:exported="false"CallbackActivity

Android マニフェスト用に用意したものは次のとおりです。

    <activity android:name="com.epicgames.ue4.SplashActivity" android:launchMode="singleTask" android:debuggable="true">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    <activity android:name="com.epicgames.ue4.GameActivity" android:exported="false"> 
      <meta-data android:name="android.app.lib_name" android:value="UE4" />
    </activity>
    <activity android:name=".BrowserActivity" android:launchMode="singleTask" android:exported="false">
      <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
      </intent-filter>
    </activity>
    <activity android:name=".CallbackActivity" android:launchMode="singleTask">
      <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:scheme="customscheme" android:host="callback" />
      </intent-filter>

そして、これが私が関連する活動のために持っているものです:

public class BrowserActivity extends Activity {
    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);

        final Uri uri = Uri.parse(getIntent().getStringExtra("url"));

        final CustomTabsIntent intent = new CustomTabsIntent.Builder().build();
        intent.intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        intent.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent.intent.setData(uri);

        startActivity(intent.intent);
    }
}

public class CallbackActivity extends Activity {
    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);

        //TODO validate only chrome custom tab HTML, started from my app, redirected here
        //getCallingPackage() is always null and referrer host can be spoofed...how to?

        final Intent intent = new Intent(this, com.epicgames.ue4.GameActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP);
 
        startActivity(intent);
    }
}
4

0 に答える 0