Problem : Whenever I run application on a new mobile, my ad loads and runs perfectly where I want it to run. But after that on same mobile ad video doesn't play, even after I un-install my application and install again.
I don't want to show ads on my main activity, but I want to load ads in that activity. That's why I have added this in my main activity class
implements AdColonyAdListener, AdColonyAdAvailabilityListener
and override its methods like this.
#Override
public void onAdColonyAdAvailabilityChange(boolean isAvailable, String arg1) {
AdColonyHelper.isAdvAvailable = isAvailable;
}
#Override
public void onAdColonyAdAttemptFinished(AdColonyAd arg0) {
}
#Override
public void onAdColonyAdStarted(AdColonyAd arg0) {
}
To track the availability of ad I have a static boolean variable in my AdColonyHelper class. AdColony Helper class:
package Helpers;
import android.app.Activity;
import com.jirbo.adcolony.AdColonyAdListener;
import com.jirbo.adcolony.AdColonyVideoAd;
public class AdColonyHelper {
public static boolean isAdvAvailable = false;
public static String APP_ID;
public static String ZONE_ID;
static Activity act = new Activity();
public static void setting(String appid, String zoneId, Activity myAct)
{
APP_ID = appid;
ZONE_ID = zoneId;
act = myAct;
}
public static void showAdv(boolean isAvailable)
{
isAdvAvailable = isAvailable;
if(isAdvAvailable)
{
AdColonyVideoAd ad = new AdColonyVideoAd(ZONE_ID);//.withListener( (AdColonyAdListener) act );
ad.show();
}
}
public static void showAdv()
{
if(isAdvAvailable)
{
AdColonyVideoAd ad = new AdColonyVideoAd(ZONE_ID).withListener( (AdColonyAdListener) act );
ad.show();
}
}
}
in on create of my main activity I initialize it like this
AdColony.configure( this, "version:1.0,store:google", APP_ID, ZONE_ID );
AdColony.addAdAvailabilityListener(this);
if ( !AdColony.isTablet() )
{
setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_PORTRAIT );
}
// below line is to set static variables in class
AdColonyHelper.setting(APP_ID, ZONE_ID, this);
This is all what I have done for ads in my main activity. Now right after going to my second Activity. I have this in on create method of that activity.
AdColonyHelper.showAdv();
This checks the availability of ad and plays it. But it plays ad just only one time.
But I continuously see this in my logcat
01-08 14:12:15.579: I/AdColony(23623): Finished downloading:
01-08 14:12:15.609: I/AdColony(23623): https://androidads21.adcolony.com/configure?......
Related
I want to show ads in a service. google admob works well because it needs context, but some other ad services like unity ads, adcolony, appodeal need activity context.
How can I provide activity context in a service. I think create an Activity will works but ads need some time to load the ad and then show so create a blank activity and show it.
For unity:
UnityAds.initialize(this, "xxxxxxx", new IUnityAdsListener() {
#Override
public void onUnityAdsReady(String s) {
Timber.e("onUnityAdsReady");
}
#Override
public void onUnityAdsStart(String s) {
Timber.e("onUnityAdsStart");
}
#Override
public void onUnityAdsFinish(String s, UnityAds.FinishState finishState) {
Timber.e("onUnityAdsFinish");
}
#Override
public void onUnityAdsError(UnityAds.UnityAdsError unityAdsError, String s) {
Timber.e("onUnityAdsError");
}
});
For adclony:
AdColony.configure(this, "xxxx", "xxx");
adColonyInterstitialListener = new AdColonyInterstitialListener() {
#Override
public void onRequestFilled(AdColonyInterstitial ad) {
adColonyInterstitial = ad;
/** Store and use this ad object to show your ad when appropriate */
}
};
AdColony.requestInterstitial("xxx", adColonyInterstitialListener);
I want to show these ads from service how can I do it while they need activity context.
I'd appreciate if you could advise on my problem.
I'm working on AR app using Vuforia SDK for Unity3D and Android plugins.
I have several ImageTargets and 3D models on my scene.
My class that works with android plugin looks like this:
public class AssetBundleAugmenter : MonoBehaviour, ITrackableEventHandler
{
void Start()
{
StartCoroutine(DownloadAndCache());
mTrackableBehaviour = GetComponent<TrackableBehaviour>();
if (mTrackableBehaviour)
{
mTrackableBehaviour.RegisterTrackableEventHandler(this);
}
init();
}
public void OnTrackableStateChanged(
TrackableBehaviour.Status previousStatus,
TrackableBehaviour.Status newStatus)
{
if (newStatus == TrackableBehaviour.Status.DETECTED ||
newStatus == TrackableBehaviour.Status.TRACKED ||
newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
{
if (!mAttached && mBundleInstance)
{
// if bundle has been loaded, let's attach it to this trackable
//...
}
OnTrackingFound();
}
else
{
OnTrakingLost();
}
}
private void OnTrackingFound()
{
if (mTrackableBehaviour is ImageTargetAbstractBehaviour)
{
GetJavaObject().Call("OnMarkerFound");
}
}
void onButtonClicked(int index)
{
//Changing current 3D model material
}
#if UNITY_ANDROID
private AndroidJavaObject javaObj = null;
//LISTENING TO BUTTON CLICK EVENTS FROM ANDROID
private sealed class EventListner : AndroidJavaProxy
{
private AssetBundleAugmenter mReceiver;
public EventListner(AssetBundleAugmenter receiver)
: base("com.mypackage.myapp.ImageTargetTracker$Listner")
{
mReceiver = receiver;
}
public void onButtonClicked(int index) //change color of model
{
mReceiver.onButtonClicked(index);
}
}
private AndroidJavaObject GetJavaObject()
{
if (javaObj == null)
{
javaObj = new AndroidJavaObject("com.mypackage.myapp.ImageTargetTracker");
}
return javaObj;
}
AndroidJavaObject activity;
private void init()
{
// Retrieve current Android Activity from the Unity Player
AndroidJavaClass jclass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
activity = jclass.GetStatic<AndroidJavaObject>("currentActivity");
// Pass reference to the current Activity into the native plugin,
GetJavaObject().Call("setActivity", activity, new EventListner(this));
}
#else
void init() {}
#endif
}
So I attached this script to all of my ImageTargets on the scene, which I know must be wrong, because UnityPlayer gets initialized several times in my init() function.
I tried to attach the script to ARCamera on my scene, and write initialization only there, but I'm not sure how to access currentActivity in scripts that work with ImageTargets. Also, I use listener - the interface in my plugin that listens to button clicks to fire some functionality in unity.
My plugin code:
public class ImageTargetTracker {
public static interface Listner {
public void onButtonClicked(int index);
}
private Listner mListner;
protected Activity mCurrentActivity;
public void setActivity(Activity activity, Listner listner)
{
mCurrentActivity = activity;
mListner = listner;
mCurrentActivity.runOnUiThread(new Runnable() {
public void run() {
LayoutInflater inflater = mCurrentActivity.getLayoutInflater();
Resources resources = mCurrentActivity.getResources();
String pkgName = mCurrentActivity.getPackageName();
int id = resources.getIdentifier("camera_layout", "layout", pkgName);
View view = inflater.inflate(id, null);
mCurrentActivity.addContentView(view, param);
//INITIALIZING UI ELEMENTS HERE (DISPLAYED ON TOP OF CAMERA)
}
public void OnMarkerFound(){
mCurrentActivity.runOnUiThread(new Runnable() {
public void run() {
//Showing some UI elements
}
});
}
}
So, how can I globally initialize the Activity and my plugin class in Unity one time, and use them in all of my scripts?
As discussed in the comments, I recommend using the singleton pattern.
Hi there StackOverflow!
I had been loocking on a way to Use the native Android Dialogs and Confimation Boxes in Libgdx...
All that i did by now was a Title and an Image under it:
Dialog yourmsgbox = new Dialog("Title", jsons);
yourmsgbox.setBounds(0f,0f,100f,200f);
yourmsgbox.add(choiceImg);
mainClass.addActor(yourmsgbox);
I suck a little at this but all the codes that i find in Google to do that are Or for Desktop or very especific for that Type of game + Even after some tries to copy the code and adapt it to my .java Files im still getting errors....
So if you guys could guide through a step by step ((Or a list Number of online items that i could follow to get this done I WOULD BE VERYY GRATEFULL !!!))
[[My Json file is EXTREMELY BUGGY, so if I could not have to mess with that Stubborn uiskin.json, I would Thank you :]]
Sorry my bad english
Please i'd apreciate a little help!?
UPDATE:: Sorry i have
two MainClasses for this project and i pick the wrong Logcat :)
I just use showMessage(); in the beggining of the create(), it
crashes when i get into the app. Here is what i did:
I Created an Inferface in core Project:
public interface NativeDialogInterface {
void showMessage(final String title, final String message, final String okButtonText);
}
Created AndroidNativeDialog in -android Project folder:
public class AndroidNativeDialog implements NativeDialogInterface {
private Activity activity;
public void initialize(Activity activity) {
this.activity = activity;
}
#Override
public void showMessage(final String title, final String message, final String okButtonText) {
this.activity.runOnUiThread(new Runnable() {
#Override
public void run() {
final AlertDialog alertDialog = new AlertDialog.Builder(activity).create();
alertDialog.setTitle(title);
alertDialog.setMessage(message);
alertDialog.setButton(okButtonText, new DialogInterface.OnClickListener() {
#Override
public void onClick(final DialogInterface arg0, final int arg1) {
alertDialog.cancel();
}
});
alertDialog.show();
}
});
}
}
*Strange that it says as warning "Method setButton(...) is deprecated"
Then i added new (dialogInterface) in the AndroidLaucher.java:
public class AndroidLauncher extends AndroidApplication {
private AndroidNativeDialog dialogInteface;
#Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
dialogInterface = new AndroidNativeDialog();
initialize(new IndexMain(dialogInteface), config);
}
}
Then in the MainClass what i did was:
btnWindow.addListener(new ClickListener(){
#Override
public void clicked(InputEvent event, float x, float y) {
mainScreen.addActor(andWindow);
dialogInteface.showMessage("TITLE", "ThE MeSsaGe", "Okayy");
Timer.schedule(new Timer.Task() {
#Override
public void run() {
andWindow.setBounds(Gdx.graphics.getWidth(), 0f, 1f, 1f);
}
}, 17);
}
});
I head to that link that "Fuat Coçkun" provided and i learn a lot about these type of structures but it seems i still have something wrongg
Its WORKS perfectly until i click that /\ Button, the button is ok if i delete the showMessage(...);
new LogCat: http://pastebin.com/NbgnyrAJ
Sorry for my bad english.
I can give you example usage of native android AlertDialog with libgdx. Firstly you need an interface in your core Project as follows :
public interface NativeDialogInterface {
void showMessage(final String title, final String message, final String okButtonText);
}
You need different implementations for each of platform you support in your project. Android project implementation will use Dialog, AlertDialog or whatever you want to use as native android component. This example shows AlertDialog implementation:
public class AndroidNativeDialog implements NativeDialogInterface {
private Activity activity;
public void initialize(Activity activity) {
this.activity = activity;
}
#Override
public void showMessage(final String title, final String message, final String okButtonText) {
this.activity.runOnUiThread(new Runnable() {
#Override
public void run() {
final AlertDialog alertDialog = new AlertDialog.Builder(activity).create();
alertDialog.setTitle(title);
alertDialog.setMessage(message);
alertDialog.setButton(okButtonText, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface arg0, int arg1) {
alertDialog.cancel();
}
});
alertDialog.show();
}
});
}
}
You need to call "initialize" method of your instance in your activity(onCreate is proper.) for setting activity field.
You can use any dummy implementation for the Desktop module of your libgdx project. Following implementation only logs the data you passed.
public class DesktopNativeDialog implements NativeDialogInterface {
#Override
public void showMessage(final String title, final String message, final String okButtonText) {
System.out.println("Title : " + title);
System.out.println("Message : " + message);
System.out.println("OkButtonText : " + okButtonText);
}
}
That's all. You should have a field typed NativeDialogInterface in your Core module and call "showMessage" method with your parameter. You will see a console log if you run your application on desktop. You will see native Android alert dialog on your glSurfaceView when you run your application on device/emulator.
I did this and created an expansion for libGDX. You can use it or check the source: https://github.com/TomGrill/gdx-dialogs
My problem is this;
I have a AsyncTask that works fine, and on doInBackground() it calls a new class that sync my data to a web service using REST service, i don't have everything on a unique class because i need the same content sync for different activitys and it's easier this way.
What i need is, on the sync procedure, i can get the number of "contacts" and everytime it downloads a contact, removes 1 from the "contacts" lenght, so, i nedd to show on the progress dialog the length of contact and refresh everytime it downloads a new "contact"
hre's my code for the AsyncTask:
public class syncContentTask extends AsyncTask<String, String, Boolean> {
private ProgressDialog mprogress;
private Context context;
//token for JSON header to authenticate
String authToken;
public syncContentTask(Context cxt, String token) {
this.context = cxt;
mprogress = new ProgressDialog(context);
authToken = token;
}
protected void onPreExecute() {
mprogress = ProgressDialog.show(context, "Sync", "Sync in progress...");
}
#Override
protected Boolean doInBackground(String... params) {
syncData syncData = new syncData();
syncData.syncData(context, authToken);
publishProgress(progress);
return true;
}
protected void onProgressUpdate(String... progress) {
//mprogress.setProgress(Integer.parseInt(progress[0]));
}
protected void onPostExecute(Boolean result) {
if (result) {
mprogress.dismiss();
}
}
}
In the Sync Data class i have functions that handles the HttpRequest and database stuff...
can anyone help??
You need to create a listener for your data progress and have it update the progress bar. Right now it looks like this line:
syncData.syncData(context, authToken);
blocks and no updates are provided to your progress indicator until it is done. So, you need something like:
MyListener listener = new MyListener(context);
SyncData syncData = new syncData(listener);
And in your listener have callback methods like myListener.downloadStarted() , myListener.updateProgressBar(int progress) and myListener.downloadCompleted() that your syncData class calls as the download progresses.
For example:
public abstract class SDScanAdapter implements SDScanListener {
public void startScan() {
}
public void updateScanProgress(int scanItemsTotal, int scanItemsCompleted) {
}
public void scanComplete() {
}
}
Then create a listener class:
public class ScanListener extends SDScanAdapter {
#Override
public void scanComplete(String contactName, String action) {
runOnUiThread(scanComplete);
}
#Override
public void startScan() {
runOnUiThread(startScan);
}
#Override
public void updateScanProgress(int scanItemsTotal,
int scanItemsCompleted) {
if (scanCountTotal != scanItemsTotal) {
scanCountTotal = scanItemsTotal;
progressBar.setMax(scanCountTotal);
}
if (scanCountUpdate != scanItemsCompleted) {
scanCountUpdate = scanItemsCompleted;
runOnUiThread(updateScanProgress);
}
}
}
And then for this example you need Runnables (startScan, scanComplete and updateScanProgress) that perform UI tasks, like updating the progress bar. In your case, you may also want to load some of the results, etc.
Then in your AsyncTask you do:
ScanListener listener = new ScanListener();
SyncData syncData = new syncData(listener);
Assuming the SDScanListener class and AsyncTask are all in your Activity. Also, your SyncData calss will need to have a SDScanListener variable that is set when it instantiates. Then, while it does its job, calls are made to the listener methods like:
scanListener.startScan();
And while it progresses, it calls the other methods (and corresponding parameters are passed in).
Hello everyone!
Im currently developing an Android Application for mobiles using the official Facebook SDK. The first screen on my application is the LoginActivity. That activity is bringing up an Facebook login dialog, were the user can enter his facebook username and password and then press the login button. I think you know which dialog im talking about, i bet you have seen it somewhere.
When the user are logging to Facebook using that dialog, theres a Facebook session which are set to true, exactly as it should be. BUT, I found out that this session is only true if you are in the LoginActivity. If the user makes an successfull login to Facebook the user are moved to another Activity by this code:
private class LoginDialogListener implements DialogListener {
#Override
public void onComplete(Bundle values) {
Intent intent = new Intent().setClass(LoginActivity.this, LocationActivity.class);
startActivity(intent);
}
And when the user are moved to the new activity in this case LocationActivity,
the session is still true but only for the LoginActivity. I want the session to be global and be true for the whole application and all activities as soon as the user are logging in.
Here is some code from LoginActivity, i hope this will make your guys to understand it all better, i bet if i post the whole activity no one would read it.
public class LoginActivity extends Activity {
public static final String APP_ID = "123123123123123";
public static final String TAG = "FACEBOOK CONNECT";
private Facebook mFacebook;
private AsyncFacebookRunner mAsyncRunner;
private static final String[] PERMS = new String[] { "user_events" };
private Handler mHandler = new Handler();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mFacebook = new Facebook(APP_ID);
mAsyncRunner = new AsyncFacebookRunner(mFacebook);
}
...
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
switch (itemId) {
case FacebookCon.LOGIN:
if (mFacebook.isSessionValid()) {
AsyncFacebookRunner asyncRunner = new AsyncFacebookRunner(
mFacebook);
asyncRunner.logout(this, new LogoutRequestListener());
} else {
mFacebook.authorize(this, PERMS, new LoginDialogListener());
}
break;
...
private class LogoutRequestListener implements RequestListener {
#Override
public void onComplete(String response, Object state) {
// Dispatch on its own thread
mHandler.post(new Runnable() {
public void run() {
}
});
}
A friend told me that i should make a "ApplicationController", i did not really understand what that were but he said that class should extend the whole application and all the variabels in the ApplicationController would be global for the whole application, and that's what i would like to do with the loginsession so it won't get lose when changing activities. But i don't know how to make this changes in my Application so i would like to have some help with this.