GettingSignals

[Android]広告(adstir)をFragment化してみた

2012年9月7日
Posted by hina

nendさんに続いて、お次はAdStirさんです。
http://ja.ad-stir.com/

AdStirさんは複数の広告ネットワークを自動で配分してくれます。

Android 2.xでも使えるように、Android Support Package v4使ってます。

libsフォルダadstir.jar を追加し、ビルドバスに追加

AndroidManifest.xml
<uses-permission android:name=”android.permission.INTERNET”/>
<uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE”/>
<application
 ・・・・>
   <meta-data android:name=”ADSTIR_APP_ID” android:value=”MEDIA-xxxxxxx” />
</application>

main.xml
<RelativeLayout
xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
>
<fragment
  android:id=”@+id/fragmentAd”
   android:name=”com.package.Sample.AdstirFragment”
   android:layout_width=”fill_parent”
   android:layout_height=”wrap_content”
   android:layout_alignParentBottom=”true”
   />
</RelativeLayout>
AdstirFragment.java
public class AdstirFragment extends Fragment {  
AdstirView adView;
public AdstirFragment() {
}
    
    @Override  
    public View onCreateView(LayoutInflater inflater,  
            ViewGroup container, Bundle savedInstanceState) {  
        
    adView = new AdstirView(getActivity(), 1);
return adView;
    }
    
    @Override
    public void onResume() {
   super.onResume();
   adView.start();
}
 
@Override
public void onPause() {
   super.onPause();
   adView.stop();
}

    @Override
    public void onDestroy() {
        super.onDestroy();
        new AdstirTerminate(getActivity());
    }

}
onResume() / onPause() でstart / stop の処理が必要。
これでいいのかな、Fragment使いこなすにはもう少しかかりそう。
Share

Comments are currently closed.

Follow

カレンダー

2024年3月
 123
45678910
11121314151617
18192021222324
25262728293031