How to implement Reward video with Startapp - java

Recently I'm facing issue related to Startapp platform for Android.
When I implemented the reward video it returns an error with:
FailledError execute Exception Error sendGetWithResponse code = [204]
Here is my function:
public void rewardAd() {
Log.i("TAG", "Test");
startAppAd.setVideoListener(new VideoListener() {
#Override
public void onVideoCompleted() {
Log.i("TAG", "Grant User");
}
});
startAppAd.loadAd(StartAppAd.AdMode.REWARDED_VIDEO, new AdEventListener() {
#Override
public void onReceiveAd(com.startapp.android.publish.adsCommon.Ad ad) {
startAppAd.showAd();
}
#Override
public void onFailedToReceiveAd(com.startapp.android.publish.adsCommon.Ad ad) {
Log.i("TAG", "Failled"+ ad.getErrorMessage());
startAppAd.showAd(new AdDisplayListener() {
#Override
public void adHidden(com.startapp.android.publish.adsCommon.Ad ad) {
Log.i("TAG", "adHidden");
}
#Override
public void adDisplayed(com.startapp.android.publish.adsCommon.Ad ad) {
Log.i("TAG", "adDisplayed");
}
#Override
public void adClicked(com.startapp.android.publish.adsCommon.Ad ad) {
Log.i("TAG", "adClicked");
}
#Override
public void adNotDisplayed(com.startapp.android.publish.adsCommon.Ad ad) {
Log.i("TAG", "adNotDisplayed"+ ad.getErrorMessage());
}
});
//startAppAd.showAd(getApplicationContext());
}
});
}
Here is the logs that shows:
TAG: Test
TAG: FailledError execute Exception Error sendGetWithResponse code = [204]
TAG: adNotDisplayed
When I comment the function startAppAd.showAd(), and uncomment the last commented one startAppAd.showAd(), it's working fine.
This is the expected working scheme:
Try to load a Video Reward Ad => startAppAd.loadAd();
if failed (like my case) => onFailedToReceiveAd();
Try to show an Ad that I can get listeners of it => startAppAd.showAd()
Thank You very much

It's solved, the script itself is not bad and works fine, the problem was with Startapp they don't show a video ad because it doesn't exist any video to show.
Now if someone is facing the same problem i suggest to use a vpn on testing device with a country that startapp should have a video ad usually US.

Related

Android Admob rewardedAd not showing rewarded ad

I'm using an admob rewardedAd and everything works fine but sometimes it doesn't show a video. Sometimes it shows a static ad like if it was an intersitial ad. It wouldn't be a problem, but when that happens and the user closes the app, onUserEarnedReward is not fired. Is there a way to force it to always show a rewarded video ad?
Here's the code where I load and prepare the callbacks for the ad:
rewardedAd = new RewardedAd(this, rewardKey);
RewardedAdLoadCallback adLoadCallback = new RewardedAdLoadCallback() {
#Override
public void onRewardedAdLoaded() { }
#Override
public void onRewardedAdFailedToLoad(int errorCode) {
rewardedAd = new RewardedAd(getApplicationContext(), rewardKey);
rewardedAd.loadAd(new AdRequest.Builder().build(), this);
}
};
adCallback = new RewardedAdCallback() {
#Override
public void onRewardedAdOpened() { }
#Override
public void onRewardedAdClosed() {
rewardedAd = new RewardedAd(getApplicationContext(), rewardKey);
rewardedAd.loadAd(new AdRequest.Builder().build(), adLoadCallback);
}
#Override
public void onUserEarnedReward(#NonNull RewardItem reward) {
/*
...
Give rewards to the user
...
*/
rewardedAd = new RewardedAd(getApplicationContext(), rewardKey);
rewardedAd.loadAd(new AdRequest.Builder().build(), adLoadCallback);
}
#Override
public void onRewardedAdFailedToShow(int errorCode) {
Toast.makeText(getApplicationContext(), getString(R.string.ad_error), Toast.LENGTH_LONG).show();
}
};
rewardedAd.loadAd(new AdRequest.Builder().build(), adLoadCallback);
Then I show it like:
rewardedAd.show(this, adCallback);
from your post it seems the issue does not happen all of the time. try not creating so many new instances of rewardedAd from this code you are calling it three times one should be enough rewardedAd = new RewardedAd(getApplicationContext(), rewardKey);
According to the the documentation there is no such thing as a static rewarded ad:
AdMob rewarded ads may be click-to-download video ads with an end
card that appears when the video ends or interactive ads, such as
playable ads or surveys.
Are you sure it's not showing an interactive ad such as a survey, where the user must answer a question to get the reward?

