I have used Ampiri integration in my app.
I copy paste all the code from their android sdk integration wizard for banner ads into my code. What bothers me is that Android Studio can not find that listener and view in the red letter.
So what is that I miss? Is there any problems on my code? If not what should I do to resolve this issue? Please help me.
Following is my code:
I’ve implemented the AdEventCallback using:
import com.ampiri.sdk.listeners.AdEventCallback;
and call it from main activity inside onCreate as describe in my code below:
public abstract class MainActivity extends AdCallbackActivity implements AdEventCallback {...}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FrameLayout adView = (FrameLayout)view.findViewById(R.id.ad_view);
StandardAd standardAd = new StandardAd(this, adView,“MY_ADUNIT_ID",BannerSize.BANNER_SIZE_320x50, adListener);
standardAd.loadAd();
Please check my comments inline for each error.
view.findViewById(R.id.ad_view)
If the ad_view is in the current Activity layout set by setContentView, you don't need to add "view."
i.e.
findViewById(R.id.ad_view)
adListener
Please implement an event listener interface AdEventCallback, referencing to our integration page.
In addition, If you will have the AdEventCallback methods in your AdCallbackActivity.java file.
please try the code below.
StandardAd standardAd = new StandardAd(
this, adView, "3dfbb889-3bcd-4c34-82ae-8fcb539c3b25",
BannerSize.BANNER_SIZE_320x50, this);
If it doesn't work, please send me your MainActivity and AdCallbackActivity to suppport#ampiri.com.
Related
I am trying to set up gdx-pay in my game. I have followed the official readme (https://github.com/libgdx/gdx-pay/), but can't seem to instantiate the PurchaseManager in my AndroidLauncher.
I have set up a class that handles PurchaseManager installation, but every time I try to instantiate it in the AndroidLauncher I get this error:
"java.lang.RuntimeException: Unable to start activity ComponentInfo{appPackage.AndroidLauncher}: java.lang.IllegalArgumentException: Support for pending purchases must be enabled. Enable this by calling 'enablePendingPurchases()' on BillingClientBuilder."
The readme says to add this to the AndroidLauncher onCreate
game.purchaseManager = new PurchaseManagerGoogleBilling(this);
The problem is that I have to add this
ProjectName.purchaseManager = new PurchaseManagerGoogleBilling(this);
This give me an error saying that I have to make purchaseManager static in my ProjectName class
When I do this, I get the RuntimeException mentioned above.
The sample gdx-pay project instantiates PurchaseManager with this code
public class AndroidLauncher extends GenericAndroidLauncher {
#Override
protected void initFlavor(GdxPayApp game) {
super.initFlavor(game);
game.purchaseManager = new PurchaseManagerGoogleBilling(this);
}
}
When I try this, #Override is invalid and initFlavor does not exist. I tried looking for initFlavor in the gdx-pay files, but had no luck finding anything...
Thanks for taking the time to help
Well it turns out that the following line in my android gradle was the issue
implementation 'com.android.billingclient:billing:2.0.1'
Gdx-pay takes care of this automatically and uses client 1.1
Setting the billingclient to 2.0.1 was the problem. I was able to fix it by deleting that line. Big thanks to the libGdx discord guys!
I am working on an augment reality android app. I developed the app in unity using vuforia and then imported it in android studio as i wanted to design it in android studio. The activity name in generated project structure is UnityPlayerActivity which has no layout in the project. The activity is passed to UnityPlayerclass and the layout is generated. This is some code of my UnityPlayerActivity activity.
protected UnityPlayer mUnityPlayer; // don't change the name of this variable; referenced from native code
// Setup activity layout
#Override protected void onCreate(Bundle savedInstanceState)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
getWindow().setFormat(PixelFormat.RGBX_8888); // <--- This makes xperia play happy
mUnityPlayer = new UnityPlayer(this);
setContentView(mUnityPlayer);
mUnityPlayer.requestFocus();
}
as it uses that layout how can i design that activity by referencing it.
It is not possible to do this by referencing the object(Java does not support call by reference).
You need to define a new function in UnityPlayer class that generates a layout and returns the LayoutParams object.
Then use the Layout inflator. Something like this:
LayoutParams mParams=mUnityPlayer.layoutGenerator() //some function to generate LayoutParams
LayoutInflator.getLayoutInflator().inflate(LayoutParams);
Finally i found an easy solution to my problem. I displayed the unity scenes in a subview using a framelayout and now i can customize the UI easily. Check here and here to see more information.
I'm trying to implement achievements with Google Play Services in a game. I have followed up the steps in this documentation and everything is ok except I got a runtime warning and then a crush. The warning is:
06-09 10:43:05.900: W/PopupManager(17888): You have not specified a View to use as content view for popups. Falling back to the Activity content view which may not work properly in future versions of the API. Use setViewForPopups() to set your content view.
My application is using openGL and the activity has a member mView that extends GLSurfaceView.
I have tried this and this (I have all those meta tags and the app_id setup correctly).
Also, TypeANumber starts correctly with my app_id.
Can anyone help me on this?
EDIT [added some code]:
Here is the Activity declaration:
public class GGActivity extends BaseGameActivity implements SensorEventListener, IDownloaderClient {
Here is onCreate where the problem occurs (after the change suggested by free3dom):
public GGView mView;
#Override protected void onCreate(Bundle icicle) {
setRequestedClients(BaseGameActivity.CLIENT_GAMES | BaseGameActivity.CLIENT_APPSTATE);
//if (DEBUG_BUILD)
{
enableDebugLog(true);
}
setContentView(mView); // make sure mView is created before
getGameHelper().createApiClientBuilder();
getGameHelper().getApiBuilder().setViewForPopups( mView );
super.onCreate(icicle);
YES, setContentView helped. Thanks!
In order for your activity to recognize and use the GLSurfaceView you have to set it. This can be done by calling
setContentView(mView);
after creating the GLSurfaceView (documentation can be found here).
As the title suggests I am trying to create an Android app using Phonegap and then trying to insert Admob into it.
I am using this tutorial provided by Adobe and it is working fine. After this when I use this tutorial provided by Google I run into problems.
According to the Google tutorial, I have to change the activity class, below is the original and the second block of code is the altered code. There doesn't seem to be any errors preventing it from compiling. It's just when I try and run it using the Android emulator I get an error stating "Unfortunately MyFirstPhonegapPlugin has stopped"
Note, using the Google tutorial, there are two ways of implementing the code, using just the class below and using a mixture of XML and the class below. I tried the other way and due to getting errors which doesn't let me compile, I've gone for this way.
package com.tricedesigns;
import org.apache.cordova.DroidGap;
import android.os.Bundle;
public class MyFirstPhoneGapPluginActivity extends DroidGap {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
}
}
Adjusted code:
package com.tricedesigns;
import org.apache.cordova.DroidGap;
import android.os.Bundle;
import com.google.ads.*;
public class MyFirstPhoneGapPluginActivity extends DroidGap {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
// Look up the AdView as a resource and load a request.
AdView adView = (AdView)this.findViewById(R.id.adView);
adView.loadAd(new AdRequest());
}
}
I am using Phonegap 1.6.1 and the most up to date SDK for Android and Admob
The way Phonegap is implemented, it pretty much hides all the details about Android and lets you basically implement a mobile web app as a native app. If you care to implement Android natively, I'd recommend reading the Hello World tutorial. The code you have here is crashing on AdView adView = (AdView)this.findViewById(R.id.adView); because you don't have a layout file with an AdView element with id adView.
If you're more interested in the mobile web part of it and plan to continue sticking with Phonegap, your best bet is to try this plugin which lets you make JavaScript calls using the Phonegap framework, and the plugin performs all of the underlying Android calls necessary to get ads.
Here is a fully functional project of what I was looking for
old version phonegap not support extenal jar lib.
but now phonegap add some new feathers.
use phonegap builder ,add config
add some config
<gap:plugin name="com.admob.plugin" version="1.0.0" source="plugins.cordova.io"/>
so not need any java code any more.
just need some js code.
admob.initAdmob("admob banner ID","admob interstitial ID");
admob.showBanner(admob.BannerSize.BANNER,admob.Position.TOP_APP);
this will create and show a admob banner at top of your app.
I've been trying to connect to twitter through android for a while.
I'm currently using this api: http://kenai.com/projects/twitterapime/forums/forum/topics/13327-Twitter-API-ME-1-8-Now-with-OAuth-support
I used their exemple with my keys and everything connects without problem. So no problem with configuration.
But in my project which has exactly the same code I can't make it work.
I believe its related with the creation of a new Intent (also this is where the eclipse is point the error)
Im trying to use a custom layout but I don't know what do I need to change to make this specific Twitter layout to work. On main activity I have a button with this:
public void onClick(View v)
{
startActivity(new Intent(this,Twitter.class));
}
on twitter class
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//this.webView = (WebView) findViewById(R.id.webView1);
WebView myWebView = new WebView(this);
setContentView(myWebView);
authenticate();
}
private void authenticate()
{
WebViewOAuthDialogWrapper page = new WebViewOAuthDialogWrapper(webView);
page.setConsumerKey(CONSUMER_KEY);
page.setConsumerSecret(CONSUMER_SECRET);
page.setCallbackUrl(CALLBACK_URL);
page.setOAuthListener(this);
page.login();
}
what requirements/adjustments are needed to make/change to the Twitter activity?
I believe I need to change something in the intent-filter but I don't even understand the work of intents. I've been only making easy layouts.
Note that I also gave internet permissions already.
Looks like i was making 2 mistakes.
First i was trying to use "webView" variable in WebViewOAuthDialogWrapper instead
"myWebView" so it wasn't initialized...
Second looks like i forgot to put the order of which the external libraries were loaded....
So be sure to put external libraries on top in eclipse project.
Lost about 2 days with these problems... oh well