【问题标题】:URL scheme not working in android browserURL方案在Android浏览器中不起作用
【发布时间】:2014-04-22 03:39:43
【问题描述】:

我需要在单击链接时打开我的应用程序。为此,我读到我必须使用 URL 方案。该链接的格式必须为 myapp://parameters。

我阅读了有关此主题的所有帖子,但是当我发送一封带有“myapp://addUser/?id=22”的电子邮件并从 chrome(在我的手机上)打开时,它无法点击。

我的清单:

 <activity
            android:name="com.example.SplashActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <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:scheme="myapp" android:host="com.example"/>
            </intent-filter>

        </activity>

我的班级:

公共类 SplashActivity 扩展 FragmentActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_splash);
    Intent intent = getIntent();

    if (Intent.ACTION_VIEW.equals(intent.getAction())) {
        Uri uri = intent.getData();
        String id = uri.getQueryParameter("id"); 
    }

}

测试代码的邮件内容:

myapp://addUser/?id=22

参考链接:

Make a link in the Android browser start up my app?

How to register some URL namespace (myapp://app.start/) for accessing your program by calling a URL in browser in Android OS?

https://legacy.madewithmarmalade.com/devnet/forum/custom-url-scheme-primarily-android-3

更新

我认为问题在于邮件正文,但我不知道如何测试。

【问题讨论】:

    标签: android url-scheme


    【解决方案1】:

    我在这里做了一个测试,在清单文件中我刚刚删除了“android:host”参数,留下了这个:

    <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="myapp" />
    </intent-filter>
    

    它在这里打开了一个 URL myapp://testing,我放了一个简单的 HTML 文件,只是为了尝试。

    【讨论】:

      【解决方案2】:

      在您的清单中

          <action android:name="android.intent.action.VIEW" />
              <category android:name="android.intent.category.DEFAULT" />
              <category android:name="android.intent.category.BROWSABLE" />
              <data android:scheme="myapp" android:host="com.example"/>
          </intent-filter>
      

      你定义了 android:host="com.example",所以你应该修改链接 URL:

      myapp://addUser/?id=22       //error
      myapp://com.example/?id=22   //correct
      

      那么它就可以工作了!!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-10-28
        • 1970-01-01
        • 1970-01-01
        • 2014-10-13
        • 2016-11-21
        • 2012-06-12
        • 1970-01-01
        相关资源
        最近更新 更多