Advertisement
  1. Code
  2. Android SDK

구글을 위한 모바일 애플리케이션 최적화

Scroll to top
Read Time: 6 min

Korean (한국어) translation by Dae-yeop Lee (you can also view the original English article)

Final product imageFinal product imageFinal product image
What You'll Be Creating

구글로 웹을 검색할 때 검색 결과에 앱을 가리키는 신비한 링크가 어떻게 표시되는지 궁금한 적이 있습니까? 앱 개발자는 어떻게 앱을 이곳에 표시할 수 있을까요?

이번 튜토리얼에서는 앱에 이 효과를 주는 방법을 보여드리겠습니다.

1. 앱 인덱싱이란?

구글 앱 인덱싱(이제 파이어베이스 앱 인덱싱으로 바뀜)을 이용하면 일반 웹 페이지처럼 네이티브 앱을 구글 검색 결과에 표시할 수 있습니다. 일반 웹 페이지 항목과 함께 표시되는 앱 항목은 적절한 검색어가 적절한 기기의 브라우저에서 제출될 경우 표시됩니다. 이 기능은 현재 안드로이드 및 iOS 플랫폼에서 지원됩니다.

왜 개발자에게는 이것이 필요할까요?

앱 인덱싱은 두 가지 중요한 작업을 동시에 수행하기 때문에 개발자의 성공 가능성을 극대화합니다.

첫째, 모바일 사용자 환경을 개선하고 향상시킵니다. 검색어와 관련된 앱이 발견되면 브라우저를 종료하지 않고도 앱을 설치하거나 앱을 직접 실행할 수 있습니다(이미 기기에 설치돼 있는 경우). 따라서 사용자는 이러한 앱에 대한 긍정적인 첫인상을 갖게 되며 앱이 올바른 맥락에서 표시될 수 있다는 사실에 무의식적으로 감사하고 고려해야 할 몇 가지 선택지를 제공받습니다.

둘째, 개발자가 구글의 검색 엔진을 통해 앱을 직접 홍보하는 데 이바지합니다. 개발자는 이 메커니즘을 활용해 트래픽을 앱으로 직접 유도하고 다운로드 횟수를 크게 늘릴 수 있습니다.

이것은 기술적으로 어떻게 가능할까요?

앱 인덱싱은 앱과 웹 사이트 사이의 관계를 수립하는 매우 단순하지만 영리한 방법으로 마술을 부립니다. 이름하야 "사이트 연동"이라고 하는 것입니다. 작업 흐름은 몇 가지 단계로 구성됩니다.

  1. URL과 구글 검색을 지원하기 위한 인텐트 필터 추가
  2. 웹 사이트와 앱을 연동
  3. 앱 인덱싱 API 코드를 추가

2. 직접 만들어 봅시다

이제 작업흐름에 대해 알아봤으니 각 단계를 진행하고 마지막으로 안드로이드 스튜디오에서 구현을 테스트하겠습니다. 그래서 여기서는 안드로이드 스튜디오 IDE에서 새로운 안드로이드 프로젝트를 만들겠습니다. 컴퓨터에 안드로이드 스튜디오 2.0 이상 버전이 설치돼 있어야합니다. 빈 액티비티가 포함된 새 안드로이드 프로젝트를 만듭니다. 저는 안드로이드 프로젝트의 이름으로 MyApp을 사용했습니다.

Create a new Project in Android StudioCreate a new Project in Android StudioCreate a new Project in Android Studio

1단계

먼저 URL과 구글 검색을 지원하기 위한 인텐트 필터를 추가하겠습니다. 인텐트는 안드로이드 앱 컴포넌트 사이에서 통신하는 에이전트이며, 인텐트 필터를 사용하는 것은 앱에 암시적 인텐트를 도입하는 표준 방법입니다.

앱 내의 암시적 인텐트는 운영체제가 일치하는 모든 등록된 컴포넌트(설치된 다른 앱의 컴포넌트까지도)를 평가하고 그중 하나를 선택하도록 요청함으로써 시스템에 설치된 다른 앱을 이용해 특정 작업을 수행할 수 있게 합니다. 이와 대조적으로 명시적 인텐트는 대상 앱 컴포넌트를 직접 지정하므로 지정된 컴포넌트만 해당 작업을 수행하도록 호출됩니다. 인텐트와 인텐트 필터에 대한 자세한 내용은 안드로이드 개발자 웹 사이트에서 확인할 수 있습니다.

이제 인텐트 필터를 작성해 보겠습니다.

  • AndroidManifest.xml 파일을 엽니다.
  • 커서로 <activity> 엘리먼트를 선택합니다.
  • 선택된 상태에서 마우스 오른쪽 버튼을 클릭한 다음 팝업 메뉴에서 Generate를 선택합니다.
  • 이어서 나타나는 팝업 메뉴에서 URL을 선택합니다.
