将GameSpark Ba​​aS集成到Android后出现黑屏

时间:2018-08-18 16:55:50

标签: android

我正在尝试将GmaeSpark系统集成到Android应用程序。首先,我想在一个简单的项目中尝试通过Android Studio创建基本项目,然后将配置添加为GameSpark教程。

我在项目的gradle中添加了依赖项;

NavUtils

我将GameSpark客户端的实现添加到模块的gradle;

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.+'
        classpath "com.github.dcendents:android-maven-gradle-plugin:2.1"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "http://repo.gamesparks.net/mvn"
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

之后,我向AndroidManifest添加了所需的代码

apply plugin: 'com.android.feature'

android {
    compileSdkVersion 27
    defaultConfig {
        minSdkVersion 24
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation project(':base')
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.gamesparks.sdk:gamesparks-android-client-sdk:+'
}

最后,我在活动中添加了开始代码;

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.slowthstudio.android.testingapp.GameSparkTest">

    <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>
        <activity
            android:name=".MainActivity"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar"
            tools:replace="android:theme">

            <intent-filter android:order="1">
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.DEFAULT" />

                <data
                    android:host="android.slowthstudio.com"
                    android:pathPattern="/.*"
                    android:scheme="https" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

但是,当我运行代码时,我仅看到带有Gamepark Preview模式文本的黑屏。连接成功,但是我看到黑屏。我在做什么错了?

1 个答案:

答案 0 :(得分:0)

我通过深入研究gamepark android sdk代码解决了问题。我在MainActivity中创建了一个Intent,然后按如下所示开始该活动;

public class MainActivity extends AppCompatActivity {

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

        String apiKey = "apikey";
        String secret = "secret";
        String credential = "device";

        GSAndroidPlatform.initialise(this, apiKey, secret, credential, false, true);

        GSAndroidPlatform.gs().setOnAvailable(new GSEventConsumer<Boolean>() {
            @Override
            public void onEvent(Boolean available) {

                if (available) {
                    //If we connect, authenticate our player

                    toastMessage("Successful");

                } else
                    toastMessage("unSuccessful");
            }
        });

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });

        Intent openMainActivity = new Intent(this.getContext(), MainActivity.class);
        openMainActivity.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        startActivity(openMainActivity);
    }

    @Override
    public void onStart() {
        super.onStart();
        GSAndroidPlatform.gs().start();
    }
...
}

然后解决了。