關於格式化問題,我試圖格式化它,但它不顯示幾行代碼,我不知道爲什麼。這是今天第二次發生。如果有人能格式化,那會很棒。在Android應用程序中整合Millennial Media SDK 5.0
Quesiton - :
的Android 2.3.3
我只是想Millennial Media等SDK集成到一個演示應用程序。沒有花哨的東西。只是簡單的應用程序,以實現它的想法。
這裏是我做了什麼:::從網站
- 下載android_5_0_0_sdk。
- 創建一個項目並將MMSDK.jar文件添加到庫中
- Rgight單擊該項目,轉到properties-> java build path-> libraries-> add jars->選擇libs和MMSDK的路徑。罐子
4.Added XML代碼到我的活動
<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>
這是我的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 -->
這裏是我的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
改變代碼所建議後千禧年馬克,我得到以下錯誤,基本相同..
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
我已經通過千禧年馬克在其他情況下給出的答案。這是我所做的。
右鍵單擊項目 - >屬性 - > java構建路徑 - >去定購併導出選項卡,並選中MMSDK jar文件的複選框。現在,我沒有收到「握手」錯誤,但「參考」錯誤仍然出現,並且沒有顯示AD。
這裏是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;
}
}
我按照您的建議更改了代碼,但仍然收到相同的錯誤。我更新了錯誤的相關問題,請看看並指導我。 –
我可以擺脫「握手」錯誤,但「參考」錯誤仍然存在。請查看更新後的問題。 –
我認爲'MMAdView adView =(MMAdView)findViewById(R.id.adView);'仍然是缺少的 - 這仍然給你帶來悲傷。我的工作實現(這裏代碼的修改)也有Reference錯誤,但是廣告視圖出現。我想當你調用MMAdView = new MMAdView(this)時,你正在創建一個新的MMAdView並調用getAd,但它不顯示廣告,因爲這不是XML佈局文件中引用的對象。 –