Select Generate from the pop-up menuSelect Generate from the pop-up menuSelect Generate from the pop-up menu

안드로이드 스튜디오가 AndroidManifest.xml 파일에 몇 가지 코드를 추가한 것을 볼 수 있습니다. 여러분의 요구사항에 맞게 생성된 코드에서 <data> 엘리먼트의 속성을 변경할 수 있습니다. 제 경우에는 데모 웹 사이트와 관련된 값을 지정했습니다.

httphttps 체계에 필요한 값을 지정합니다.

1
<?xml version="1.0" encoding="utf-8"?>
2
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
    package="com.mycompany.myapp">
4
5
    <application
6
        android:allowBackup="true"
7
        android:icon="@mipmap/ic_launcher"
8
        android:label="@string/app_name"
9
        android:supportsRtl="true"
10
        android:theme="@style/AppTheme">
11
        <activity android:name=".MainActivity">
12
            <intent-filter>
13
                <action android:name="android.intent.action.MAIN" />
14
15
                <category android:name="android.intent.category.LAUNCHER" />
16
            </intent-filter><!-- ATTENTION: This intent was auto-generated. Follow instructions at

17
  https://g.co/AppIndexing/AndroidStudio to publish your URLs. -->
18
            <intent-filter>
19
                <action android:name="android.intent.action.VIEW" />
20
21
                <category android:name="android.intent.category.DEFAULT" />
22
                <category android:name="android.intent.category.BROWSABLE" />
23
                <!-- ATTENTION: This data URL was auto-generated. We recommend that you use the HTTP scheme.

24
                  TODO: Change the host or pathPrefix as necessary. -->
25
                
26
                <data
27
                    android:host="sites.google.com"
28
                    android:pathPrefix="/site/appindexingex/home/main"
29
                    android:scheme="http" />
30
                <data
31
                    android:host="sites.google.com"
32
                    android:pathPrefix="/site/appindexingex/home/main"
33
                    android:scheme="https" />
34
            </intent-filter>
35
        </activity><!-- ATTENTION: This was auto-generated to add Google Play services to your project for

36
     App Indexing.  See https://g.co/AppIndexing/AndroidStudio for more information. -->
37
        <meta-data
38
            android:name="com.google.android.gms.version"
39
            android:value="@integer/google_play_services_version" />
40
    </application>
41
42
</manifest>

2단계

이제 웹 사이트를 앱과 연동해야 합니다.

구글 검색 콘솔(Google Search Console)을 이용해 앱과 연동할 웹 URL을 확인해야 합니다. 구글 계정으로 검색 콘솔에 로그인하면 손쉽게 따라할 수 있는 URL 확인 절차를 확인할 수 있습니다.

또한 파이어베이스 앱 인덱싱 가이드(Firebase App Indexing Guide)에서 연동된 웹 사이트의 구조를 정의해서 앱의 구조와 일치시키는 방법에 대한 자세한 내용을 확인할 수 있습니다. 하지만 여기서는 안드로이드 스튜디오를 이용해 앱을 테스트하는 중이므로 이번 튜토리얼에서 이러한 세부 사항을 알아볼 필요는 없을 것입니다.

테스트를 위해서는 구글에서 확인한 실제 웹 URL만 있으면 됩니다. 1단계에서 <data> 엘리먼트에 지정한 속성은 확인된 웹 URL과 일치해야 하며, 완전하게 작동해야 합니다.

3단계

마지막으로 앱 인덱싱 API 코드를 추가하겠습니다. 안드로이드 스튜디오에서는 다음과 같은 자동화된 방법을 제공합니다.

  • 안드로이드 프로젝트의 MainActivity.java 파일을 엽니다.
  • 커서로 onCreate라는 단어를 선택합니다.
  • 선택된 상태에서 마우스 오른쪽 버튼을 클릭하고 팝업 메뉴에서 Generate를 선택합니다.
  • 이어서 나타나는 팝업 메뉴에서 App Indexing API Code를 선택합니다.
Select the App Indexing API Code from the secondary pop-up menuSelect the App Indexing API Code from the secondary pop-up menuSelect the App Indexing API Code from the secondary pop-up menu

안드로이드 스튜디오에서 MainActivity.java 파일에 추가한 자동 생성 코드를 볼 수 있을 것입니다. Uri.parse() 함수의 링크를 편집해서 앱과 연동된 URL을 올바르게 가리키게 합니다.

