Need Help Installing Google Play Services in my game - android

I made this game using libGDX. I already uploaded the game to the play store.
Now I am having trouble installing Google play services to it.
-I followed the instructions and tried running the final .apk file, but after adding all, the Game says Game Unfortunately Stopped working.
Would anybody be able to help me? I dont know what is the problem thats causing the game to not run. There are no errors as well.
Here is my MainActivity File:
public abstract class MainActivity extends AndroidApplication
implements
GameHelperListener,
ActionResolver {
private GameHelper gameHelper;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
cfg.useGL20 = false;
initialize(new ZBGame(), cfg);
// initialize(new TutorialLibgdxGameservices(this), false);
gameHelper.setup(this);
// AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
// cfg.useGL20 = false;
// initialize(new ZBGame(), cfg);
}
public MainActivity() {
gameHelper = new GameHelper(this);
gameHelper.enableDebugLog(true, "GPGS");
}
/** Called when the activity is first created. */
#Override
public void onStart() {
super.onStart();
gameHelper.onStart(this);
}
#Override
public void onStop() {
super.onStop();
gameHelper.onStop();
}
#Override
public void onActivityResult(int request, int response, Intent data) {
super.onActivityResult(request, response, data);
gameHelper.onActivityResult(request, response, data);
}
#Override
public boolean getSignedInGPGS() {
return gameHelper.isSignedIn();
}
#Override
public void loginGPGS() {
try {
runOnUiThread(new Runnable() {
public void run() {
gameHelper.beginUserInitiatedSignIn();
}
});
} catch (final Exception ex) {
}
}
#Override
public void submitScoreGPGS(int score) {
gameHelper.getGamesClient().submitScore("CgkI_v3s4-UREAIQAQ", score);
}
#Override
public void getLeaderboardGPGS() {
startActivityForResult(
gameHelper.getGamesClient().getLeaderboardIntent("CgkI_v3s4-UREAIQAQ"), 100);
}
#Override
public void onSignInFailed() {
}
#Override
public void onSignInSucceeded() {
}
}
Thanks

Related

When I must reward player for watching video in the core (libgdx)?

