안드로이드 프로그래밍 초보입니다.

안드로이드 프로그래밍 및 애드몹을 시작하면서 자료를 남기고자 합니다.

 

https://developers.google.com/admob/android/quick-start

 

시작하기  |  Android  |  Google Developers

Android 앱을 제작 중인 Google AdMob 게시자를 위한 모바일 광고 SDK입니다.

developers.google.com

구글 애드몹을 시작할 때 안드로이드에 필요한 광고 안내 자료가 있습니다.

 

Get Started (시작하기)

 

This guide is for publishers who want to monetize an Android app with AdMob and aren't using Firebase. If you plan to include Firebase in your app (or you're considering it), see the AdMob with Firebase version of this guide instead.

이 가이드는 파이어베이스없이 안드로이드 앱과 애드몹과 연결하여 수익을 얻으려는 개발자를 위하 것이다. 만일 당신이 당신의 앱에 파이어페이스를 포함할 계확이라면(고려중이라면) 파이어베이스와 연동된 애드몹(AdMob with Firebase) 설명서를 보라

 

Integrating the Google Mobile Ads SDK into an app is the first step toward displaying ads and earning revenue. Once you've integrated the SDK, you can choose an ad format (such as native or rewarded video) and follow the steps to implement it.

광고를 보이고 수익을 얻는 첫걸음은 앱에 구글 모바일 광고 sdk를 결합하는 것이다. 만일 당신이 sdk를 결합했다면 당신은 광고의 규격을 고르고 그 구현방법을 따라야 한다.

 

https://youtu.be/kSh8-quhFHM

 

Prerequisites  선결조건

  • Use Android Studio 3.2 or later 안드로이드 스튜디오 3.2 이상을 사용할 것
  • minSdkVersion 16 or later 
  • compileSdkVersion 28 or later

Import the Mobile Ads SDK

Note: You should begin with a new project in Android Studio and check the box to Use AndroidX Artifacts or refer to Migrating to AndroidX to migrate your project.

 

당신이 새로운 안드로이드 프로젝트를 시작한다면 Use AndroidX Artifacts를 선택하거나 당신의 프로젝트를 AndroidX로 전환하는 것을 찾아보라 => 이전 버전의 안드로이드 스튜디오에는 프로젝트를 생성할 때 체크 박스가 있었던 것으로 기억하는데 지금은 없어졌네요. 신경쓸 필요가 없지요.

 

Apps can import the Google Mobile Ads SDK with a Gradle dependency that points to Google's Maven repository. First, make sure that google() is referenced in the allprojects section of your project-level build.gradle file.

google()을 모든 프로젝트에서 참조하는 것을 확실합니다. 

 

Example project-level build.gradle (excerpt) 프로젝트 레벨의 build.gradle에서 수행

allprojects {
    repositories
{
        google
()
   
}
} => 기본으로 설정되어있습니다.

 

Next, open the app-level build.gradle file for your app, and look for a "dependencies" section.

Example app-level build.gradle (excerpt) 해당 앱 레벨의 build.gradle에서 수행

dependencies {
    implementation fileTree
(dir: 'libs', include: ['*.jar'])
    implementation
'androidx.appcompat:appcompat:1.0.2'

implementation 'com.google.android.gms:play-services-ads:19.0.1'  => 복사할 부분
}

Add the line in bold above, which instruct Gradle to pull in the latest version of the Mobile Ads SDK and additional related dependencies. Once that's done, save the file and perform a Gradle sync.

위에서 굵은 글자의 라인을 추가하라. 그것은 Gradle에게 최신 모바일 광고 SDK를 끌어당기게하고 관련된 의존성을 더할 것이다.  그것이 완료되면 파일을 저장하고 Gradle의 sync를 수행하라.

Update your AndroidManifest.xml

Add your AdMob App ID to your app's AndroidManifest.xml file by adding a <meta-data> tag with name com.google.android.gms.ads.APPLICATION_ID, as shown below.

You can find your App ID in the AdMob UI. For android:value insert your own AdMob App ID in quotes, as shown below.

<manifest>
   
<application>
       
<!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
       
<meta-data
           
android:name="com.google.android.gms.ads.APPLICATION_ID"
           
android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>

   
</application>
</manifest>  

 

Important: This step is required as of Google Mobile Ads SDK version 17.0.0. Failure to add this <meta-data> tag results in a crash with the message: The Google Mobile Ads SDK was initialized incorrectly.

중요: 이 단계에서는 google mobile Ads SDK 17.0.0버젼이 필요하다. 만일 meta-data 태그를 추가하는데 실패하면 다음과 같은 메시지가 나온다. "구글 모바일 ads sdk는 부적절하게 초기화 되었습니다."

Initialize Mobile Ads SDK

Before loading ads, have your app initialize the Mobile Ads SDK by calling MobileAds.initialize() which initializes the SDK and calls back a completion listener once initialization is complete (or after a 30-second timeout). This needs to be done only once, ideally at app launch.

Warning: Ads may be preloaded by the Mobile Ads SDK or mediation partner SDKs upon calling MobileAds.initialize(). If you need to obtain consent from users in the European Economic Area (EEA), set any request-specific flags (such as tagForChildDirectedTreatment or tag_for_under_age_of_consent), or otherwise take action before loading ads, ensure you do so before initializing the Mobile Ads SDK.

Here's an example of how to call the initialize() method in an Activity:

Example MainActivity (excerpt)

JavaKotlin

package ...
import ...
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;

public class MainActivity extends AppCompatActivity {

   
protected void onCreate(Bundle savedInstanceState) {
       
super.onCreate(savedInstanceState);
        setContentView
(R.layout.activity_main);

       
MobileAds.initialize(this, new OnInitializationCompleteListener() {
           
@Override
           
public void onInitializationComplete(InitializationStatus initializationStatus) {
           
}
       
});
   
}
}

 

If you're using mediation, wait until the completion handler is called before loading ads, as this will ensure that all mediation adapters are initialized.

Select an ad format

The Mobile Ads SDK is now imported and you're ready to implement an ad. AdMob offers a number of different ad formats, so you can choose the one that best fits your app's user experience.

String input="5.2", output;

Double ans = 0;

 

ans=Double.parseDouble(input);

//if input is not String type, it throws NumberFormatException error

//만일 input이 String Type이 아니면 NumberFormatExecption error를 발생시킨다.

//if input is null, it throws NullpointException error

//만일 input이 Null이면 NullpointException error를 발생시킨다.

함수는 Double형을 반환한다.

 

output=Double.toString(ans*2);

//ans*2의 값을 ASCII의 형태의 문자열로 반환한다.

 

Toast.makeText(MainActivity.this, output, Toast.LENGTH_SHORT).show();

//안드로이드에서 간단한 문자열(output)로 화면에 표시

 

10.4

 

 

+ Recent posts