Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Android获取url_Android_Android Intent - Fatal编程技术网

使用Android获取url

使用Android获取url,android,android-intent,Android,Android Intent,我正在尝试获取为打开应用程序而单击的URL。我只是很难找到我能从哪里得到这些信息。我有一个清单,点击时打开应用程序。链接将是“”,我正试图将其交给要处理的应用程序 <intent-filter> <data android:scheme="http" android:host="host.com" android:pathPrefix="/file.html" />

我正在尝试获取为打开应用程序而单击的URL。我只是很难找到我能从哪里得到这些信息。我有一个清单,点击时打开应用程序。链接将是“”,我正试图将其交给要处理的应用程序

 <intent-filter>
           <data android:scheme="http"
                android:host="host.com" 
                android:pathPrefix="/file.html" />
          <action android:name="android.intent.action.VIEW" />
          <category android:name="android.intent.category.BROWSABLE" />
          <category android:name="android.intent.category.DEFAULT" />
 </intent-filter>

您应该能够通过以下方式获得活动中的意图数据:

Uri uri = this.getIntent().getData();
URL url = new URL(uri.getScheme(), uri.getHost(), uri.getPath());

你必须用try/catch来包围

基本上,一旦获得Uri(即,
getIntent().getData()
),就可以将完整的url读取为
Uri.toString()
。假设您的
android:host
有效并已设置,您还可以通过调用
uri.getEncodedQuery()
来获取实际的查询数据

如果需要,以下是工作示例中的更多详细信息:

  • 这是我的清单设置:
  • 假设用户单击了url“”
    uri.toString()
    products“”,并且
    uri.getEncodedQuery()
    products“ll=43.455095,44.177416”

  • 希望有帮助

    我将当前的OnCreate方法添加到顶部。但似乎仍然不起作用。我的onCreate方法似乎没有被调用,据我所知,它将在系统调用onCreate时被调用,并通过重写它重定向到我创建的onCreate。
    Uri uri = this.getIntent().getData();
    URL url = new URL(uri.getScheme(), uri.getHost(), uri.getPath());
    
    Uri uri = this.getIntent().getData();
        try
        {
            URL url = new URL(uri.getScheme(), uri.getHost(), uri.getPath());
        }
        catch (MalformedURLException e)
        {
    
        }      
    
                <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="boo.acme.com"
                        android:scheme="http" />
                </intent-filter>
    
    Uri uri = this.getIntent().getData();