【问题标题】:How to open specific activity on clicking on link?如何在点击链接时打开特定活动?
【发布时间】:2017-12-12 06:36:55
【问题描述】:

我正在开发一个 android 应用程序,因为我添加了共享 whatsapp 共享功能,我已经成功完成,现在我想在用户单击我共享的链接时打开我的 android 应用程序的特定活动。我已经搜索链接很少,但没有运气,我希望有朋友能帮助我。

添加清单

  <activity
            android:name=".ProductDescriptionActivity"
            android:exported="true"
            android:screenOrientation="portrait"
            android:theme="@style/Theme.AppCompat.NoActionBar">

            <intent-filter>
                <action android:name="com.abc.allaboutcity.MESSAGE" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>


            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data android:scheme="http"
                    android:host="http://allaboutcity.in"
                    android:pathPrefix="/allaboutcity" />
            </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" />
                <!-- Accepts URIs that begin with "example://gizmos” -->
                <data android:scheme="allaboutcity"
                    android:host="allaboutcity" />
            </intent-filter>
        </activity>

【问题讨论】:

标签: android android-intent deep-linking


【解决方案1】:

您应该在清单文件中将意图过滤器添加到要打开的活动

<activity
    android:name="Your Activity"
    android:label="Your Activity Title"
    android:theme="Your Style">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
    <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data
            android:host="your url"
            android:path="/your path"
            android:scheme="http" />
    </intent-filter>
</activity>

【讨论】:

  • 我应该在哪个活动中写这个?
  • 点击链接时要打开的活动
  • 好的,我试试这个,谢谢兄弟
  • 您好,当为应用程序选择器“完成操作使用”打开对话框时,它没有显示我的应用程序。
  • 如果您的方案是 https,您确定您提供了正确的主机和路径吗?请更改并重试。
【解决方案2】:

在您的 WebView 活动中使用此代码

      Intent intent = getIntent();
      String action = intent.getAction();
      Uri data = intent.getData();

      Webview webView = (WebView) findViewById(R.id.webview_id);
      webView.getSettings().setJavaScriptEnabled(true);
      webView.loadUrl(""+ data);

接下来,在 AndroidManifest.xml 中使用这段代码,它的所有链接(Https / Http):

        <intent-filter android:autoVerify="true">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
             <data android:scheme="https"/>
            <data android:scheme="http"
                android:host="http://allaboutcity.in"
                android:pathPrefix="/allaboutcity" />
            <data android:host="www.host.com" android:pathPattern="/movie/0.*/" android:scheme="http"/>
        </intent-filter>

【讨论】:

    猜你喜欢
    • 2017-09-15
    • 1970-01-01
    • 1970-01-01
    • 2017-11-07
    • 2019-05-31
    • 1970-01-01
    • 2020-01-08
    • 2020-08-19
    • 1970-01-01
    相关资源
    最近更新 更多