I am making a game on LibGdx that has video ads. I implemented interface and it's methods. Everything works, video is shown.
AndroidLauncher:
public class MainAndroidLauncherAuthorization extends AndroidApplication implements
AdsController, RewardedVideoAdListener, AdHandler {
private static final String TAG = "GoogleActivity";
private static final int RC_SIGN_IN = 9001;
private FirebaseAuth mAuth;
private GoogleSignInClient mGoogleSignInClient;
private RewardedVideoAd rewardedVideoAd;
private boolean isRewardLoaded;
private boolean completed;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
setContentView(R.layout.activity);
initialize(new STARTGame(this, this), config);
MobileAds.initialize(this, "ca-app-pub-3940256099942544/5224354917");
rewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
rewardedVideoAd.setRewardedVideoAdListener(this);
loadRewardedVideoAd();
}
public void loadRewardedVideoAd() {
isRewardLoaded=false;
rewardedVideoAd.loadAd("ca-app-pub-3940256099942544/5224354917", new
AdRequest.Builder().build());
}
#Override
public void onRewardedVideoAdLoaded() {
isRewardLoaded =true;
}
#Override
public void showRewardedVideo() {
runOnUiThread(new Runnable() {
#Override
public void run() {
if (rewardedVideoAd.isLoaded()) {
rewardedVideoAd.show();
} else {
loadRewardedVideoAd();
}
}
});
}
#Override
public boolean hasVideoReward(){
return isRewardLoaded;
}
#Override
public void onRewardedVideoAdOpened() {
}
#Override
public void onRewardedVideoStarted() {
}
#Override
public void onRewardedVideoAdClosed() {
loadRewardedVideoAd();
}
#Override
public void onRewarded(RewardItem reward) {
loadRewardedVideoAd();
}
#Override
public void onRewardedVideoAdLeftApplication() {
}
#Override
public void onRewardedVideoAdFailedToLoad(int i) {
}
#Override
public void onRewardedVideoCompleted() {
completed = true;
}
#Override
public boolean addCoins() {
return completed;
}
#Override
protected void onResume() {
super.onResume();
rewardedVideoAd.resume(this);
}
#Override
public void onPause() {
super.onPause();
rewardedVideoAd.pause(this);
}
#Override
public void onDestroy() {
super.onDestroy();
rewardedVideoAd.destroy(this);
}
#Override
public void coin_10() {
Prefs prefs = new Prefs();
prefs.plus_Coins_bank(10);
}
}
Interface:
public interface AdsController {
void showRewardedVideo();
void loadRewardedVideoAd();
boolean addCoins();
boolean hasVideoReward();
Core:
public class Win_01_18 extends Window implements AdsController, AdHandler {
private Prefs prefs;
public Win_01_18(AdHandler sums, final AdsController adsController, final AssetMan assetMan) {
super("", assetMan.get_skin_dialogs(), "dialog_window_main");
*******
Button btn_buy_10 = new Button(assetMan.get_skin_buttons_coins_video(), "btn_video_long");
***
btn_buy_10.addListener(new ClickListener() {
#Override
public void clicked(InputEvent event, float x, float y) {
adsController.showRewardedVideo();
super.clicked(event, x, y);
}
});
#Override
public void showRewardedVideo() {
}
#Override
public void loadRewardedVideoAd() {
}
#Override
public boolean addCoins() {
return false;
}
#Override
public boolean hasVideoReward() {
return false;
}
#Override
public void coin_10() {
}
Everything works. There are 2 questions:
1 - How to check the onRewardedVideoCompleted() method from core-class?
2 - On what event should the coins be added for watching a video in the core-class?
I am currently trying this myself. But what about changing the
void showRewardedVideoAd()
to a boolean
boolean showRewardedVideoAd()
And then in the onRewardedVideoCompleted() you return true and if it fails you return false.
Then in the core where you call the ad you put
boolean adFinished = False;
adFinished = adsController.showRewardedVideo();
if(adFinished){
// give them the coins or whatever
} else {
// the ad failed or the clicked it away early or something. Don't give them coins and go on
}

Optimum way to implement youtube player into android application

I'm working on a android application and i get mp4 file urls from a json file. Now i want to play these files inside my app using a youtube player. After some research i managed to play my videos within my app. But when i go back from playing videos to other parts of my app,the app seems to be slowed down. I need to know if i'm doing this correctly.
This is my code used to play the video.
if (YouTubeApiServiceUtil.isYouTubeApiServiceAvailable(activity).equals(
YouTubeInitializationResult.SUCCESS)
&& android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
Intent intent = YouTubeStandalonePlayer
.createVideoIntent(activity, API_KEY,
video.getFile());
startActivity(intent);
}
from video.getFile(); i'm getting my video url.
i have used YouTubeAndroidPlayerApi.jar as the library.
1.Download YouTubePlyaer API https://developers.google.com/youtube/android/player/downloads/
Register your app on google developer console https://console.developers.google.com
Take an unique API Key and use that in your App.
use below code
public class AboutUs extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_about_us);
YouTubePlayerView youTubePlayerView = (YouTubePlayerView) findViewById(R.id.youtube_player);
youTubePlayerView.initialize(Constants.YOUTUBE_API_KEY, this);
initViews();
}
private void initViews() {
Button btnVisitMega = (Button) findViewById(R.id.btn_visit_megaforties);
Button btnVisitSecurity = (Button) findViewById(R.id.btn_visit_security_seals);
btnVisitMega.setOnClickListener(this);
btnVisitSecurity.setOnClickListener(this);
}
#Override
public void onInitializationFailure(Provider arg0, YouTubeInitializationResult arg1) {
Toast.makeText(this, "Failured to Initialize!", Toast.LENGTH_LONG).show();
}
#Override
public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean wasRestored) {
/** add listeners to YouTubePlayer instance **/
player.setPlayerStateChangeListener(playerStateChangeListener);
player.setPlaybackEventListener(playbackEventListener);
/** Start buffering **/
if (!wasRestored) {
player.cueVideo(Constants.YOUTUBE_VIDEO_ID);
}
}
private PlaybackEventListener playbackEventListener = new PlaybackEventListener() {
#Override
public void onBuffering(boolean arg0) {
}
#Override
public void onPaused() {
}
#Override
public void onPlaying() {
}
#Override
public void onSeekTo(int arg0) {
}
#Override
public void onStopped() {
}
};
private PlayerStateChangeListener playerStateChangeListener = new PlayerStateChangeListener() {
#Override
public void onAdStarted() {
}
#Override
public void onError(ErrorReason arg0) {
}
#Override
public void onLoaded(String arg0) {
}
#Override
public void onLoading() {
}
#Override
public void onVideoEnded() {
}
#Override
public void onVideoStarted() {
}
};

Play Service wont submit score

