把自己的程式上架google play後
當然開點廣告賺收益囉
首先,先確認你有google play開發者帳號
再來申請ADMOD(寫基本資料很簡單~~
接著上廣告囉
參考網站: https://developers.google.com/admob/android/quick-start
若看不懂英文就看我說明吧~~~
先到你的 build.gradle(project) 確認有以下程式碼
allprojects { repositories { google() } }
到build.gradle(module)加入
dependencies { implementation 'com.google.android.gms:play-services-ads:18.3.0' }
到你的 AndroidManifest.xml加入你的廣告ID
<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>
接著到你的java頁面加入:
public class MainActivity extends AppCompatActivity { private ADView madView; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); MobileAds.initialize(this, new OnInitializationCompleteListener() { @Override public void onInitializationComplete(InitializationStatus initializationStatus) { } }); } }
在java頁面中在加入(以下以banner為例)
String myid=getString(R.string.appid);
MobileAds.initialize(this, myid);
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
mAdView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
}
@Override
public void onAdOpened() {
// Code to be executed when an ad opens an overlay that
// covers the screen.
}
});
以上
就大功告成啦~~~~
文章標籤
全站熱搜
留言列表