I want to increment when finish watching video ads .I am calling startRevMobSession()
function on button click , but it increment also when there is no video available.. anyone please tell me its correct implementation.
I am using Android Studio
Double counter = 0.0;
Double adding = 0.0005;
String strCounter;
SharedPreferences sharedpreferences;
RevMob revmob;
RevMobFullscreen video;
private boolean videoIslodaded;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video1);
}
public void startRevMobSession() {
videoIslodaded = false;
//RevMob's Start Session method:
revmob = RevMob.startWithListener(this, new RevMobAdsListener() {
@Override
public void onRevMobSessionStarted() {
loadVideo(); //Cache the video once the session is stared
}
@Override
public void onRevMobSessionNotStarted(String message) {
//If the session fails, no ad will be displayed.
}
},"<YOUR_APP_ID>");
}
public void loadVideo(){
video = revmob.createVideo(this,new RevMobAdsListener(){
@Override
public void onRevMobVideoLoaded() {
videoIslodaded = true; //Video ready to be displayed
showVideo();
}
@Override
public void onRevMobVideoStarted() {
videoIslodaded = false;
}
@Override
public void onRevMobAdNotReceived(String message) {
videoIslodaded = false; //Ad failed to load;
}
});
}
public void showVideo(){
if(videoIslodaded) video.showVideo();
}
public void watch1_btn(View view){
startRevMobSession();
sharedpreferences = getSharedPreferences("MyPREFERENCES", Context.MODE_PRIVATE);
counter = Double.longBitsToDouble(sharedpreferences.getLong("key",Double.doubleToLongBits(0)));
counter = counter+adding;
strCounter = Double.toString(counter);
sharedpreferences = getSharedPreferences("MyPREFERENCES", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putLong("key", Double.doubleToRawLongBits(counter));
editor.commit();
}
}