White patches while GameCircle Integration in Cocos2d Android - android

I am integrating Game Circle SDK & Whisper Sync in my game. I have implemented the code, but it has caused an issue. When I load the game and get the game state from the WhisperSync and set my local variables, white patches are observed in some places randomly instead of the proper image. When I turn of GameCircle & Whisper Sync it runs fine.
My game is developed using Cocos2d Android.
Does any one encountered such issue?
I have attached the image for reference.
Some Code:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
CCGLSurfaceView _glSurfaceView = new CCGLSurfaceView(this);
setContentView(_glSurfaceView);
CCDirector.sharedDirector().attachInView(_glSurfaceView);
CCDirector.sharedDirector().setDisplayFPS(false);
CCDirector.sharedDirector().setAnimationInterval(1.0f / 60.0f);
CCScene scene = IntroLayer.scene();
CCDirector.sharedDirector().runWithScene(scene);
}
#Override
public void onResume() {
super.onResume();
if (IS_AMAZON) {
AmazonGamesClient.initialize(this, callback, myGameFeatures);
AmazonGamesClient.getWhispersyncClient()
.setWhispersyncEventListener(
new WhispersyncEventListener() {
#Override
public void onAlreadySynchronized() {
// TODO Auto-generated method stub
super.onAlreadySynchronized();
System.out
.println("FA here onAlreadySynchronized");
loadGameScene();
}
#Override
public void onDataUploadedToCloud() {
// TODO Auto-generated method stub
super.onDataUploadedToCloud();
System.out
.println("FA here onDataUploadedToCloud");
}
#Override
public void onDiskWriteComplete() {
// TODO Auto-generated method stub
super.onDiskWriteComplete();
System.out
.println("FA here onDiskWriteComplete");
}
#Override
public void onFirstSynchronize() {
// TODO Auto-generated method stub
super.onFirstSynchronize();
System.out
.println("FA here onFirstSynchronize");
loadGameScene();
}
#Override
public void onNewCloudData() {
// TODO Auto-generated method stub
super.onNewCloudData();
System.out
.println("FA here onNewCloudData");
}
#Override
public void onSyncFailed(FailReason reason) {
// TODO Auto-generated method stub
super.onSyncFailed(reason);
System.out
.println("FA here onSyncFailed reason: "
+ reason.name());
}
#Override
public void onThrottled() {
// TODO Auto-generated method stub
super.onThrottled();
System.out.println("FA here onThrottled");
}
});
Log.i(TAG, "onResume: call initiateGetUserIdRequest");
PurchasingManager.initiateGetUserIdRequest();
Log.i(TAG, "onResume: call initiateItemDataRequest for skus: "
+ LAppInfo.getInstance().getList());
Set<String> skus = new HashSet<String>(LAppInfo.getInstance()
.getList());
PurchasingManager.initiateItemDataRequest(skus);
}
CCDirector.sharedDirector().resume();
}
private AmazonGamesCallback callback = new AmazonGamesCallback() {
#Override
public void onServiceNotReady(AmazonGamesStatus status) {
// unable to use service
System.out.println("FA here callback onServiceNotReady: "
+ status.name());
}
#Override
public void onServiceReady(AmazonGamesClient amazonGamesClient) {
System.out.println("FA here callback onServiceReady: ");
agsClient = amazonGamesClient;
}
};
private void loadGameScene() {
LoadData();
CCScene mainMenu = LevelMenuScene.scene();
CCDirector.sharedDirector().replaceScene(
CCFadeTransition.transition(0.5f, mainMenu));
}

Solved it by a work around by having a boolean variable and set it to true after the data is loaded in firstsync/alreadysync method. and loading the scene in the main thread instead of the callback of whispersync. Will be glad to know if some one find a proper solution.

Related

Web View running on other than UI thread

