GettingSignals

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

2012年9月7日
Posted by hina

とあるアプリをタブレット対応したので、ついでに広告処理もFragment実装してみました。

使用したアドネットワークは、nendさん。
https://www.nend.net/

libsフォルダにnendSDK-1.2.1.jarを格納し、ビルドパスに追加

AndroidManifest.xml

    <uses-permission android:name=”android.permission.INTERNET”/>
    <uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE”/>

追記。

main.xml
<?xml version=”1.0″ encoding=”utf-8″?> <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.sample.package.NendFragment”
   android:layout_width=”fill_parent”
   android:layout_height=”wrap_content”
   />

</RelativeLayout>
NendFragment.java
public class NendFragment extends Fragment implements NendAdListener {  
private static final int SPOT_ID = ****** 発行されたSPOT ID ******;
private static final String API_KEY = “******** 発行されたAPI KEY *********”;
public NendFragment() {
}
    
    @Override  
    public View onCreateView(LayoutInflater inflater,  
            ViewGroup container, Bundle savedInstanceState) {  
        
    NendAdView adView = new NendAdView(getActivity().getApplicationContext(), SPOT_ID, API_KEY);
    adView.setListener(this);
return adView;
    }
@Override
public void onFailedToReceiveAd(NendAdView arg0) {
}
@Override
public void onReceiveAd(NendAdView arg0) {
}
}
Fragment化しておけば、レイアウトファイルに追加するだけでいいから便利ですねー。
Share

Comments are currently closed.

Follow

カレンダー

2024年4月
1234567
891011121314
15161718192021
22232425262728
2930