Im running into a problem when trying to submit a score to my Play Services Leader board. From my MainActivity the user is logged in successfully then from my GameScreen activity I try to submit a score but it fails:(...My Question is does the connection persist or do I have to reconnect the user before I submit???
MAIN ACTIVITY.
public class MainActivity extends BaseGameActivity implements View.OnClickListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
Button siButton;
private GoogleApiClient mGoogleApiClient;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN)
.addApi(Games.API).addScope(Games.SCOPE_GAMES)
.build();
siButton = (Button) findViewById(R.id.sign_out_button);
siButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (view.getId() == R.id.sign_in_button) {
beginUserInitiatedSignIn();
} else if (view.getId() == R.id.sign_out_button) {
signOut();
findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
findViewById(R.id.sign_out_button).setVisibility(View.GONE);
}
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public void onSignInSucceeded() {
findViewById(R.id.sign_in_button).setVisibility(View.GONE);
findViewById(R.id.sign_out_button).setVisibility(View.VISIBLE);
}
#Override
public void onSignInFailed() {
findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
findViewById(R.id.sign_out_button).setVisibility(View.GONE);
}
#Override
public void onClick(View v) {
}
#Override
public void onConnected(Bundle bundle) {
}
#Override
public void onConnectionSuspended(int i) {
}
#Override
public void onConnectionFailed(ConnectionResult connectionResult) {
}
}
GAMESCREEN
public class GameScreen extends BaseGameActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
private int c;
private GoogleApiClient mGoogleApiClient;
TextView counter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.game_screen);
setRequestedClients(BaseGameActivity.CLIENT_GAMES | BaseGameActivity.CLIENT_APPSTATE);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN)
.addApi(Games.API).addScope(Games.SCOPE_GAMES)
.build();
private void progressSetup() {
Thread timerThread = new
Thread() {
#Override
public void run() {
try {
while (mbActive && (waited < TIMER_RUNTIME)) {
sleep(THREAD_SLEEP);
if (mbActive) {
waited += 100;
updateProgress(waited);
if (waited > 9999) {
mbActive = false;
gameOver();
}
}
}
} catch (InterruptedException e) {
Log.d("fail", "failure" + e);
}
}
};
startTread = false;
timerThread.start();
}
private void updateProgress(final int timePassed) {
if (null != mProgressBar) {
progress = mProgressBar.getMax() * timePassed / TIMER_RUNTIME;
mProgressBar.setProgress(progress);
}
}
//game over
private void gameOver() {
runOnUiThread(new Runnable() {
#Override
public void run() {
upDateScore();
}
});
}
private void upDateScore(){
if (mGoogleApiClient.isConnected()) {
Games.Leaderboards.submitScore(mGoogleApiClient, getString(R.string.app_id), c);
Log.d("connectted.....................................................");
} else {
Log.d("not connectted.....................................................");
}
}
#Override
public void onBackPressed() {
Intent home = new Intent(GameScreen.this, MainActivity.class);
home.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(home);
}
#Override
public void onConnected(Bundle bundle) {
}
#Override
public void onConnectionSuspended(int i) {
}
#Override
public void onConnectionFailed(ConnectionResult connectionResult) {
}
#Override
public void onSignInFailed() {
}
#Override
public void onSignInSucceeded() {
}
}
Just replace getString(R.string.app_id) with your LEADERBOARD id in method Games.Leaderboards.submitScore(mGoogleApiClient, getString(R.string.app_id).
Leaderboard id looks like this: "CgkI0tXt-q0HEA****"
Ivan Syabro is right. You must use the LEADERBOARD_ID, see Leaderboards in Android - Updating the player's score.
In the developer console's game services section, you can easily export your leaderboard and achievements ids as xml files using the provided button.
In general, using the game services with more than one activity might cause additional waiting periods as each of them signs in individually at its start. Therefore, as far as I know, the implementation with fragments should be preferred, see this famous example playgameservices/android-basic-samples.

How to implement phonegap/cordova in android webview?

I need just a few minutes for someone to tell me if these steps are correct for implementing cordova in a android webview:
EDIT: Ok I finally got it working these are the right steps:
1) I create project: cordova create hello com.example.hello HelloWorld and enter the folder
2) cordova platform add android, cordova run android (cordova.jar is created) => the app is launched => device is ready is shown
3) I create a cordova_layout.xml in "/res/layout" with this code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<org.apache.cordova.CordovaWebView
android:id="#+id/cordova_web_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
</LinearLayout>
4)Import the project (as an "existing project" in eclipse) and add to the main java file after imports:
public class HelloWorld extends Activity implements CordovaInterface {
private CordovaWebView cordova_webview;
private String TAG = "CORDOVA_ACTIVITY";
private final ExecutorService threadPool = Executors.newCachedThreadPool();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cordova_layout);
cordova_webview = (CordovaWebView) findViewById(R.id.cordova_web_view);
// Config.init(this);
String url = "file:///android_asset/www/index.html";
cordova_webview.loadUrl(url, 10000);
}
#Override
protected void onPause() {
super.onPause();
Log.d(TAG, "onPause");
}
#Override
protected void onResume() {
super.onResume();
Log.d(TAG, "onResume");
}
#Override
protected void onDestroy() {
super.onDestroy();
if (this.cordova_webview != null) {
this.cordova_webview
.loadUrl("javascript:try{cordova.require('cordova/channel').onDestroy.fire();}catch(e){console.log('exception firing destroy event from native');};");
this.cordova_webview.loadUrl("about:blank");
cordova_webview.handleDestroy();
}
}
#Override
public Activity getActivity() {
return this;
}
#Override
public ExecutorService getThreadPool() {
return threadPool;
}
#Override
public Object onMessage(String message, Object obj) {
Log.d(TAG, message);
if (message.equalsIgnoreCase("exit")) {
super.finish();
}
return null;
}
#Override
public void setActivityResultCallback(CordovaPlugin cordovaPlugin) {
Log.d(TAG, "setActivityResultCallback is unimplemented");
}
#Override
public void startActivityForResult(CordovaPlugin cordovaPlugin,
Intent intent, int resultCode) {
Log.d(TAG, "startActivityForResult is unimplemented");
}
}
NOTE: the activity name must match the one in manifest.xml
Hope it will help you.
Have a nice day!
If you want to load an url in a phonegap app then you may use the below code to load your first url from asset
public class MyPhoneGapActivity extends DroidGap {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html", 10000);
}
For embedding a cordova webview in native android application and loading an url use the below code
public class CordovaActivity extends Activity implements CordovaInterface {
private CordovaWebView cordova_webview;
private String TAG = "CORDOVA_ACTIVITY";
private final ExecutorService threadPool = Executors.newCachedThreadPool();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cordova_layout);
cordova_webview = (CordovaWebView) findViewById(R.id.cordova_web_view);
// Config.init(this);
String url = "file:///android_asset/www/index.html";
cordova_webview.loadUrl(url, 10000);
}
#Override
protected void onPause() {
super.onPause();
Log.d(TAG, "onPause");
}
#Override
protected void onResume() {
super.onResume();
Log.d(TAG, "onResume");
}
#Override
protected void onDestroy() {
super.onDestroy();
if (this.cordova_webview != null) {
this.cordova_webview
.loadUrl("javascript:try{cordova.require('cordova/channel').onDestroy.fire();}catch(e){console.log('exception firing destroy event from native');};");
this.cordova_webview.loadUrl("about:blank");
cordova_webview.handleDestroy();
}
}
#Override
public Activity getActivity() {
return this;
}
#Override
public ExecutorService getThreadPool() {
return threadPool;
}
#Override
public Object onMessage(String message, Object obj) {
Log.d(TAG, message);
if (message.equalsIgnoreCase("exit")) {
super.finish();
}
return null;
}
#Override
public void setActivityResultCallback(CordovaPlugin cordovaPlugin) {
Log.d(TAG, "setActivityResultCallback is unimplemented");
}
#Override
public void startActivityForResult(CordovaPlugin cordovaPlugin,
Intent intent, int resultCode) {
Log.d(TAG, "startActivityForResult is unimplemented");
}
}