1
package com.mycompany.myapp;
2
3
import android.net.Uri;
4
import android.support.v7.app.AppCompatActivity;
5
import android.os.Bundle;
6
7
import com.google.android.gms.appindexing.Action;
8
import com.google.android.gms.appindexing.AppIndex;
9
import com.google.android.gms.common.api.GoogleApiClient;
10
11
public class MainActivity extends AppCompatActivity {
12
13
    /**

14
     * ATTENTION: This was auto-generated to implement the App Indexing API.

15
     * See https://g.co/AppIndexing/AndroidStudio for more information.

16
     */
17
    private GoogleApiClient client;
18
19
    @Override
20
    protected void onCreate(Bundle savedInstanceState) {
21
        super.onCreate(savedInstanceState);
22
        setContentView(R.layout.activity_main);
23
        // ATTENTION: This was auto-generated to implement the App Indexing API.

24
        // See https://g.co/AppIndexing/AndroidStudio for more information.

25
        client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
26
    }
27
28
    @Override
29
    public void onStart() {
30
        super.onStart();
31
32
        // ATTENTION: This was auto-generated to implement the App Indexing API.

33
        // See https://g.co/AppIndexing/AndroidStudio for more information.

34
        client.connect();
35
        Action viewAction = Action.newAction(
36
                Action.TYPE_VIEW, // TODO: choose an action type.

37
                "Main Page", // TODO: Define a title for the content shown.

38
                // TODO: If you have web page content that matches this app activity's content,

39
                // make sure this auto-generated web page URL is correct.

40
                // Otherwise, set the URL to null.

41
42
                
43
44
                Uri.parse("http://sites.google.com/site/appindexingex/home/main"),
45
                // TODO: Make sure this auto-generated app URL is correct.

46
                Uri.parse("android-app://com.mycompany.myapp/http/sites.google.com/site/appindexingex/home/main")
47
        );
48
        AppIndex.AppIndexApi.start(client, viewAction);
49
    }
50
51
    @Override
52
    public void onStop() {
53
        super.onStop();
54
55
        // ATTENTION: This was auto-generated to implement the App Indexing API.

56
        // See https://g.co/AppIndexing/AndroidStudio for more information.

57
        Action viewAction = Action.newAction(
58
                Action.TYPE_VIEW, // TODO: choose an action type.

59
                "Main Page", // TODO: Define a title for the content shown.

60
                // TODO: If you have web page content that matches this app activity's content,

61
                // make sure this auto-generated web page URL is correct.

62
                // Otherwise, set the URL to null.

63
64
65
                Uri.parse("http://sites.google.com/site/appindexingex/home/main"),
66
                // TODO: Make sure this auto-generated app URL is correct.

67
                Uri.parse("android-app://com.mycompany.myapp/http/sites.google.com/site/appindexingex/home/main")
68
        );
69
        AppIndex.AppIndexApi.end(client, viewAction);
70
        client.disconnect();
71
    }
72
}

3. 테스트

이제 앱 인덱싱 구현이 제대로 작동하는지 확인하기 위해 안드로이드 스튜디오에서 작업한 내용을 테스트해 보겠습니다. 먼저 인터넷에 연결돼 있는지 확인합니다. 그런 다음 안드로이드 스튜디오에서 Tools > Android > Google App Indexing Test를 선택합니다.

On Android Studio select Tools Android Google App Indexing TestOn Android Studio select Tools Android Google App Indexing TestOn Android Studio select Tools Android Google App Indexing Test

잠시 후 아래와 비슷한 화면이 나타납니다. 테스트를 통과한 결과를 통해 앱 인덱싱이 앱에서 올바르게 작동하는 것을 확인할 수 있습니다.

Test result screen showing test passedTest result screen showing test passedTest result screen showing test passed

결론

앱 인덱싱은 여러분의 앱을 더 많이 다운로드하도록 유도하는 데 유용한 기능이며, 개발자에게는 더욱 광범위한 사용자 기반을 타겟팅하는 데 크게 도움될 것입니다. 이 튜토리얼에서는 앱 인덱싱 구현이 올바르게 작동하는지만 확인하고 사용자가 구현의 결과로 얻은 기능을 정확히 어떻게 인식하는지는 확인하지 않았습니다. 파이어베이스, 구글 웹 마스터, 안드로이드 스튜디오 앱 인덱싱 도움말 웹 사이트에서 더 많은 정보를 찾아봄으로써 여러분은 다음 단계로 나아갈 수 있을 것입니다.

Advertisement
Did you find this post useful?
Want a weekly email summary?
Subscribe below and we’ll send you a weekly email summary of all new Code tutorials. Never miss out on learning about the next big thing.
Advertisement
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.