0

我正在尝试在我的 Phonegap 应用程序上使用 MillenialMedia,但我无法让它工作。我在 LogCat 上收到以下错误:

08-12 12:52:36.755:I/MillennialMediaSDK(333):初始化 MMLayout。
08-12 12:52:37.385: W/MillennialMediaSDK(333): MMLayout 添加视图(MMWebView 最初来自 (1) MRaidState(loading)。)到 AdType[(b) InternalId(1) LinkedId(0) isFinishing(false) ]
08-12 12:52:37.645: W/MillennialMediaSDK(333): AdView onLayout changedtrue int left 0 int top 687 int right 480 int bottom 762
08-12 12:52:37.685: W/MillennialMediaSDK(333): Id check对于父母:1 对 1
08-12 12:52:38.355:I/MillennialMediaSDK(333):Millennial 广告返回失败。返回零内容长度。
08-12 12:52:38.965:E/MillennialMediaSDK(333):无法握手。不受信任的服务器证书

这是我的代码:

/*
       Licensed to the Apache Software Foundation (ASF) under one
       or more contributor license agreements.  See the NOTICE file
       distributed with this work for additional information
       regarding copyright ownership.  The ASF licenses this file
       to you under the Apache License, Version 2.0 (the
       "License"); you may not use this file except in compliance
       with the License.  You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

       Unless required by applicable law or agreed to in writing,
       software distributed under the License is distributed on an
       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
       KIND, either express or implied.  See the License for the
       specific language governing permissions and limitations
       under the License.
 */

package com.logicstudio.paradise.Replay;

import android.os.Bundle;
import org.apache.cordova.*;
import android.os.Handler;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

public class Replay extends DroidGap
{
    //Constants for tablet sized ads (728x90)
    private static final int IAB_LEADERBOARD_WIDTH = 728;
    private static final int IAB_LEADERBOARD_HEIGHT = 90;

    private static final int MED_BANNER_WIDTH = 480;
    private static final int MED_BANNER_HEIGHT = 60;

    //Constants for phone sized ads (320x50)
    private static final int BANNER_AD_WIDTH = 320;
    private static final int BANNER_AD_HEIGHT = 50;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        super.setIntegerProperty("splashscreen", R.drawable.splash);
        super.loadUrl(Config.getStartUrl());

        int placementWidth = BANNER_AD_WIDTH;
        int placementHeight = BANNER_AD_HEIGHT;

        //Finds an ad that best fits a users device.
        if(canFit(IAB_LEADERBOARD_WIDTH)) {
            placementWidth = IAB_LEADERBOARD_WIDTH;
            placementHeight = IAB_LEADERBOARD_HEIGHT;
        }
        else if(canFit(MED_BANNER_WIDTH)) {
            placementWidth = MED_BANNER_WIDTH;
            placementHeight = MED_BANNER_HEIGHT;
        }


        com.millennialmedia.android.MMSDK.initialize(this);

        com.millennialmedia.android.MMAdView adView = new com.millennialmedia.android.MMAdView(this);

        LinearLayout layout = super.root;

        adView.setApid("131468");

        //Set your metadata in the MMRequest object
        com.millennialmedia.android.MMRequest request = new com.millennialmedia.android.MMRequest();

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

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

        //Set the ad size. Replace the width and height values if needed.
        adView.setWidth(placementWidth);
        adView.setHeight(placementHeight);

        //Calculate the size of the adView based on the ad size. Replace the width and height values if needed.
        int layoutWidth = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, placementWidth, getResources().getDisplayMetrics());
        int layoutHeight = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, placementHeight, getResources().getDisplayMetrics());

        //Create the layout parameters using the calculated adView width and height.
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(layoutWidth, layoutHeight);

        //This positions the banner.
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);

        adView.setLayoutParams(layoutParams);

        //Add the adView to the layout. The layout is assumed to be a RelativeLayout.
        layout.addView(adView);

        adView.getAd();
    }

    protected boolean canFit(int adWidth) {
        int adWidthPx = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, adWidth, getResources().getDisplayMetrics());
        DisplayMetrics metrics = this.getResources().getDisplayMetrics();
        return metrics.widthPixels >= adWidthPx;
    }
}

任何帮助将不胜感激。提前致谢!

4

1 回答 1

1

PhoneGap 的工作原理是将 HTML/CSS/JS 放入一个特殊的 WebView (CordovaWebView) 中,该 WebView 在整个屏幕上运行。控制此默认行为的代码位于其 DroidApp 类中。

要让 Millennial 广告发挥作用(或任何标准的 Android 控件,就此而言),您必须创建一个扩展 android.app.Activity(而不是 DroidApp)的类,并将您的 CordovaWebView 嵌入该活动中。CordovaWebView 将处理您的应用程序的所有 Phonegap 相关资产,而您的活动及其相应的布局可以处理您的 Android 特定类(如 Millennial 的 MMAdView)。

为了更深入地了解 PhoneGap 在 Android 上的工作原理,我强烈建议您在此处阅读他们的文档:http: //cordova.apache.org/docs/en/2.7.0/guide_cordova-webview_android.md.html

要详细了解如何让 Millennial 的 SDK 在该环境中运行,请在此处与支持人员交谈:https ://tools.mmedia.com/user/supportDevPortal

于 2013-09-17T19:03:52.233 回答