unity3d插入android有米广告
有米官网:http://www.youmi.net/register?r=MTI0MDg=
国内的广告,我觉得万普和有米还不错,我也只试了这两个,其他的都是看评价的,呵呵~~~首先我们去有米官网注册一个账号http://www.youmi.net/register?r=MTI0MDg=;然后添加一个应用,添加成功后会给你一个ID和密钥,在我们的程序中会用到。
在从官网下载jar包,目前有三个jar包,一个是广告条的,另一个是积分墙的,及推送广告。还有就是导入unity的class.jar。
其他都就写代码啦,首先在eclipse下建立一个android工程,把下载的两个jar包导入工程。我们只需要写他的主activity,AndroidManifest.xml和proguard-Projector.txt文件。
MainActivity.java:
注:注意把Activity改成UnityPlayerActivity哦!
- package com.dlnu.goddess;
- import com.unity3d.player.UnityPlayerActivity;
- import net.youmi.android.AdManager;
- import net.youmi.android.AdView;
- import net.youmi.android.appoffers.YoumiOffersManager;
- import net.youmi.android.appoffers.YoumiPointsManager;
- import net.youmi.push.android.YoumiPush;
- import android.os.Bundle;
- import android.content.Context;
- import android.view.ViewGroup.LayoutParams;
- import android.widget.LinearLayout;
- public class MainActivity extends UnityPlayerActivity {
- Context context =null;
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- context = this;
- //推送广告
- YoumiPush.startYoumiPush(this, "f6e5dc3a6da84ca0", "98fb0492fd253f61", true);
- //banner广告
- AdManager.init(this,"9a96b4725e1947e6", "dbf605c63c57e21c", 30, false);
- LinearLayout layout=new LinearLayout(this);
- addContentView(layout, new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
- AdView adView = new AdView(this);
- LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
- layout.addView(adView, params);
- //积分墙
- YoumiOffersManager.init(this, "9a96b4725e1947e6", "dbf605c63c57e21c");
- }
- //打开积分墙
- void open1(){
- YoumiOffersManager.showOffers( MainActivity.this,YoumiOffersManager.TYPE_REWARD_OFFERS);
- }
- //打开推荐列表
- void opne2(){
- YoumiOffersManager.showOffers(MainActivity.this,YoumiOffersManager.TYPE_REWARDLESS_APPLIST);
- }
- //打开单个推荐
- void open3(){
- YoumiOffersManager.showOffers(MainActivity.this,YoumiOffersManager.TYPE_REWARDLESS_FEATUREDAPP);
- }
- //获取积分
- int getpoint(){
- return YoumiPointsManager.queryPoints(this);
- }
- }
AndroidManifest.xml:
注:注意主Aactivity哦,我这里是android:name="com.dlnu.goddess.MainActivity",就是我们上面的那个Activity,其实就是你第一个看到的页面,个人理解哦,呵呵~~~
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.dlnu.goddess"
- android:versionCode="1"
- android:versionName="1.0" >
- <uses-sdk
- android:minSdkVersion="8"
- android:targetSdkVersion="17" />
- <uses-permission android:name="android.permission.INTERNET"/>
- <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
- <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
- <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
- <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
- <uses-permission android:name="com.android.browser.permission.WRITE_HISTORY_BOOKMARKS"/>
- <application
- android:allowBackup="true"
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name"
- android:theme="@style/AppTheme" >
- <activity
- android:name="com.dlnu.goddess.MainActivity"
- android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- <service android:name="net.youmi.push.android.YoumiService"></service>
- <activity android:name="net.youmi.push.android.YoumiActivity"></activity>
- <receiver android:name="net.youmi.push.android.YoumiReceiver">
- <intent-filter>
- <action android:name="android.intent.action.BOOT_COMPLETED" />
- </intent-filter>
- <intent-filter>
- <action android:name="android.intent.action.PACKAGE_ADDED"/>
- <action android:name="android.intent.action.PACKAGE_INSTALL"/>
- <data android:scheme="package"/>
- </intent-filter>
- </receiver>
- <activity android:name="net.youmi.android.appoffers.YoumiOffersActivity"
- android:configChanges="keyboard|keyboardHidden|orientation"/>
- <activity
- android:configChanges="keyboard|keyboardHidden|orientation"
- android:name="net.youmi.android.AdActivity" />
- <receiver android:name="net.youmi.android.YoumiReceiver">
- <intent-filter>
- <action android:name="android.intent.action.PACKAGE_ADDED"/>
- <action android:name="android.intent.action.PACKAGE_INSTALL"/>
- <data android:scheme="package"/>
- </intent-filter>
- </receiver>
- <meta-data android:name="YOUMI_CHANNEL" android:value="0"></meta-data>
- </application>
- </manifest>
proguard-Projector.txt:
- # To enable ProGuard in your project, edit project.properties
- # to define the proguard.config property as described in that file.
- #
- # Add project specific ProGuard rules here.
- # By default, the flags in this file are appended to flags specified
- # in ${sdk.dir}/tools/proguard/proguard-android.txt
- # You can edit the include path and order by changing the ProGuard
- # include property in project.properties.
- #
- # For more details, see
- # http://developer.android.com/guide/developing/tools/proguard.html
- # Add any project specific keep options here:
- # If your project uses WebView with JS, uncomment the following
- # and specify the fully qualified class name to the JavaScript interface
- # class:
- #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
- # public *;
- #}
- -keep class net.youmi.push.android.** {
- *;
- }
- -keep class net.youmi.android.appoffers.** {
- *;
- }
- -keep class net.youmi.android.** {
- *;
- }
接下来的部分就得看雨松MOMO的了,先在unity下建立一个工程,安装雨松momo的做法,把我们android工程打包并且放入unity里面就行,注意:在Plugins/Android/下要建立一个libs文件夹,把从有米官方下载的两个jar包导入。Plugins/Android/libs/xxx.jar,yyy,jar;最后最重要的就是把工程的包名改成android工程下的,我这里是com.dlnu.nate;剩下的就是看你在unity下调用android里面open1,open2,open3函数了。
Unity下的脚本:
- using UnityEngine;
- using System.Collections;
- public class AdTest : MonoBehaviour {
- AndroidJavaClass jc;
- AndroidJavaObject jo;
- void Start()
- {
- jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
- jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
- }
- void Update ()
- {
- if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.Home) )
- {
- Application.Quit();
- }
- }
- void OnGUI()
- {
- if(GUILayout.Button("OPEN1",GUILayout.Height(100)))
- {
- jo.Call("open1");
- }
- if(GUILayout.Button("OPEN2",GUILayout.Height(100)))
- {
- jo.Call("open2");
- }
- if(GUILayout.Button("OPEN3",GUILayout.Height(100)))
- {
- jo.Call("open3");
- }
- }
- }
注:一定要记得把报名改成Android里面的一样哦!
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。