I am trying to show flurry interstitial but getting following message in debug screen and I am not receiving interstitial on my screen.
07-14 15:55:31.390: W/webview(10588): java.lang.Throwable: Warning: A
WebView method was called on thread 'FlurryAgent'. All WebView methods
must be called on the UI thread. Future versions of WebView may not
support use on other threads.
I have followed this tutorial completely :
Android Integration
At present I am working on AndEngine. As error replying I put my all code in UI thread but result is same.
Here is my code for displaying ads :
protected void onCreate(Bundle pSavedInstanceState) {
super.onCreate(pSavedInstanceState);
// configure Flurry
FlurryAgent.setLogEnabled(false);
// init Flurry
FlurryAgent.init(MainGameActivity.this, MY_FLURRY_APIKEY);
mFlurryAdInterstitial = new FlurryAdInterstitial(MainGameActivity.this,
MY_ADSPACE_NAME);
FlurryAdTargeting adTargeting = new FlurryAdTargeting();
// enable test mode for this interstitial ad unit
adTargeting.setEnableTestAds(true);
mFlurryAdInterstitial.setTargeting(adTargeting);
// allow us to get callbacks for ad events
mFlurryAdInterstitial.setListener(interstitialAdListener);
mFlurryAdInterstitial.fetchAd();
}
FlurryAdInterstitialListener interstitialAdListener = new FlurryAdInterstitialListener() {
#Override
public void onFetched(final FlurryAdInterstitial adInterstitial) {
adInterstitial.displayAd();
}
#Override
public void onError(final FlurryAdInterstitial adInterstitial,
FlurryAdErrorType adErrorType, int errorCode) {
adInterstitial.destroy();
}
#Override
public void onAppExit(FlurryAdInterstitial arg0) {
// TODO Auto-generated method stub
}
#Override
public void onClicked(FlurryAdInterstitial arg0) {
// TODO Auto-generated method stub
}
#Override
public void onClose(FlurryAdInterstitial arg0) {
// TODO Auto-generated method stub
}
#Override
public void onDisplay(FlurryAdInterstitial arg0) {
// TODO Auto-generated method stub
}
#Override
public void onRendered(FlurryAdInterstitial arg0) {
// TODO Auto-generated method stub
}
#Override
public void onVideoCompleted(FlurryAdInterstitial arg0) {
// TODO Auto-generated method stub
}
};
#Override
protected void onStart() {
super.onStart();
FlurryAgent.onStartSession(MainGameActivity.this);
}
#Override
protected void onStop() {
super.onStop();
FlurryAgent.onEndSession(MainGameActivity.this);
}
#Override
public void onDestroy() {
super.onDestroy();
mFlurryAdInterstitial.destroy();
}
So what can I do in this situation?

how to place ads in admob in app

how to use ad-mob in app and what are the steps how i post ads in ad-mob how can i test in my device before uploading to Google play store.i am new to ad-mob. please explain me with sample example of it by step-wise.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.interstitialAds = new InterstitialAd(this, "ca-app-pub-****");
this.interstitialAds.setAdListener(this);
Button loadButton = (Button) this.findViewById(R.id.loadButton);
loadButton.setOnClickListener(loadButtonOnClick);
this.textView = (TextView) this.findViewById(R.id.stateTextView);
}
private OnClickListener loadButtonOnClick = new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
textView.setText("Loading Intertitial Ads");
AdRequest adr = new AdRequest();
// add your test device here
adr.addTestDevice(AdRequest.TEST_EMULATOR);
interstitialAds.loadAd(adr);
}
};
#Override
public void onDismissScreen(Ad arg0) {
// TODO Auto-generated method stub
}
#Override
public void onFailedToReceiveAd(Ad ad, ErrorCode error) {
String message = "Load Ads Failed: (" + error + ")";
textView.setText(message);
}
#Override
public void onLeaveApplication(Ad arg0) {
// TODO Auto-generated method stub
}
/**
* Called when an Activity is created in front of the app (e.g. an
* interstitial is shown, or an ad is clicked and launches a new Activity).
*/
#Override
public void onPresentScreen(Ad arg0) {
// TODO Auto-generated method stub
}
#Override
public void onReceiveAd(Ad arg0) {
if (interstitialAds.isReady()) {
interstitialAds.show();
} else {
textView.setText("Interstitial ad was not ready to be shown.");
}
}
}
Get rid of your AdListener.
Call intersitial.loadAd in your constructor
Call interstitial.show at a natural break point in your app
Call interstitial.loadAd
Go to 3.
See https://developers.google.com/mobile-ads-sdk/docs/admob/android/interstitial

How to keep voice recognition while device is asleep?

I was wondering, how can I keep the device listening for voice commands with voice recognition while the device is asleep? The idea I have is that I would like the device to respond to my voice, even if I have the screen locked or the screen has timed out.
Is this possible? I have tried using this as a service and an interface and it stops listening once the screen locks. Can I receive any help with this? This is my class.
public class VoiceEngineService extends Activity {
private boolean isSpeakingDone = false; // default setting
private SpeechRecognizer sr = SpeechRecognizer.createSpeechRecognizer(this);
private AudioManager mAudioManager;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.wait_for_speech);
// mute beep sound
mAudioManager.setStreamSolo(AudioManager.STREAM_VOICE_CALL, true);
sr.setRecognitionListener(new listener());
Intent i = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); // LANGUAGE_MODEL_WEB_SEARCH
i.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getApplication()
.getClass().getName());
i.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 6);
i.putExtra(RecognizerIntent.EXTRA_PROMPT, "");
i.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, 5500);
sr.startListening(i);
}
class listener implements RecognitionListener {
#Override
public void onReadyForSpeech(Bundle params) {
// TODO Auto-generated method stub
}
#Override
public void onBeginningOfSpeech() {
// TODO Auto-generated method stub
}
#Override
public void onRmsChanged(float rmsdB) {
// TODO Auto-generated method stub
}
#Override
public void onBufferReceived(byte[] buffer) {
// TODO Auto-generated method stub
}
#Override
public void onEndOfSpeech() {
// TODO Auto-generated method stub
}
#Override
public void onError(int error) {
// TODO Auto-generated method stub
if (SharedPref.getVoiceController() == false) {
sr.cancel();
Intent i = new Intent();
sr.startListening(i);
} else {
sr.stopListening();
sr.destroy();
finish();
}
}
#Override
public void onResults(Bundle results) {
// TODO Auto-generated method stub
isSpeakingDone = true;
ArrayList<String> mDataList = results
.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
Intent i = new Intent();
i.putStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS, mDataList);
setResult(RESULT_OK, i);
finish();
}
#Override
public void onPartialResults(Bundle partialResults) {
// TODO Auto-generated method stub
}
#Override
public void onEvent(int eventType, Bundle params) {
// TODO Auto-generated method stub
}
} // end listener class
#Override
protected void onPause() {
if ((isSpeakingDone == false)) {
finish();
}
super.onPause();
}
#Override
protected void onStop() {
// when speaking is true finish() has already been called
if (isSpeakingDone == false) {
finish();
}
super.onStop();
}
#Override
protected void onDestroy() {
sr.stopListening();
sr.destroy();
super.onDestroy();
}
}
You have to implement your voice listener in a service. Create a class that extends 'Service' and make up some logic to take care of recording.
If you tried already the service, then it might be that you tried to redirect commands to an activity which most likely has been stopped by Android OS. Generally when talking about doing stuff when phone is in lock mode, you only can hope to accomplish tasks in one or more services coupled togethe.
When you are in Activity, of course wen the activity goes out of scope it will be shut down by Android OS. but services can still run in background unless shut dow mm explicitly by your own code or in rare cases that Android will recognize that it needs memory and processor power for other tasks.

