我有引用Android app带有admob横幅模板,但我不知道如何将插页式广告adob整合到这个项目中。带有sqlite数据库的模板。
这里是MainActivity.java的代码
package com.XXXX.MYpackage;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.SystemClock;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.TextView;
import com.XXXX.MYpackage.R;
import com.XXXX.MYpackage.activity.AbstractContentActivity;
import com.XXXX.MYpackage.activity.FavouristList;
import com.XXXX.MYpackage.activity.QuoteList;
import com.XXXX.MYpackage.activity.SearchActivity;
import com.XXXX.MYpackage.activity.SettingActivity;
import com.XXXX.MYpackage.db.DataHeper;
import com.XXXX.MYpackage.db.entity.QOD;
import com.XXXX.MYpackage.utils.CustomSharePreferences;
import com.XXXX.MYpackage.utils.WriteLog;
public class MainActivity extends AbstractContentActivity{
private ImageButton btn_author;
private ImageButton btn_quotes;
private ImageButton btn_fav;
private ImageButton btn_facebook;
private ImageButton btn_search;
final static int AUTHORIZE_ACTIVITY_RESULT_CODE = 10;
private DataHeper dataHeper;
private TextView tv_body;
private PendingIntent mAlarmSender;
@Override
protected void initView() {
// TODO Auto-generated method stub
super.initView();
CustomSharePreferences sharePreferences = new
CustomSharePreferences(getApplicationContext());`
btn_author = (ImageButton)findViewById(R.id.d_authors_btn);
btn_quotes = (ImageButton)findViewById(R.id.d_quotes_btn);
btn_fav = (ImageButton)findViewById(R.id.d_favs_btn);
tv_body = (TextView)findViewById(R.id.d_qod_body);
btn_facebook = (ImageButton)findViewById(R.id.actionbar_facebook_btn);
btn_search = (ImageButton)findViewById(R.id.actionbar_search_btn);
dataHeper = new DataHeper(getApplicationContext());
btn_author.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
WriteLog.d("ThangTB", "onclick image");
Intent i = new Intent(getApplicationContext(), SettingActivity.class);
startActivity(i);
}
});
btn_quotes.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
WriteLog.d("ThangTB", "onclick image");
Intent i = new Intent(getApplicationContext(), QuoteList.class);
startActivity(i);
}
});
btn_fav.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
WriteLog.d("ThangTB", "onclick image");
Intent i = new Intent(getApplicationContext(), FavouristList.class);
startActivity(i);
}
});
btn_facebook.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
facebook();
}
});
btn_search.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intentSearch = new Intent(getApplicationContext(), SearchActivity.class);
startActivity(intentSearch);
}
});
mAlarmSender = PendingIntent.getService(MainActivity.this,
0, new Intent(MainActivity.this, AlarmService_Service.class), 0);
// We want the alarm to go off 30 seconds from now.
long firstTime = SystemClock.elapsedRealtime();
// Schedule the alarm!
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,firstTime, 30*1000, mAlarmSender);
}
@Override
protected int getViewLayoutId() {
// TODO Auto-generated method stub
return R.layout.dashboard;
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
new GetData().execute();
super.onResume();
}
private class GetData extends AsyncTask<Object, Object, Object>{
private QOD quoteOfDay;
public GetData() {
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Object doInBackground(Object... params) {
// TODO Auto-generated method stub
quoteOfDay = dataHeper.getQOD();
return null;
}
@Override
protected void onPostExecute(Object result) {
if (quoteOfDay!=null) {
tv_body.setText(Html.fromHtml(quoteOfDay.getBody()));
}
super.onPostExecute(result);
}
}
public void facebook() {
Uri localUri = Uri.parse(getResources().getString(R.string.facebook_fanpage));
Intent localIntent = new Intent("android.intent.action.VIEW", localUri);
startActivity(localIntent);
}
}
以下是一些来自admob banner(quotepreview.xml)的xml代码和其他使用相同代码的xml代码 - 我认为这只代码为admob banner。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:orientation="vertical" android:id="@id/qp_main_parent"
android:background="@drawable/bg_default" android:clickable="true"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:orientation="vertical" android:id="@id/widget99"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:id="@id/ad_holder" style="@style/AdHolder" />
<RelativeLayout android:background="@drawable/actionbar_bg"
android:paddingRight="5.0dip" android:layout_width="fill_parent"
android:layout_height="48.0dip"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads">
<com.google.ads.AdViewandroid:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="k15XXX"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR,xxx2xxxx"
ads:loadAdOnCreate="true"/>
</RelativeLayout>
<ImageViewandroid:background="@drawable/dashboard_bar_shadow"android:layout_width=
"fill_parent"android:layout_height="6.0dip"/>
</LinearLayout>
<ScrollViewandroid:id="@id/qp_body_wrapper"android:clickable="true"
android:layout_width="fill_parent"android:layout_height="fill_parent"android:
layout_marginTop="10.0dip"android:layout_above="@id/widget34"android:layout_below
="@id/widget99">
<LinearLayoutandroid:orientation="vertical"android:id="@id/qp_body_
wrapper_container"android:clickable="true"android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextViewandroid:textSize="18.0dip"android:gravity="left"android:id="@id/qp_body"
android:padding="10.0dip"android:clickable="true"android:layout_width=
"fill_parent"android:layout_height="wrap_content"style="@style/QuoteViewText"/>
</LinearLayout>
</ScrollView>
<LinearLayoutandroid:gravity="center"android:orientation="horizontal"android:id=
"@id/widget34"android:layout_width="fill_parent"android:layout_height=
"wrap_content"android:layout_alignParentBottom="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<Buttonandroid:id="@id/qp_previous_btn"android:background="@drawable/
state_left_arrow"android:layout_width="48.0dip"android:layout_height=
"48.0dip"android:layout_margin="12.0dip"/>
<Buttonandroid:id="@id/qp_random_btn"android:background="@drawable/state_
refresh_btn"android:layout_width="48.0dip"android:layout_height="48.0dip"
android:layout_margin="12.0dip"/>
<Buttonandroid:id="@id/qp_favourite"android:background="@drawable/
qp_fav_btn_normal"android:layout_width="48.0dip"android:layout_height=
"48.0dip"android:layout_margin="12.0dip"/>
<Buttonandroid:id="@id/qp_next_btn"android:background="@drawable/
state_right_arrow"android:layout_width="48.0dip"android:layout_height=
"48.0dip"android:layout_margin="12.0dip"/>
</LinearLayout>
</RelativeLayout>
以下是AndroidManifest.xml中的代码
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.XXXX.MYpackage"
android:versionCode="1"
android:versionName="1" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.CustomDark" >
<activity
android:name=".SplashActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar"
android:screenOrientation="portrait"> >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.XXXX.MYpackage.Widget" android:label="@string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/widget_generic" />
</receiver>
<service android:name="com.XXXX.MYpackage.AlarmService_Service"
android:process=":remote" />
<activity android:name=".MainActivity" android:screenOrientation="portrait"></activity>
<activity android:name=".activity.AuthorList" android:screenOrientation="portrait">>
</activity>
<activity android:name=".activity.AuthorQuoteList"
android:screenOrientation="portrait"></activity>
<activity android:name=".activity.QuoteView" android:screenOrientation="portrait">
</activity>
<activity android:name=".activity.QuoteList" android:screenOrientation="portrait">
</activity>
<activity android:name=".activity.FavouristList" android:screenOrientation="portrait">
</activity>
<activity android:name=".activity.CategoryList" android:screenOrientation="portrait">
</activity>
<activity android:name=".activity.FilterList" android:screenOrientation="portrait">
</activity>
<activity android:name=".activity.CategoryQuoteList"
android:screenOrientation="portrait"></activity>
<activity android:name=".activity.SearchActivity" android:screenOrientation="portrait">
</activity>
<activity android:name=".activity.HelpActivity" android:screenOrientation="portrait">
</activity>
<activity android:name=".activity.SettingActivity"
android:screenOrientation="portrait"></activity>
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|
screenSize|smallestScreenSize"/>
</application>
</manifest>
请帮我整合admob interstitial。谢谢
答案 0 :(得分:0)
您不需要任何额外的布局或Manifest配置来集成插页式广告,但您需要添加少量代码。
请参阅https://developers.google.com/mobile-ads-sdk/docs/admob/advanced