Android 如何在应用程序中添加mopub广告

Android 如何在应用程序中添加mopub广告,android,ads,mopub,Android,Ads,Mopub,我想在我的应用程序中添加广告横幅,我已经将mopub sdk与我的项目集成,并将库导入并添加到我的项目中,现在我的问题是如何添加横幅显示以及我必须在我的应用程序中编写的代码,关于广告的java代码和xml代码,请帮助enyone 下面给出了我的java代码和mainifest文件代码 mainactivity.java package com.example.ration; import android.app.Activity; import android.content.Intent;

我想在我的应用程序中添加广告横幅,我已经将mopub sdk与我的项目集成,并将库导入并添加到我的项目中,现在我的问题是如何添加横幅显示以及我必须在我的应用程序中编写的代码,关于广告的java代码和xml代码,请帮助enyone

下面给出了我的java代码和mainifest文件代码

mainactivity.java

package com.example.ration;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class MainActivity extends Activity {

    private WebView web;
    int k;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);



        web=(WebView)findViewById(R.id.web);
        web.getSettings().setJavaScriptEnabled(true);
        web.setWebViewClient(new WebViewClient());
        web.getSettings().setBuiltInZoomControls(true);
        web.loadUrl("http://dcs-dof.gujarat.gov.in/live-info.htm");
//        web.getProgress();


    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        menu.add(0,1,menu.NONE,"About");
        menu.add(0,2,menu.NONE,"Feedback");
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        int id=item.getItemId();
        if(id == 1)
        {

            Toast.makeText(MainActivity.this,"About",Toast.LENGTH_LONG).show();

            Intent i=new Intent(MainActivity.this,about.class);
            startActivity(i);
         }
        else {

            Toast.makeText(MainActivity.this,"Feedback",Toast.LENGTH_LONG).show();

            Intent i2 =new Intent(MainActivity.this,feedback.class);
            startActivity(i2);
        }
        return super.onOptionsItemSelected(item);
    }


    private boolean doubleBackToExitPressedOnce = false;

    @Override
    protected void onResume() {
        super.onResume();
        // .... other stuff in my onResume ....
        this.doubleBackToExitPressedOnce = false;
    }

    @Override
    public void onBackPressed() {
        if (doubleBackToExitPressedOnce) {
            super.onBackPressed();
            return;
        }
        this.doubleBackToExitPressedOnce = true;
        Toast.makeText(this,"Press Again to Exit", Toast.LENGTH_SHORT).show();
    }
    } 
我的清单文件是

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

    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.ration.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="com.example.ration.about"></activity>
        <activity android:name="com.example.ration.feedback"></activity>
        <activity android:name="com.mopub.mobileads.MoPubActivity" android:configChanges="keyboardHidden|orientation"/>
        <activity android:name="com.mopub.mobileads.MraidActivity" android:configChanges="keyboardHidden|orientation"/>
        <activity android:name="com.mopub.mobileads.MraidBrowser" android:configChanges="keyboardHidden|orientation"/>
        <activity android:name="com.mopub.mobileads.MraidVideoPlayerActivity" android:configChanges="keyboardHidden|orientation"/>
        <activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
        <activity android:name="com.millennialmedia.android.MMActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:configChanges="keyboardHidden|orientation|keyboard" />
        <activity android:name="com.millennialmedia.android.VideoPlayer" android:configChanges="keyboardHidden|orientation|keyboard" />
    </application>

</manifest>

我认为您最好仔细阅读本指南,其中解释了横幅广告整合的步骤

希望这对你有帮助

在XML文件中使用视图

        <com.mopub.mobileads.MoPubView
        android:id="@+id/mrect_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center_horizontal"
        android:layout_weight="1" />

你好,伙计…我提到了它,但我对这个代码有点困惑@PranavLathigara你的困惑是什么?关于横幅代码的困惑在哪里?在活动\u main中准确地写它,如果有,那么我的布局将受到干扰…?你怎么能说你的布局会受到干扰?你有没有想过在你的版面中要把广告放在哪里@PranavLathigaraI希望在应用程序开始时显示它…如果您有示例,请发送给我…非常感谢
           public void loadMoPubView(MoPubView moPubView, String adUnitId, String keywords) {
    if (moPubView == null) {
        Utils.logToast(LockScreenActivity.this, "Unable to inflate MoPubView from xml.");
        //Toast.makeText(this, "Unable to inflate MoPubView from xml.", Toast.LENGTH_SHORT).show();
        return;
    }

    try {
        Utils.validateAdUnitId(adUnitId);
    } catch (IllegalArgumentException exception) {
        Utils.logToast(LockScreenActivity.this, exception.getMessage());
        return;
    }



    moPubView.setBannerAdListener(this);
    moPubView.setAdUnitId(adUnitId);
    moPubView.setKeywords(keywords);
    moPubView.setAutorefreshEnabled(true);
    moPubView.loadAd();


}