简体   繁体   English

如何通过Android中的浏览器打开已安装的Android应用程序?

[英]How to open installed android application via browser in android?

I want to make my app to get opened when user enters particular url in the browser like chrome or internet.For this i have referred and googled about this topic what i noticed is similar and i have used in my manifest file but still doesnt work. 我想让我的应用程序在用户在浏览器中输入特定的URL(例如chrome或internet)时打开。为此,我已经提及并用谷歌搜索了这个主题,我发现这是相似的,并且我在清单文件中使用过但仍然无法正常工作。 i have referred below links for my issue 我已经在下面提到了我的问题的链接

Launching custom Android application from Android browser / Chrome 从Android浏览器/ Chrome启动自定义Android应用程序

Launch custom android application from android browser 从android浏览器启动自定义android应用程序

How to open android application when an URL is clicked in the browser 在浏览器中单击URL时如何打开android应用程序

Intercepting links from the browser to open my Android app 拦截来自浏览器的链接以打开我的Android应用

All this have same answer but when i use this it has no effect,when i type url www.myurl.co.gdf or http://www.myurl.co.gdf it doesnt prompt the user it opens in browser itself instead of opening myapp or showing choose dialog box 所有这些都有相同的答案,但是当我使用它时,当我键入url www.myurl.co.gdf或http://www.myurl.co.gdf时,它没有任何作用,它不会提示用户在浏览器本身而不是浏览器中打开打开myapp或显示选择对话框

the code i have used in manifest file is as follows 我在清单文件中使用的代码如下

<application
android:icon="@drawable/logo"
android:label="@string/app" >
<activity
    android:name="com.app.secondActivity"
    android:configChanges="orientation|keyboardHidden"
    android:label="@string/service"
    android:screenOrientation="portrait"
    android:theme="@style/aa_theme" >
              <intent-filter android:label="@string/app" >
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
       <intent-filter>
    <data
        android:host="www.myurl.co.gdf"
        android:pathPrefix="/"
        android:scheme="http" >
    </data>

    <action android:name="android.intent.action.VIEW" />

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

 <activity
    android:name="com.app.firstActivity"
    android:configChanges="orientation|keyboardHidden"
    android:label="@string/activity_title"
    android:screenOrientation="portrait"
    android:theme="@style/aa_theme" />
</application>

If this works fine for others why not for me? 如果这对其他人有用,为什么对我不呢? Note:i have changed to above code only in manifest and i have not changed or added any thing extra in .java files or anyother files. 注意:我仅在清单中更改了以上代码,并且没有更改或添加任何.java文件或其他文件中的其他内容。

For this to work should i make any device setting changes or should i add Uri intentUri = getIntent().getData(); 为此,我应该对设备设置进行任何更改,还是应该添加Uri intentUri = getIntent()。getData(); in .java file (should use then why?)or should i type differently in browser or have i used intentfilter in wrong activity or is there anything i am missing? 在.java文件中(应该使用然后为什么?),或者我应该在浏览器中键入不同的内容?还是我在错误的活动中使用了intentfilter,或者我缺少什么?

one more thing i am using some cordova plugins to this app, i dont think this has to do with opening an app. 我在此应用程序中使用了一些cordova插件,我认为这与打开应用程序无关。

I am very new to android please give me some ideas regarding this.. 我对android非常陌生,请给我一些有关此的想法。

The issue isn't with your code- it is with your testing strategy. 问题不在于您的代码,而在于您的测试策略。

Typing a URL in a browser does not typically start an Intent , and thus Android doesn't check to see if any other apps can handle the URL. 在浏览器中键入URL通常不会启动Intent ,因此Android不会检查是否有其他应用程序可以处理该URL。 When a user types a link into Chrome, for example, Chrome assumes that the user wants to continue using Chrome and will handle browsing to the URL itself. 例如,当用户在Chrome中输入链接时,Chrome会假定该用户希望继续使用Chrome,并会处理对URL本身的浏览。

Instead, you need to create an intent containing your URL to test if Android will handle deep links to your application correctly. 相反,您需要创建一个包含URL的意图,以测试Android是否将正确处理到您应用程序的深层链接。

The easiest way to do so is via the following ADB command: 最简单的方法是通过以下ADB命令:

adb shell am start
    -W -a android.intent.action.VIEW
    -d http://www.myurl.co.gdf/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM