gpt4 book ai didi

android - 在 Android 应用程序中集成 Millennial Media SDK 5.0

转载 作者:太空狗 更新时间:2023-10-29 13:30:06 24 4
gpt4 key购买 nike

关于格式化的问题,我试过格式化,但是没有显示几行代码,不知道为什么。这是今天第二次发生。如果有人可以格式化它,那就太好了。

问题-:

安卓 2.3.3

我只是想将 millennial media sdk 集成到演示应用程序中。没有花哨的东西。只是简单的应用程序,了解如何实现它。

这是我所做的:::

  1. 从网站下载了 android_5_0_0_sdk。
  2. 创建项目并将MMSDK.jar文件添加到libs
  3. 右键单击项目,转到属性->java 构建路径->库->添加 jars-> 选择库和 MMSDK.jar 的路径

4.将 XML 代码添加到我的 Activity 中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mm="http://millennialmedia.com/android/schema" // this
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />

// and this
<com.millennialmedia.android.MMAdView
android:id="@+id/adView"
android:layout_width="468dp"
android:layout_height="60dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
mm:apid="123149"
mm:height="60"
mm:width="468" />


</RelativeLayout>
  1. 这是我的 AndroidManifest.xml

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

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

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

    <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
    android:name="com.example.millennialdemo.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>

    <!-- Start of MillennialMedia.com code -->
    <activity
    android:name="com.millennialmedia.android.MMActivity"
    android:configChanges="keyboardHidden|orientation|keyboard" >
    </activity>
    <activity
    android:name="com.millennialmedia.android.VideoPlayer"
    android:configChanges="keyboardHidden|orientation|keyboard" >
    </activity>

    <!-- End of MillennialMedia.com code -->

  1. 这是我的 MainActivity:-

    import com.millennialmedia.android.MMAdView;
    import com.millennialmedia.android.MMInterstitial;
    import com.millennialmedia.android.MMAd;
    import com.millennialmedia.android.MMBroadcastReceiver;
    import com.millennialmedia.android.MMRequest;
    import com.millennialmedia.android.MMSDK;
    import com.millennialmedia.android.RequestListener.RequestListenerImpl;
    public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    MMSDK.initialize(this);

    setContentView(R.layout.activity_main);

    MMAdView adView = new MMAdView(this);

    //Replace YOUR_APID with the APID provided to you by Millennial Media
    adView.setApid("123149");

    //Set your metadata in the MMRequest object
    MMRequest request = new MMRequest();

    //Add metadata here.

    //Add the MMRequest object to your MMAdView.
    adView.setMMRequest(request);

    //Sets the id to preserve your ad on configuration changes.
    adView.setId(MMSDK.getDefaultAdId());
    adView.getAd();//change suggested by Millennial Mark


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
    }

    }

我想我已经完成了文档中告诉我的任何事情,但我没有收到任何广告,我得到的只是我的 logcat 中的以下日志...

05-20 20:54:58.932: E/Web Console(386): ReferenceError: Can't find variable: MMJS at undefined:1
05-20 20:54:58.932: E/Web Console(386): ReferenceError: Can't find variable: MMJS at undefined:1
05-20 20:54:58.972: W/MillennialMediaSDK(386): AdView onLayout changedfalse int left 24 int top 24 int right 456 int bottom 99
05-20 20:55:00.382: D/dalvikvm(386): GC_CONCURRENT freed 1228K, 57% free 2903K/6727K, external 2002K/2137K, paused 6ms+6ms
05-20 20:55:01.172: E/MillennialMediaSDK(386): Could not get a handshake. No peer certificate
05-20 20:55:01.172: E/MillennialMediaSDK(386): Could not get a handshake. No peer certificate
05-20 20:55:01.212: D/dalvikvm(386): GC_CONCURRENT freed 826K, 58% free 2843K/6727K, external 2002K/2137K, paused 6ms+5ms

我不明白这是怎么回事。如果有人能帮助我,我将不胜感激。

改变之后

 MMAdView adView = new MMAdView(this);

MMAdView adView = (MMAdView) findViewById(R.id.adView);

我仍然有同样的问题..这是 logcat..

05-20 21:57:26.911: I/MillennialMediaSDK(467): Initializing MMLayout.
05-20 21:57:27.631: W/MillennialMediaSDK(467): MMLayout adding view (MMWebView originally from(1) MRaidState(loading).) to AdType[(b) InternalId(1) LinkedId(0) isFinishing(false)]
05-20 21:57:27.842: W/MillennialMediaSDK(467): AdView onLayout changedtrue int left 24 int top 24 int right 456 int bottom 114
05-20 21:57:27.861: W/MillennialMediaSDK(467): Id check for parent: 1 versus 1
05-20 21:57:27.911: W/MillennialMediaSDK(467): AdView onLayout changedfalse int left 24 int top 24 int right 456 int bottom 114
05-20 21:57:28.041: E/Web Console(467): ReferenceError: Can't find variable: MMJS at undefined:1
05-20 21:57:28.051: E/Web Console(467): ReferenceError: Can't find variable: MMJS at undefined:1
05-20 21:57:28.551: W/MillennialMediaSDK(467): AdView onLayout changedfalse int left 24 int top 24 int right 456 int bottom 114
05-20 21:57:29.541: D/dalvikvm(467): GC_CONCURRENT freed 1226K, 57% free 2905K/6727K, external 2002K/2137K, paused 5ms+9ms
05-20 21:57:30.292: E/MillennialMediaSDK(467): Could not get a handshake. No peer certificate
05-20 21:57:30.301: E/MillennialMediaSDK(467): Could not get a handshake. No peer certificate
05-20 21:57:30.331: D/dalvikvm(467): GC_CONCURRENT freed 813K, 58% free 2843K/6727K, external 2002K/2137K, paused 4ms+4ms

按照Millennial Mark的建议修改代码后,出现如下错误,基本相同..

05-21 08:54:38.948: I/MillennialMediaSDK(341): Initializing MMLayout.
05-21 08:54:39.616: W/MillennialMediaSDK(341): MMLayout adding view (MMWebView originally from(1) MRaidState(loading).) to AdType[(b) InternalId(1) LinkedId(0) isFinishing(false)]
05-21 08:54:40.027: W/MillennialMediaSDK(341): AdView onLayout changedtrue int left 24 int top 24 int right 456 int bottom 99
05-21 08:54:40.055: W/MillennialMediaSDK(341): Id check for parent: 1 versus 1
05-21 08:54:40.115: W/MillennialMediaSDK(341): AdView onLayout changedfalse int left 24 int top 24 int right 456 int bottom 99
05-21 08:54:40.295: E/Web Console(341): ReferenceError: Can't find variable: MMJS at undefined:1
05-21 08:54:40.295: E/Web Console(341): ReferenceError: Can't find variable: MMJS at undefined:1
05-21 08:54:40.295: W/MillennialMediaSDK(341): AdView onLayout changedfalse int left 24 int top 24 int right 456 int bottom 99
05-21 08:54:58.139: E/MillennialMediaSDK(341): Ad request HTTP error. androidsdk.ads.mp.mydas.mobi
05-21 08:54:59.527: E/MillennialMediaSDK(341): Could not get a handshake. ads.mp.mydas.mobi
05-21 08:54:59.527: E/MillennialMediaSDK(341): Could not get a handshake. ads.mp.mydas.mobi

Millennial Mark 在其他场景中给出的答案我已经看过了。这是我所做的。

右键单击项目->属性->java构建路径->转到命令和导出选项卡并选中MMSDK jar文件的复选框。现在,我没有收到“握手”错误,但仍然出现“引用”错误,并且也没有显示任何广告。

这是 logcat 跟踪

05-21 09:03:33.565: E/Web Console(341): ReferenceError: Can't find variable: MMJS at undefined:1
05-21 09:03:46.296: W/MillennialMediaSDK(341): Id check for parent: 1 versus 1
05-21 09:03:46.346: E/Web Console(341): ReferenceError: Can't find variable: MMJS at undefined:1

修改后的 MainActivity

package com.example.millennialdemo;

import android.os.Bundle;
import android.app.Activity;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.Menu;
import android.widget.RelativeLayout;

import com.millennialmedia.android.MMAdView;
import com.millennialmedia.android.MMInterstitial;
import com.millennialmedia.android.MMAd;
import com.millennialmedia.android.MMBroadcastReceiver;
import com.millennialmedia.android.MMRequest;
import com.millennialmedia.android.MMSDK;
import com.millennialmedia.android.RequestListener.RequestListenerImpl;


public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

MMSDK.initialize(this);

setContentView(R.layout.activity_main);

MMAdView adView = (MMAdView) findViewById(R.id.adView);

//Replace YOUR_APID with the APID provided to you by Millennial Media
adView.setApid("123149");

//Set your metadata in the MMRequest object
MMRequest request = new MMRequest();

//Add metadata here.

//Add the MMRequest object to your MMAdView.
adView.setMMRequest(request);

//Sets the id to preserve your ad on configuration changes.
adView.setId(MMSDK.getDefaultAdId());
adView.getAd();


}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}

最佳答案

我认为 Tarun 的第一步是正确的。变化:

MMAdView adView = new MMAdView(this);

MMAdView adView = (MMAdView)findViewById(R.id.adView);

并添加:

adView.getAd();

...在您的 Activity 的 onCreate(...) 方法结束时(在 adView.setId(MMSDK.getDefaultAdId()); 之后)。

关于android - 在 Android 应用程序中集成 Millennial Media SDK 5.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16653670/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com