[android] 안드로이드 브라우저에서 사용자 정의 안드로이드 응용 프로그램을 실행

안드로이드 브라우저에서 내 안드로이드 응용 프로그램을 시작하는 방법에 대해 아무도 나를 안내 할 수 있습니까?



답변

<intent-filter>와 함께 <data>요소를 사용하십시오 . 예를 들어, twitter.com에 대한 모든 링크를 처리하려면 다음과 같이 안에 넣으 <activity>십시오 AndroidManifest.xml.

<intent-filter>
    <data android:scheme="http" android:host="twitter.com"/>
    <action android:name="android.intent.action.VIEW" />
</intent-filter>

그런 다음 사용자가 브라우저에서 트위터 링크를 클릭하면 작업을 완료하기 위해 사용할 애플리케이션 (브라우저 또는 애플리케이션)이 표시됩니다.

물론 웹 사이트와 앱을 긴밀하게 통합하려는 경우 고유 한 체계를 정의 할 수 있습니다.

<intent-filter>
    <data android:scheme="my.special.scheme" />
    <action android:name="android.intent.action.VIEW" />
</intent-filter>

그런 다음 웹 앱에서 다음과 같은 링크를 넣을 수 있습니다.

<a href="my.special.scheme://other/parameters/here">

사용자가 클릭하면 앱이 자동으로 시작됩니다 (아마도 my.special.scheme://uri 유형을 처리 할 수있는 유일한 앱이기 때문에 ). 이것의 유일한 단점은 사용자가 앱을 설치하지 않으면 심한 오류가 발생한다는 것입니다. 확인할 방법이 확실하지 않습니다.


편집 : 질문에 대답하기 getIntent().getData()위해 Uri객체 를 반환하는 것을 사용할 수 있습니다 . 그런 다음 Uri.*메소드를 사용하여 필요한 데이터를 추출 할 수 있습니다 . 예를 들어 사용자가 다음 링크를 클릭했다고 가정 해 보겠습니다 http://twitter.com/status/1234.

Uri data = getIntent().getData();
String scheme = data.getScheme(); // "http"
String host = data.getHost(); // "twitter.com"
List<String> params = data.getPathSegments();
String first = params.get(0); // "status"
String second = params.get(1); // "1234"

의 어느 곳에서나 위의 작업을 수행 할 수 Activity있지만에서 할 수도 있습니다 onCreate(). params.size()에서 경로 세그먼트 수를 얻는 데 사용할 수도 있습니다 Uri. Uri특정 부분을 추출하는 데 사용할 수있는 다른 방법 은 javadoc 또는 Android 개발자 웹 사이트를 참조하십시오 .


답변

CHROME2014 년 1 월 28 일 현재 위의 모든 답변이 작동하지 않았습니다.

내 앱은 행 아웃, Gmail 등의 앱의 http://example.com/someresource/ 링크에서 제대로 시작 되었지만 크롬 브라우저에는 없습니다.

이 문제를 해결하려면 CHROME에서 올바르게 시작되도록 인 텐트 필터를 다음과 같이 설정해야합니다

<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="example.com"
        android:pathPrefix="/someresource/"
        android:scheme="http" />
    <data
        android:host="www.example.com"
        android:pathPrefix="/someresource/"
        android:scheme="http" />
</intent-filter>

pathPrefix요소에 주목

사용자가 Google 검색 결과 또는 다른 웹 사이트의 링크를 클릭하여 크롬 브라우저에서 http://example.com/someresource/ 패턴을 요청할 때마다 앱이 활동 선택기 내에 나타납니다.


답변

여기 내 의견을 참조하십시오 : Android 브라우저에서 링크를 만들어 내 앱을 시작합니까?

새로운 인터넷 방식을 정의하지 않는 한 사람들이 자신의 방식을 사용하지 않는 것이 좋습니다.


답변

내 경우에는 두 가지 범주를 설정해야했고 효과가있었습니다 <intent-filter>.

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


답변

예를 들어 다음과 같은 것이 있습니다.

앱을 여는 링크 : http://example.com

앱의 패키지 이름 : com.example.mypackage

그런 다음 다음을 수행해야합니다.

1) 활동에 인 텐트 필터를 추가하십시오 (원하는 활동이 될 수 있습니다. 자세한 정보는 문서를 확인하십시오 ).

        <activity
        android:name=".MainActivity">

        <intent-filter android:label="@string/filter_title_view_app_from_web">
            <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 "http://example.com" -->

            <data
                android:host="example.com"
                android:scheme="http" />
        </intent-filter>

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

    </activity> 

2) 링크를 테스트 하거나이 방법을 사용할 HTML 파일을 작성하십시오 .

<a href="intent://example.com#Intent;scheme=http;package=com.example.mypackage;end">Open your Activity directly (just open your Activity, without a choosing dialog). </a>

<a href="http://example.com">Open this link with browser or your programm (by choosing dialog).</a>

3) 모바일 Chrome을 사용하여 테스트

4) 끝입니다.

딥 링크를 테스트하기 위해 시장에 앱을 게시 할 필요는 없습니다 =)

또한 자세한 내용은 설명서 및 유용한 프레젠테이션을 확인하십시오 .


답변

도해야 <category android:name="android.intent.category.BROWSABLE"/>링크에서 올바르게 인식 활동을 확인하기 위해 텐트 필터에 추가됩니다.


답변

다음 링크는 브라우저에서 직접 앱을 설치 (설치된 경우)하는 방법에 대한 정보를 제공합니다. 그렇지 않으면 플레이 스토어에서 앱을 직접 열어 사용자가 원활하게 다운로드 할 수 있습니다.

https://developer.chrome.com/multidevice/android/intents