我已经用SO帮助我解决编程挫折多年了,这感觉就像我第一次遇到一个独一无二的问题(或者至少是其他人没有问过的问题)。无论如何,这是我在下面的问题,我将非常感谢任何人都能提供的任何帮助。 :)
过去24小时左右,我一直在努力在我现有的Android应用中实施Google游戏服务。我按照Google提供的说明,在开发者控制台中设置应用程序,使用签名证书密钥,将其链接到我在商店中的应用程序,将应用程序ID放入我的Eclipse项目中的所有位置。我推荐使用BaseGameActivity类,我的项目编译得很好,没有错误。我还使用FacebookSDK和AdMob / Google广告(使用新的Google服务库)。我想不出任何我没有做过的可以解释我错误的事情 - 如下......
当我的应用程序打开并尝试登录时,会弹出并正常请求权限/授权,但是一旦我授予这些权限,就会显示“登录失败。请检查您的网络连接,然后重试。”。这种情况在过去24小时内每次都发生过,因为我一直在尝试一些小调整,希望能有所作为。我100%确定我的网络连接没有问题,如错误信息所示。
P.S。它似乎确实连接/登录了一个随机时间,我得到了欢迎消息,但当它到达我的应用程序中的下一个活动时,它似乎再次退出并返回错误消息。我还从Google+方面进行了检查,我可以看到我确实授予了我的应用权限(这意味着我确实已成功登录并正确授权)所以我无法理解我在其中获得的错误消息游戏本身。
我知道这很长,但我希望尽可能彻底地解释我的问题 - 有人可以建议我如何处理这个问题吗? :(
import java.util.Iterator;
import java.util.List;
import java.util.Timer;
import android.app.ActionBar.LayoutParams;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.view.Display;
import android.view.Gravity;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.RotateAnimation;
import android.widget.FrameLayout;
import android.widget.Gallery;
import android.widget.ImageView;
import com.flurry.android.FlurryAgent;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.google.example.games.basegameutils.BaseGameActivity;
//import android.view.Gravity;
//import com.google.ads.AdRequest;
//import com.google.ads.AdSize;
//import com.google.ads.AdView;
public class MainActivity extends BaseGameActivity {
private FrameLayout myLayout;
private FrameLayout.LayoutParams params;
private MainMenuView myView;
private RotateAnimation buttonRotate, buttonReverseRotate;
private ImageView start, achievements, highscores;
protected AdView adView;
boolean musicStopped = false;
//private AdView adView;
String name = "startSt";
int width, height;
Intent i;
public void onSignInFailed () {
}
public void onSignInSucceeded () {
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_level_select);
i = new Intent(this, BackgroundMusicService.class);
startService(i);
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
adView = new AdView(this);
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId("fasf78678fhk");
//adView.setAdSize(AdSize.BANNER);
//adView.setAdUnitId(AD_UNIT_ID);
if (android.os.Build.VERSION.SDK_INT >= 13) {
display.getSize(size);
width = size.x;
height = size.y;
}
else {
width = display.getWidth();
height = display.getHeight();
}
start = new ImageView(this);
//animview.setAdjustViewBounds(true); // set the ImageView bounds to match the Drawable's dimensions
start.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
params = new FrameLayout.LayoutParams((int)(width * 0.40), (int)(height * ((double)60/534)));
params.setMargins((int)(width * 0.30), (int) (height * ((double)280/534)), (int)(width * 0.70), (int)(height * ((double)340/534)));
//(int)(width * 0.20), (int)(height * 0.01), (int)(width * 0.80), (int)(height * 0.14)
params.gravity = Gravity.TOP;
start.setLayoutParams(params);
start.setBackgroundResource(R.drawable.startbtn);
//
achievements = new ImageView(this);
//animview.setAdjustViewBounds(true); // set the ImageView bounds to match the Drawable's dimensions
achievements.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
params = new FrameLayout.LayoutParams((int)(width * 0.40), (int)(height * ((double)53/534)));
params.setMargins((int)(width * 0.30), (int) (height * ((double)353/534)), (int)(width * 0.70), (int)(height * ((double)408/534)));
//(int)(width * 0.20), (int)(height * 0.01), (int)(width * 0.80), (int)(height * 0.14)
params.gravity = Gravity.TOP;
achievements.setLayoutParams(params);
achievements.setBackgroundResource(R.drawable.achievementsbtn);
//
highscores = new ImageView(this);
//animview.setAdjustViewBounds(true); // set the ImageView bounds to match the Drawable's dimensions
highscores.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
params = new FrameLayout.LayoutParams((int)(width * 0.40), (int)(height * ((double)56/534)));
params.setMargins((int)(width * 0.30), (int) (height * ((double)422/534)), (int)(width * 0.70), (int)(height * ((double)478/534)));
//(int)(width * 0.20), (int)(height * 0.01), (int)(width * 0.80), (int)(height * 0.14)
params.gravity = Gravity.TOP;
highscores.setLayoutParams(params);
highscores.setBackgroundResource(R.drawable.highscoresbtn);
//adView = new AdView(this, AdSize.BANNER, "a152709973dcd0d");
//LinearLayout.LayoutParams LP = (LinearLayout.LayoutParams) adView.getLayoutParams();
//LP.gravity=Gravity.BOTTOM;
//adView.setLayoutParams(LP);
musicStopped = false;
buttonRotate = new RotateAnimation(-4f, 4f, (float) (0.2 * width), (float) (height * ((double)28/534)));
buttonRotate.setDuration(1000);
buttonRotate.setRepeatMode(RotateAnimation.REVERSE);
buttonRotate.setRepeatCount(1000);
buttonRotate.setFillEnabled(true);
buttonRotate.setFillAfter(true);
//
buttonReverseRotate = new RotateAnimation(4f, -4f, (float) (0.2 * width), (float) (height * ((double)28/534)));
buttonReverseRotate.setDuration(1000);
buttonReverseRotate.setRepeatMode(RotateAnimation.REVERSE);
buttonReverseRotate.setRepeatCount(1000);
buttonReverseRotate.setFillEnabled(true);
buttonReverseRotate.setFillAfter(true);
buttonReverseRotate.setStartOffset(0);
//adView.setX(0f);
//adView.setY((float) (height * 0.8));csd
myView = new MainMenuView (this, i, width, height);
myLayout = new FrameLayout(this);
setContentView(myLayout);
myLayout.addView(myView);
myLayout.addView(start);
myLayout.addView(highscores);
myLayout.addView(achievements);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
lp = new FrameLayout.LayoutParams((int)(width), (int)(height * 0.09));
lp.setMargins((int)(width * 0.0), (int)(height * 0.00), (int)(width * 1), (int)(height * 0.09));
lp.gravity = Gravity.TOP;
adView.setLayoutParams(lp);
myLayout.addView(adView);
adView.loadAd(new AdRequest.Builder().build());
adView.setVisibility(View.INVISIBLE);
start.setVisibility(View.GONE);
achievements.setVisibility(View.GONE);
highscores.setVisibility(View.GONE);
//FACEBOOK
//adView.loadAd(new AdRequest());
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
name = "activity result runs";
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.level_select, menu);
return true;
}
public String getName() {
return name;
}
public void onBackPressed () {
stopService(i);
super.onBackPressed();
}
public void showButtons () {
//start.setVisibility(View.VISIBLE);
//achievements.setVisibility(View.VISIBLE);
//highscores.setVisibility(View.VISIBLE);
}
//public void onUserLeaveHint () {
//stopService(i);
//super.onUserLeaveHint();
//}
private boolean isAppForeground() {
ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> l = mActivityManager
.getRunningAppProcesses();
Iterator<RunningAppProcessInfo> i = l.iterator();
while (i.hasNext()) {
RunningAppProcessInfo info = i.next();
if (info.uid == getApplicationInfo().uid && info.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND)
{
return true;
}
}
return false;
}
@SuppressWarnings("deprecation")
public void onResume () {
super.onResume();
//name = "StartSt2";
start.startAnimation(buttonRotate);
highscores.startAnimation(buttonRotate);
achievements.startAnimation(buttonReverseRotate);
}
public void onStop () {
super.onStop();
FlurryAgent.onEndSession(this);
if (!isAppForeground()) {
stopService(i);
musicStopped = true;
}
}
public void onStart () {
super.onStart();
FlurryAgent.onStartSession(this, "KFKHK45345JHDADF");
//stopService(i);
//startService(i);
}
public void onRestart () {
super.onRestart();
if (musicStopped) {
//stopService(i);
startService(i);
musicStopped = false;
}
}
public void startMusicService () {
startService(i);
}
public void stopMusicService () {
stopService(i);
}
}
答案 0 :(得分:0)
确保定义了res / ids.xml中定义的应用ID:
<string name="app_id">YOUR_APP_ID</string>
游戏的应用ID只有12个左右的数字,来自游戏图标下的https://play.google.com/apps/publish。
接下来,确保您的Android应用程序位于同一个项目中。如果两者不匹配,您可能会收到这样的错误。