Own app is loading infinitely with Quickblox

I made an android app just like this tutorial :
[https://www.youtube.com/watch?v=5AhghMG9Y1I I can register and sign in without any problems but after logging in it stays forever in the screen "Loading" and it doesnt open the next activity where I can start chatting with other users. The android monitor says:
FATAL EXCEPTION: main
Process: com.example.georg.chatapp, PID: 31740
java.lang.NullPointerException: Attempt to invoke virtual method
'java.lang.String com.quickblox.users.model.QBUser.getLogin()' on a
null object reference
at
com.example.georg.chatapp.ListUsersActivity$4.onSuccess(ListUsersActivity.java:160)
at
com.example.georg.chatapp.ListUsersActivity$4.onSuccess(ListUsersActivity.java:149)
Here is the code where its linked to:
private void retrieveAllUsers() {
QBUsers.getUsers(null).performAsync(new QBEntityCallback<ArrayList<QBUser>>() {
#Override
public void onSuccess(ArrayList<QBUser> qbUsers, Bundle bundle) {
//add cache
QBUsersHolder.getInstance().putUsers(qbUsers);
ArrayList<QBUser> qbUserWithoutCurrent = new ArrayList<QBUser>();
for (QBUser user : qbUsers)
{
if (!user.getLogin().equals(QBChatService.getInstance().getUser().getLogin()))
qbUserWithoutCurrent.add(user);
}
ListUsersAdapter adapter = new ListUsersAdapter(getBaseContext(),qbUserWithoutCurrent);
lstUsers.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
#Override
public void onError(QBResponseException e) {
Log.e("ERROR",e.getMessage());
}
});
}
User Login:
private void createSessionForChat() {
final ProgressDialog mDialog = new ProgressDialog(ChatDialogsActivity.this);
mDialog.setMessage("Verbindung wird hergestellt");
mDialog.setCanceledOnTouchOutside(false);
mDialog.show();
String user,password;
user = getIntent().getStringExtra("user");
password = getIntent().getStringExtra("password");
final QBUser qbUser = new QBUser(user,password);
QBAuth.createSession(qbUser).performAsync(new QBEntityCallback<QBSession>() {
#Override
public void onSuccess(QBSession qbSession, Bundle bundle) {
qbUser.setId(qbSession.getUserId());
try {
qbUser.setPassword(BaseService.getBaseService().getToken());
} catch (BaseServiceException e) {
e.printStackTrace();
}
QBChatService.getInstance().login(qbUser, new QBEntityCallback() {
#Override
public void onSuccess(Object o, Bundle bundle) {
mDialog.dismiss();
}
#Override
public void onError(QBResponseException e) {
Log.e("ERROR",""+e.getMessage());
}
});
}
#Override
public void onError(QBResponseException e) {
}
});
}
I hope you have an idea how to solve it. I use QuickBlox as server.
When I press the "back" button while its loading the next activity with the floating button appears for some secconds and then it crashes.
It happen because no user is logged in to the chat (maybe logged to the REST but not to chat). In your case you need login to the chat before loading users, for it use QBChatService.getInstance().login(qbUser);
qbUser - QBUser with id, login and password.

Rewarded Videos doesn't load the first time but loads after

My App has a button to open reward videos >> when this button is pressed for the first time, it toasts "Check your Internet connection", when hit the second or third time, it shows the video with no problems
MobileAds.initialize(getActivity(), getString(R.string.VID_App_ID));
mRewardVideoAd = MobileAds.getRewardedVideoAdInstance(getActivity());
mRewardVideoAd.loadAd(getString(R.string.VID_App_Unit_ID), new AdRequest.Builder()
.addTestDevice(getString(R.string.TestDeviceID))
.build());
mRewardVideoAd.setRewardedVideoAdListener(this);
loadRewardedVideoAd();
Here are the methods used :
private void loadRewardedVideoAd() {
mRewardVideoAd.loadAd(getString(R.string.VID_App_Unit_ID), new AdRequest.Builder()
.addTestDevice(getString(R.string.TestDeviceID))
.build());
}
#OnClick(R.id.button_more_money)
public void more_money() {
if (mRewardVideoAd.isLoaded()) {
mRewardVideoAd.show();
} else
{
Toast.makeText(getActivity(), "Check your internet connection", Toast.LENGTH_LONG).show();
loadRewardedVideoAd();
}
}
#Override
public void onResume() {
mRewardVideoAd.resume(getActivity());
super.onResume();
loadRewardedVideoAd();
}
Edit: Solved
- It took some time and the solution was to load at onCreate()
Thanks to Martin De Simone and Avi Levin
Rewarded videos take time to load, your code is fine, the first time you are pressing, the video is loading and then when you press probably the video has already loaded.
Try to toast something in the onAdLoaded to check this
As Martin said, RV ad takes a time to load. basically, it needs to download ~30-second video which takes sometimes few second.
I recommend using the SDK provided RewardedVideoAdListener interface which will help you know when the ad is ready to show. furthermore, it will help you to understand the AdMob rewarded video ad's life cycle.
In order to use it you need to do the following phases:
Implement RewardedVideoAdListener listener in your java class
Override the following methods (I used Toast UI messages for visualization, it can be deleted)
Code:
#Override
public void onRewarded(RewardItem reward) {
Toast.makeText(this, "onRewarded! currency: " + reward.getType() + " amount: " +
reward.getAmount(), Toast.LENGTH_SHORT).show();
}
#Override
public void onRewardedVideoAdLeftApplication() {
Toast.makeText(this, "onRewardedVideoAdLeftApplication",
Toast.LENGTH_SHORT).show();
}
#Override
public void onRewardedVideoAdClosed() {
Toast.makeText(this, "onRewardedVideoAdClosed", Toast.LENGTH_SHORT).show();
}
#Override
public void onRewardedVideoAdFailedToLoad(int errorCode) {
Toast.makeText(this, "onRewardedVideoAdFailedToLoad", Toast.LENGTH_SHORT).show();
}
#Override
public void onRewardedVideoAdLoaded() {
Toast.makeText(this, "onRewardedVideoAdLoaded", Toast.LENGTH_SHORT).show();
}
#Override
public void onRewardedVideoAdOpened() {
Toast.makeText(this, "onRewardedVideoAdOpened", Toast.LENGTH_SHORT).show();
}
#Override
public void onRewardedVideoStarted() {
Toast.makeText(this, "onRewardedVideoStarted", Toast.LENGTH_SHORT).show();
}
BTW: before a show call, I recommend using isLoaded() method in order to if the AdMob is ready to show something, for example:
if (mAd.isLoaded()) {
mAd.show();
}
More information can be found inside Google AdMob doc's

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

Exception "Can't create handler inside thread that has not called looper prepare" in android app

I'm working on my first android app and I'm trying to use Quickblox.com as my backend.
In order to use it, I need to authorize the app by creating a session using their SDK.
So, I have the following code:
// Initialize QuickBlox application with credentials.
QBSettings.getInstance().fastConfigInit(Consts.APP_ID, Consts.AUTH_KEY, Consts.AUTH_SECRET);
// Authorize application
QBAuth.createSession(new QBCallback() {
#Override public void onComplete(Result result) {}
#Override
public void onComplete(Result result, Object context) {
if (result.isSuccess()) {
showMainScreen();
} else {
// print errors that came from server
Toast.makeText(getBaseContext(), result.getErrors().get(0), Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.INVISIBLE);
}
}
}, QBQueries.QB_QUERY_AUTHORIZE_APP);
This code works well with an emulator, but it doesn't work if I try with a real android phone. I have a connection timeout error. I think I need to make this kind of requests (Web Services) in the background right?
So I tried to use the AsyncTask to make the request to QB in the background, and changed the code to this:
new AsyncTask<Void, Void, Void>() {
#Override
protected Void doInBackground(Void... params) {
// Initialize QuickBlox application with credentials.
QBSettings.getInstance().fastConfigInit(Consts.APP_ID, Consts.AUTH_KEY, Consts.AUTH_SECRET);
// Authorize application
QBAuth.createSession(new QBCallback() {
#Override public void onComplete(Result result) {}
#Override
public void onComplete(Result result, Object context) {
if (result.isSuccess()) {
showMainScreen();
} else {
// print errors that came from server
Toast.makeText(getBaseContext(), result.getErrors().get(0), Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.INVISIBLE);
}
}
}, QBQueries.QB_QUERY_AUTHORIZE_APP);
return null;
}
}.execute();
I've seen a lot of similar questions here at SO, but I can't seem to find an answer that works with my code. I saw that functions that deal with the UI need to be called from the main thread, so I suppose that the code I have inside
onComplete(Result result, Object context)
should be inside a block like this right?
runOnUiThread(new Runnable()
{
public void run()
{
// code here
}
});
But I tried that as well and it didn't work. Any guesses?
I believe the problem is not because of the Toast and showMainScreen(). It still fails with this code:
// Initialize QuickBlox application with credentials.
QBSettings.getInstance().fastConfigInit(Consts.APP_ID, Consts.AUTH_KEY, Consts.AUTH_SECRET);
QBAuth.createSession(new QBCallback() {
#Override
public void onComplete(Result arg0, Object arg1) {
// TODO Auto-generated method stub
}
#Override
public void onComplete(Result arg0) {
// TODO Auto-generated method stub
}
}, QBQueries.QB_QUERY_AUTHORIZE_APP);
But it doesn't fail if I just create the QBCallback object, without passing it to the QBAuth.createSession function.
You can't show a Toast in doInBackground of AsyncTask as it is a different threat and not the main UI thread.
To show a toast or any UI related task you have to do it in onPostExecute method of AsyncTask.
What you can do is
new AsyncTask<Void, Void, boolean>() {
#Override
protected boolean doInBackground(Void... params) {
// Initialize QuickBlox application with credentials.
QBSettings.getInstance().fastConfigInit(Consts.APP_ID, Consts.AUTH_KEY, Consts.AUTH_SECRET);
boolean res = false;
// Authorize application
QBAuth.createSession(new QBCallback() {
#Override public void onComplete(Result result) {}
#Override
public void onComplete(Result result, Object context) {
if (result.isSuccess()) {
//showMainScreen();
res = true
}
//else {
// print errors that came from server
//Toast.makeText(getBaseContext(), result.getErrors().get(0), //Toast.LENGTH_SHORT).show();
//progressBar.setVisibility(View.INVISIBLE);
//}
}
}, QBQueries.QB_QUERY_AUTHORIZE_APP);
return res;
}
protected void onPostExecute(boolean result) {
if(result) {
showMainScreen();
} else {
Toast.makeText(getBaseContext(), result.getErrors().get(0), Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.INVISIBLE);
}
}
}.execute();
You don't need to use AsyncTasks, because all operations already perform in background.
And also this one
QBAuth.createSession(new QBCallback() {
it performs request in background to QB and call callback in Main thread.
Could you explain what 'connection timeout error' you got.
Is there anything in log?

Categories

Resources