java.lang.ExceptionInInitializerError When call service

When i run my project from eclipse its working perfectly.
After created signed apk, i've tested on my device. its throws below exception.
FATAL EXCEPTION: main
java.lang.ExceptionInInitializerError
at com.rvg.app.aws.RegisterService.onCreate(Unknown Source)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2529)
My SplashScreen class
public class SplashActivity extends BaseFragmentActivity {
private boolean isDestroyed = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_spashscreen);
startRegisterService();
mHandler.sendEmptyMessageDelayed(1,4000l);
}
private void startRegisterService(){
if(!MyApplication.getSnsPreference().isRegistered()){
startService(new Intent(this, RegisterService.class));
}
}
#SuppressLint("HandlerLeak")
private Handler mHandler = new Handler(){
public void handleMessage(android.os.Message msg) {
if(msg.what == 1 && !isDestroyed){
Intent intent;
if(MyApplication.getUserPrefs().isLoggedIn()){
intent = new Intent(SplashActivity.this, HomeActivity.class);
}
else{
intent = new Intent(SplashActivity.this, WelcomeActivity.class);
}
startActivity(intent);
finish();
}
};
};
#Override
protected void onDestroy() {
isDestroyed = true;
super.onDestroy();
}
}
and my RegisterService class
public class RegisterService extends Service{
private PushRegister mRegister;
#Override
public void onCreate() {
super.onCreate();
mRegister = new PushRegister(this);
startRegister();
}
private void startRegister(){
new AsyncTask<Void, Void, Boolean>(){
#Override
protected Boolean doInBackground(Void... params) {
return mRegister.registerSns();
}
protected void onPostExecute(Boolean result) {
stopSelf();
}
}.execute();
}
#Override
public IBinder onBind(Intent intent) {
return null;
}
}
How to solve this.?
When run from eclipse there is no problem. After signed apk i've loaded on sd card and installed. When open the app it crash.
What is the issue and how to solve it?

Categories

Resources