Opens hundreds of tabs on single ad-click - java

listener = new RevMobAdsListener() {
#Override
public void onRevMobAdClicked() {
Log.i("[RevMob]", "Advertisement Clicked!");
revmob.openAdLink(application, APPLICATION_ID, this);
return;
}
#Override
public void onRevMobAdDismiss() {
Log.i("[RevMob]", "Advertisement Closed!");
fullscreenAd.hide();
}
#Override
public void onRevMobAdDisplayed() {
Log.i("[RevMob]", "Advertisement Displayed!");
}
#Override
public void onRevMobAdNotReceived(String message) {
Log.i("[RevMob]", "No Advertisement Available!");
}
#Override
public void onRevMobAdReceived() {
Log.i("[RevMob]", "Advertisement Pulled from network!");
}
#Override
public void onRevMobSessionIsStarted() {}
#Override
public void onRevMobSessionNotStarted(String arg0) {}
};
So what the problem is, is that once I click on the advertisement it continuously opens tabs in my browser.
LogCat spams the following debug messages. (In order)
Advertisment Pulled from network!
Advertisement Displayed!
Reporting impression using testing mode: with_ads
Advertisement Clicked!
^The above is apmmed on repeat, everytime it opens a new tab

Look at your first listener (onRevMobAdClicked): when you click the first ad, this listener is called, and it calls an adlink.
By default (from RevMob SDK), when called (openAdLink), the link calls automatically onRevMobAdReceived, onRevMobAdDisplayed and onRevMobAdClicked listeners.
Then, this adlink is opened and it fires this same listener (onRevMobAdClicked), calling again the adlink, which will fire the listener, which will call again the adlink, ..........
You have to change the way you call the link.
Also, you don't need to call fullscreen.hide() in onRevMobAdDismiss. When the fullscreen is dismissed by the user, this event is fired.
Hope that helps!

Related

Android Java: Speech Recognition App crashes whenever there are no results

I am developing an Android app that uses the Google speech recognition api. For some reason, when I start up the app (via USB debugging on my Android phone), starting the listening process works just fine, and the app works smoothly if I do actually say something after clicking the button to make the app start listening for audio. However, if I click the button to start listening, and then I don't say anything, then the app crashes for some reason. In other words, if the speech recognition gets no results, then the app just crashes. Does anyone have any idea as to why?
Below is an excerpt of my code. (Yes, I did account for the permissions. I just didn't include that code in the excerpt below).
I have tried putting try catch blocks in various places to see if I could catch the error that causes the crash, but it has yet to work. Furthermore, while there is an onResults method, there does not seem to be an onNoResults method.
speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
recognitionListener = new RecognitionListener() {
#Override
public void onReadyForSpeech(Bundle params) {
// Called when the speech recognition process is ready to begin
}
#Override
public void onBeginningOfSpeech() {
// Called when the user begins speaking
}
#Override
public void onRmsChanged(float rmsdB) {
// Called when the volume of the spoken input changes
}
#Override
public void onBufferReceived(byte[] buffer) {
// Called when the app receives a buffer of audio data
}
#Override
public void onEndOfSpeech() {
// Called when the user stops speaking
}
#Override
public void onError(int error) {
// Called when an error occurs during the speech recognition process
TextView textView = findViewById(R.id.errors);
textView.setText(error);
}
#Override
public void onResults(Bundle results) {
// Called when the speech recognition process has completed and the results are available
List<String> resultList = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
if (resultList != null && resultList.size() > 0) {
// Display the first result in the text field
TextView textView = findViewById(R.id.spokenWords);
textView.setText(resultList.get(0));
}
//speechRecognizer.startListening(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH));
}
#Override
public void onPartialResults(Bundle partialResults) {
// Called when the app receives partial results of the speech recognition process
}
#Override
public void onEvent(int eventType, Bundle params) {
// Called when the app receives other events from the speech recognition process
}
};
speechRecognizer.setRecognitionListener(recognitionListener);
Button startSpeech = findViewById(R.id.startSpeech);
startSpeech.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
TextView textView = findViewById(R.id.spokenWords);
textView.setText("Listening");
speechRecognizer.startListening(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH));
}
});

WearableListenerService only handles onMessageReceived() on second try

I've got a simple Android Wear demo to illustrate the Message API. I'm capturing input on a watch and passing it off to a handheld device for cloud processing, so the following class that extends WearableListenerService is running on a phone:
public class ListenerService extends WearableListenerService {
private static final String MESSAGE_PATH = "/handle-inbound-message";
#Override
public void onMessageReceived(MessageEvent messageEvent) {
super.onMessageReceived(messageEvent);
if(messageEvent.getPath().equals(MESSAGE_PATH)) {
updateData(new String(messageEvent.getData()));
}
}
private void updateData(final String volume) {
new Thread(new Runnable() {
#Override
public void run() {
// do neat stuff with the inbound data
}
}).start();
}
}
...and the wearable code generating the message, by way of clicking a button on the wearable app, is like so:
private void sendToHandheld(final byte[] volume) {
if(nodeId != null) {
new Thread(new Runnable() {
#Override
public void run() {
client.blockingConnect(CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS);
Wearable.MessageApi.sendMessage(client, nodeId, MESSAGE_PATH, volume);
client.disconnect();
}
}).start();
}
}
The code works fine...except for the fact that I have to click the button twice in the wearable app to get onMessageReceived() to fire. The app starts up, but doesn't get the message the first time...with the app still open, I click the button again and it fires perfectly. Can anyone see where I might have made a mistake?
(Also, I'm seeing a lot of code demos a repos where people don't call super.onMessageReceived().)
OK, I think I solved the issue - I commented-out the line in onMessageReceived() where the superclass is called...and that fixed it.
SUCCESS!

Android - Getting data out of Startapp

I use Startapp as my ad network in my applications and I need to be able to handle when a user clicks on an ad. I could not find any documentation for this function, and I would rather use onPause() because other things might pause the activity. Help would be appreciated!
Try this:
YourStartAppAd.showAd(new AdDisplayListener() {
#Override
public void adHidden(Ad ad) {
}
#Override
public void adDisplayed(Ad ad) {
}
#Override
public void adClicked(Ad ad) {
}
});
https://github.com/StartApp-SDK/Documentation/wiki/android-advanced-usage

libgdx: InputAdapter does not work when resumed from browser

I have a Screen implementation with InputMultiplexer which is initialized in the show() method. The InputMultiplexer is initialized with InputAdapter and the Stage object.
The InputAdapter object listens for the back button.
class MyInputAdapter extends InputAdapter {
#Override
public boolean keyDown(int keycode) {
if (keycode == Keys.BACK) {
// do someting
return true;
}
return false;
}
}
class MyScreen implements Screen {
#Override
public void show() {
initInputProcessors();
}
private void initInputProcessors() {
if (backButtonInputProcessor != null) {
initInputMultiplexer();
Gdx.input.setCatchBackKey(true);
Gdx.input.setInputProcessor(inputMiltiplexer);
} else {
Gdx.input.setCatchBackKey(false);
Gdx.input.setInputProcessor(stage);
}
}
private void initInputMultiplexer() {
if (inputMiltiplexer == null) {
inputMiltiplexer = new InputMultiplexer();
inputMiltiplexer.addProcessor(backButtonInputProcessor);
inputMiltiplexer.addProcessor(stage);
}
}
}
All works fine, and the back button reacts without any problem.
The problem occurs, in the following scenario. I use admob. So when clicking an ad banner, this brings you to browser. When you are back from browser to the app, the back button is not intercepted and the application just exits.
I also tried calling the InitInputProcessors method inside the resume() method, same result.
The answer to my question on LibGDX forum has solved it. Following is the solution by skunktrader:
Try adding this to your android MainActivity
#Override
public void onResume() {
super.onResume();
theView.requestFocus();
theView.requestFocusFromTouch();
}
Where theView is the value returned from initializeForView().
Try to set your InputProcessor as null in hide() method. Like this:
#Override
public void hide() {
Gdx.input.setInputProcessor(null);
}

Observing an event in roboguice application in a custom view

Basing on the RoboGuice API for firing an event, inside my CustomButtonView implementation I have did like so:
#Override
public void onClick(View v) {
CommonApplication.getInstance().fireEvent(new InteractionButtonClicked());
// setSelected();
}
public class InteractionButtonClicked
{
public String getRef()
{
return (String)getTag();
}
}
// handle the click event
protected void handleClick(#Observes InteractionButtonClicked button) {
if (getTag().equals(button.getRef())) {
//do A
} else {
//do B
}
}
However, handleClick does not get called in this context=> when I set an #Observer in the main activity it's containing method does get called.
I'm trying to understand why, and if there is an option to observe the event in the Customview context...

Categories

Resources