How to keep playing YouTubePlayer in Android

Now I'm creating an Android application witch use YouTube api to play Video.
But the player stop when I change Activity.
I want to keep Playing like a Music Player even when Activity will change.
I try to solve that by adding Static on YouTubePlayer.(But cannot solve.)
I mean I want to Keep it's playing when the Activity or the Application itself move to Background.
So if you have any ideas, please share with me :)
-----------------Code-----------------
public class PlayActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener,YouTubePlayer.PlayerStateChangeListener{
public static final String DEVELOPER_KEY = "My_Dev_Key";
private LinearLayout yPos;
private static YouTubePlayer yt;
private YouTubePlayerView ytp;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.play);
yPos = (LinearLayout)findViewById(R.id.youtube_pos);
try{
ytp = new YouTubePlayerView(this);
ytp.initialize(DEVELOPER_KEY, this);
}catch(Exception e){
finish();
}
yPos.addView(ytp);
}
#Override
public void onAdStarted() {
// TODO Auto-generated method stub
}
#Override
public void onError(ErrorReason arg0) {
// TODO Auto-generated method stub
}
#Override
public void onLoaded(String arg0) {
// TODO Auto-generated method stub
}
#Override
public void onLoading() {
// TODO Auto-generated method stub
}
#Override
public void onVideoEnded() {
// TODO Auto-generated method stub
}
#Override
public void onVideoStarted() {
// TODO Auto-generated method stub
}
#Override
public void onInitializationFailure(Provider arg0,
YouTubeInitializationResult arg1) {
// TODO Auto-generated method stub
}
#Override
public void onInitializationSuccess(Provider arg0, YouTubePlayer arg1,
boolean arg2) {
// TODO Auto-generated method stub
if(!arg2){
if(yt == null){
yt = arg1;
yt.setPlayerStateChangeListener(this);
yt.setPlayerStyle(YouTubePlayer.PlayerStyle.DEFAULT);
yt.loadVideo("u0v5A6cQOhs");
}
}
}
}

LibGdx - need help on Screen class

I've been using libgdx for the past 3 weeks..
I created two screens referencing to a game:
public class Game extends Game {
TitleScreen titleScreen;
SplashScreen splashScreen;
#Override
public void create() {
// TODO Auto-generated method stub
titleScreen = new TitleScreen(this);
splashScreen = new SplashScreen(this);
setScreen(splashScreen);
}
}
and
public class SplashScreen implements Screen {
Game game;
public SplashScreen(Game game) {
// TODO Auto-generated constructor stub
this.game = game;
}
#Override
public void show() {
// TODO Auto-generated method stub
}
#Override
public void hide() {
// TODO Auto-generated method stub
}
#Override
public void render(float delta) {
// TODO Auto-generated method stub
Gdx.gl.glClearColor(0.5f, 1f, 1f, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
if(Gdx.input.justTouched()){
game.splashScreen.dispose();
game.setScreen(game.titlescreen);
}
}
#Override
public void resize(int width, int height) {
// TODO Auto-generated method stub
}
#Override
public void pause() {
// TODO Auto-generated method stub
}
#Override
public void resume() {
// TODO Auto-generated method stub
}
#Override
public void dispose() {
// TODO Auto-generated method stub
}
How do I dispose the splashscreen entirely? When I called the game.setscreen(game.splashscreen) in titlescreen class, it resume the splashscreen;. I'm expecting to set a new splashscreen..
Create a new splash screen every time you want to show a splash from the beginning:
game.setScreen(new SplashScreen(game));

Categories

Resources