0

我添加了 startapp ads sdk,但我需要以编程方式激活横幅

我知道怎么了

但是这种方法让我可以添加没有 xml 文件的横幅

请问有人可以帮忙吗?

我从这里得到 sdk:

https://support.start.io/hc/en-us/articles/360006662474-Advanced-Usage#adding-banner-callbacks-0-8

在此处输入图像描述

我的主要活动:

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import com.startapp.sdk.ads.banner.Banner;
import com.startapp.sdk.adsbase.Ad;
import com.startapp.sdk.adsbase.SDKAdPreferences;
import com.startapp.sdk.adsbase.StartAppSDK;
import com.startapp.sdk.adsbase.StartAppAd;
import android.content.Intent;
import android.view.View;
import com.startapp.sdk.adsbase.VideoListener;
import com.startapp.sdk.adsbase.adlisteners.AdEventListener;


import android.os.Bundle;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.startapp.sdk.adsbase.StartAppSDK;

public class MainActivity extends AppCompatActivity {

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

        StartAppSDK.init(this,
                "Your App ID",
                new SDKAdPreferences()
                        .setAge(35)
                        .setGender(SDKAdPreferences.Gender.MALE));


        // Get the Main relative layout of the entire activity
        RelativeLayout mainLayout = (RelativeLayout)findViewById(R.id.mainLayout);
// Define StartApp Banner
        Banner startAppBanner = new Banner(context);
        RelativeLayout.LayoutParams bannerParameters =
                new RelativeLayout.LayoutParams(
                        RelativeLayout.LayoutParams.WRAP_CONTENT,
                        RelativeLayout.LayoutParams.WRAP_CONTENT);
        bannerParameters.addRule(RelativeLayout.CENTER_HORIZONTAL);
        bannerParameters.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
// Add to main Layout
        mainLayout.addView(startAppBanner, bannerParameters);

    }


    public void btnOpenActivity (View view){
        Intent nextActivity = new Intent(this, MainActivity.class);
        startActivity(nextActivity);
        StartAppAd.showAd(this);
    }
    public void someMethod() {
        // start your next activity
        startActivity(new Intent(this, MainActivity.class));

        // and show interstitial ad
        StartAppAd.showAd(this);
    }

    public void showRewardedVideo(View view) {

        final StartAppAd rewardedVideo = new StartAppAd(this);

        rewardedVideo.setVideoListener(new VideoListener() {
            @Override
            public void onVideoCompleted() {
                Toast.makeText(getApplicationContext(), "Grant the reward to user", Toast.LENGTH_SHORT).show();
            }
        });

        rewardedVideo.loadAd(StartAppAd.AdMode.REWARDED_VIDEO, new AdEventListener() {
            @Override
            public void onReceiveAd(Ad ad) {
                rewardedVideo.showAd();
            }

            @Override
            public void onFailedToReceiveAd(Ad ad) {
                Toast.makeText(getApplicationContext(), "Can't show rewarded video", Toast.LENGTH_SHORT).show();
            }
        });
    }





}

我的主要负责人:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.myapplication"
    tools:ignore="ExtraText">
    xmlns:tools="http://schemas.android.com/tools"
    tools:ignore="ExtraText">
    xmlns:tools="http://schemas.android.com/tools”
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" tools:node="remove"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.MyApplication">

        <meta-data android:name="com.startapp.sdk.APPLICATION_ID"
            android:value="206399494" />
        <meta-data android:name="com.startapp.sdk.RETURN_ADS_ENABLED"
            android:value="true" />

        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

4

0 回答 0