如何将 android 应用程序添加到 Admob

how to add android application to Addmob

首先我已经阅读了所有这些链接: google developper, tutorial-1,google developper-2,tutorial-2

我做到了 following:GpsMapActivity(横幅 admob 应该在这里)(我没有在这里显示整个代码)

  public class GpsMapActivity extends android.support.v4.app.FragmentActivity implements OnMarkerClickListener, LocationListener,OnMapClickListener {

protected void onCreate(Bundle savedInstanceState) {

Tracker t = ((GoogleAnalyticsApp) getApplication()).getTracker(TrackerName.APP_TRACKER);
        t.setScreenName("Home");
        t.send(new HitBuilders.AppViewBuilder().build());
        t.enableAdvertisingIdCollection(true);
}
@Override
    protected void onStart() {
        // TODO Auto-generated method stub
        super.onStart();
        GoogleAnalytics.getInstance(GpsMapActivity.this).reportActivityStart(this);
    }


    @Override
    protected void onStop() {
        // TODO Auto-generated method stub
        super.onStop();
        GoogleAnalytics.getInstance(GpsMapActivity.this).reportActivityStop(this);
    }
}

GoogleAnalyticApplcation class

public class GoogleAnalyticsApp extends Application {

    private static final String PROPERTY_ID = "**my_admob_tracking_id_here";

    public static int GENERAL_TRACKER = 0;

    public enum TrackerName {
        APP_TRACKER, GLOBAL_TRACKER, ECOMMERCE_TRACKER,
    }

    public HashMap mTrackers = new HashMap();

    public GoogleAnalyticsApp() {
        super();
    }

    public synchronized Tracker getTracker(TrackerName appTracker) {
        if (!mTrackers.containsKey(appTracker)) {
            GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
            Tracker t = (appTracker == TrackerName.APP_TRACKER) ? analytics.newTracker(PROPERTY_ID) : (appTracker == TrackerName.GLOBAL_TRACKER) ? analytics.newTracker(R.xml.global_tracker) : analytics.newTracker(R.xml.ecommerce_tracker);
            mTrackers.put(appTracker, t);
        }
        return (Tracker) mTrackers.get(appTracker);//If I dont cast tracker //here eclipse gives error.In tutorial there is no cast
    }
}

res/xml files:app_tracker.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="ga_trackingId">**my_admob_tracking_id_here</string>

    <bool name="ga_autoActivityTracking">true</bool>
    <bool name="ga_reportUncaughtExceptions">true</bool>

    <string name="ga_appName">GoogleAnalyticsApp</string>
    <string name="ga_appVersion">1.1.3</string>

    <bool name="ga_debug">true</bool>

    <item name="ga_dispatchPeriod" format="integer" type="integer">120</item>

    <string name="ga_sampleFrequency">90</string>

    <bool name="ga_anonymizeIp">true</bool>
    <bool name="ga_dryRun">false</bool>

    <string name="ga_sampleFrequency">100.0</string>

    <integer name="ga_sessionTimeout">-1</integer>

    <string name="turkiye.yollari.trafikolaylari">GoogleAnalyticsApp</string>

</resources>

ecommerce_tracker.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <integer name="ga_sessionTimeout">60</integer>
    <string name="ga_trackingId">**my_admob_tracking_id_here</string>
</resources>

global_trackker.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <integer name="ga_sessionTimeout">300</integer>

    <!-- Enable automatic Activity measurement -->
    <bool name="ga_autoActivityTracking">true</bool>

    <!-- The screen names that will appear in reports -->
    <screenName name="turkiye.yollari.trafikolaylari.GpsMapActivity">
        GoogleAnalyticsApp ScreenViewSampleScreen
    </screenName>

    <!--  The following value should be replaced with correct property id. -->
    <string name="ga_trackingId">**my_admob_tracking_id_here</string>
</resources>

android_manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="turkiye.yollari.trafikolaylari"
    android:versionCode="1"
    android:versionName="1.0" >

     <permission
        android:name="com.example.socialnetworkatilimroads.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"></permission>
     <uses-permission
        android:name="com.example.socialnetworkatilimroads.permission.MAPS_RECEIVE"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission
        android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE"/>
    <uses-permission
        android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>

    <uses-permission
        android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>

    <uses-sdk
        android:minSdkVersion="17"
        android:targetSdkVersion="17" />

    <application

        android:clearTaskOnLaunch="true" 
        android:name=".GoogleAnalyticsApp"
        android:allowBackup="true"
        android:icon="@drawable/app_icon"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name="turkiye.yollari.trafikolaylari.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter> 
        </activity>
        <activity android:name="turkiye.yollari.trafikolaylari.RegisterationActivity" />
        <activity android:name="turkiye.yollari.trafikolaylari.RecoverPasswordActivity" />
        <activity android:name="turkiye.yollari.trafikolaylari.LoginActivity" />
        <activity android:name="turkiye.yollari.trafikolaylari.GpsMapActivity" />

        <activity android:name="turkiye.yollari.trafikolaylari.BannedActivity" />
        <activity android:name="turkiye.yollari.trafikolaylari.MyAccountActivity" />
        <activity android:name="turkiye.yollari.trafikolaylari.AnnouncementsActivity" />

        <uses-library android:name="com.google.android.maps" />
<meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />

<meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyAO2u35cPnPAve3KEjAzveQCd8PUxh2oPk" />
    </application>
</manifest>

我的应用程序没有崩溃,但横幅 admob 不是 shown.What 我不见了?

据我所知,您还没有在您的应用中添加任何与横幅广告有关的内容。上面引用的所有代码和链接都与分析有关,而不是广告。

您需要遵循以下步骤:https://developers.google.com/mobile-ads-sdk/docs/admob/android/quick-start