I did everything like the tutorial tells the AdMob site, put the layout in XML, imported the path Google Play Sevices and added the lines of code from the tutorial, my application compiles, but no longer opens on your smartphone.
Follows the code.
Classe
package your.CalculoHE.namespace;
import org.apache.cordova.DroidGap;
import com.google.android.gms.ads.*;
import android.os.Bundle;
public class CalculoHoraExtraActivity extends DroidGap {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.main);
super.setIntegerProperty("splashscreen", R.drawable.sobreaviso);
super.loadUrl("file:///android_asset/www/index.html", 3000);
// Consultar o AdView como um recurso e carregar uma solicitação.
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="ca-app-pub-*******"
ads:adSize="BANNER"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hora extras"
/>
</LinearLayout>
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="your.CalculoHE.namespace"
android:versionCode="4"
android:versionName="1.2" >
<uses-sdk android:minSdkVersion="9" />
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true"
android:resizeable="true"
android:anyDensity="true"
/>
<application android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
<activity android:configChanges="orientation|keyboardHidden" android:name=".CalculoHoraExtraActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>
Try changing:
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
To:
AdView adView = (AdView)this.findViewById(R.id.adView);
adView.loadAd(new AdRequest());
Related
I have implemented test banner ads in my project and they work, but when the banner ad gets loaded the color of the imageview that is also in my activity gets darker, after some time the color of my imageview changes back to normal. Is something wrong with my code or could this be an sdk related problem?
Here is how it looks:
(Normal imageview) , (Imageview when ad is loaded)
here is my code:
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".YouAreDream">
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
app:adSize="BANNER"
app:adUnitId="ca-app-pub-3940256099942544/6300978111"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/constraintLayout2"
app:layout_constraintVertical_bias="0.42000002"></com.google.android.gms.ads.AdView>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="100dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0">
<ImageView
android:id="#+id/imageViewYou"
android:layout_width="321dp"
android:layout_height="311dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.13999999"
app:srcCompat="#drawable/dream"/>
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/Dream"
android:textColor="#color/black"
android:textSize="40dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageViewYou"
app:layout_constraintVertical_bias="0.32999998" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Q_Dream"
android:textSize="24dp"
android:textStyle="italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView"
app:layout_constraintVertical_bias="0.19999999" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Here is my java code:
package com.example.minecraftstreamertest;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;
public class YouAreDream2 extends AppCompatActivity {
ImageView mImageView;
AdView mAdView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_you_are_dream2);
MobileAds.initialize(this, new OnInitializationCompleteListener() {
#Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
mImageView = (ImageView) findViewById(R.id.imageViewYou);
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_in);
mImageView.setAnimation(animation);
mImageView.clearColorFilter();
}
}
Here is my Manifest code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.minecraftstreamertest">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.MinecraftStreamerTest"
>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-7897828714906116~2778343400"/>
<activity android:name=".YouAreDream2"></activity>
<activity
android:name=".YouAreBadboyhalo"
android:screenOrientation="portrait" />
<activity
android:name=".YouAreQuackity"
android:screenOrientation="portrait" />
<activity
android:name=".YouAreFundy"
android:screenOrientation="portrait" />
<activity
android:name=".YouAreTubbo"
android:screenOrientation="portrait" />
<activity
android:name=".YouAreWilbur"
android:screenOrientation="portrait" />
<activity
android:name=".YouAreGeorge"
android:screenOrientation="portrait" />
<activity
android:name=".YouArePhilza"
android:screenOrientation="portrait" />
<activity
android:name=".YouAreTommy"
android:screenOrientation="portrait" />
<activity
android:name=".YouAreRanboo"
android:screenOrientation="portrait" />
<activity
android:name=".YouAreJschlatt"
android:screenOrientation="portrait" />
<activity
android:name=".YouAreSlime"
android:screenOrientation="portrait" />
<activity
android:name=".YouAreKarl"
android:screenOrientation="portrait" />
<activity
android:name=".YouAreSapnap"
android:screenOrientation="portrait" />
<activity
android:name=".YouAreTechno"
android:screenOrientation="portrait" />
<activity
android:name=".YouAreDream"
android:screenOrientation="portrait" />
<activity
android:name=".TestActivity"
android:screenOrientation="portrait" />
<activity
android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
I solved the problem!
it seems to be some kind of layer bug but I'm not sure.
this is the one line i needed to add in my java file:
mAdView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
here is the java file
public class YouAreWilbur extends AppCompatActivity {
ImageView mImageView;
AdView mAdView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_you_are_wilbur);
mImageView = (ImageView) findViewById(R.id.imageViewYou);
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_in);
mImageView.setAnimation(animation);
MobileAds.initialize(this, new OnInitializationCompleteListener() {
#Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
mAdView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
I found how to fix the bug on this page: https://issuetracker.google.com/issues/36996575
I have the same problem. I have tried a lot but couldn't figure it out. The cause of the problem is the banner ads. Actually if any animation exists in banner, imageview's darkness changes by the animation, like a flash.
this is my manifest files:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iadmo.dahan"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="preferExternal"
>
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:allowBackup="true"
android:name="com.iadmo.dahan.application.MyApplication"
android:icon="#drawable/appicon"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity
android:name="com.iadmo.dahan.activity.WelcomeActivity"
android:label="#string/app_name"
android:windowSoftInputMode="adjustPan|stateHidden"
android:theme="#android:style/Theme.NoTitleBar"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden"
android:clearTaskOnLaunch="false"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activity.MainActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.RecommendActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden"
android:configChanges="orientation|keyboardHidden"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.PersonalActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.LoginActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.RegisterActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.DownloadedActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.SortedActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.ClassesActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.SearchedActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.ProductDetailsActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.PerClassActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.ProductCommentActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.ProductSimpleInfoActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.CommentDetailsActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<activity android:name=".activity.DownloadingActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
/>
<service android:name="com.iadmo.dahan.service.DownloadService"/>
</application>
and this is the xml for layout of productdetailsActivity:
public class ProductDetailsActivity extends TabActivity {
private TabHost mHost;
private String appId, userId;
private ListView per_class_simple_info;
private List<BaseInfo> datas;
private DetailsAdapter adapter;
private TextView txtview1, txtview2;
private Button back;
private TextView title_name;
private Dialog dialog;
#SuppressWarnings("deprecation")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_productdetail);
MyApplication.getInstance().addActivity(this);
Bundle bundle = getIntent().getExtras();
appId = bundle.getString("appId");
userId = AppUtil.getString(getApplicationContext(), "userid", "");
initCompanents();
initViews();
initDatas();
Intent intent = new Intent();
intent.setAction("GOODID");
intent.putExtras(bundle);
getApplicationContext().sendBroadcast(intent);
initEvents();
}
#SuppressWarnings("deprecation")
private void initViews() {
back = (Button) findViewById(R.id.back);
title_name = (TextView) findViewById(R.id.title_name);
per_class_simple_info = (ListView) findViewById(R.id.per_class_simple_info);
mHost = this.getTabHost();
mHost.addTab(mHost.newTabSpec("mhost_job").setIndicator(txtview1)
.setContent(new Intent(this, ProductSimpleInfoActivity.class)));
mHost.addTab(mHost.newTabSpec("mhost_company").setIndicator(txtview2)
.setContent(new Intent(this, ProductCommentActivity.class)));
}
private void initCompanents() {
txtview1 = new TextView(this);
txtview1.setText("简介");
txtview1.setTextColor(getResources().getColor(R.color.white));
txtview1.setGravity(Gravity.CENTER);// 文字居中
txtview1.setTextSize(15);// 字体大小
txtview1.setPadding(15, 16, 15, 15);// 四周填充
txtview1.setBackgroundResource(R.drawable.tabhost_bg);
txtview2 = new TextView(this);
txtview2.setText("评论");
txtview2.setTextColor(getResources().getColor(R.color.black));
txtview2.setGravity(Gravity.CENTER);// 居中
txtview2.setTextSize(15);// 字体大小
txtview2.setPadding(15, 16, 15, 15);// 填充
txtview2.setBackgroundResource(R.drawable.tabhost_bg);
LayoutParams param1 = new LayoutParams(
android.view.ViewGroup.LayoutParams.FILL_PARENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
param1.setMargins(0, 10, 0, 0);
param1.weight = 1;// 权重
txtview1.setLayoutParams(param1);
LayoutParams param2 = new LayoutParams(
android.view.ViewGroup.LayoutParams.FILL_PARENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
param2.setMargins(0, 10, 0, 0);
param2.weight = 1;// 权重
txtview2.setLayoutParams(param2);
}
and this is the productSimpleInfoActivity's code:
public class ProductSimpleInfoActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_simpleinfo);
MyApplication.getInstance().addActivity(this);
initViews();
registerReceivers();
initEvents();
}
this is the productDetail xml layout,i think this is right ,i tired it ,it worked,but today i tired again,it failed:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
>
</TabWidget>
<View
android:layout_width="fill_parent"
android:layout_height="#dimen/s_5"
android:background="#color/red_light" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
Try the following code.It hopefully works.
main.xml file :
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#android:id/tabhost" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
></TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"></FrameLayout>
</LinearLayout>
</TabHost>
In Class File add this code in your onCreate():
setContentView(R.layout.main);
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, Personal.class);
spec = tabHost.newTabSpec("personal").setIndicator("Personal").setContent(intent);
tabHost.addTab(spec);
This is my main class -
package com.example.trial;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AdView adview = (AdView) this.findViewById(R.id.adView);
AdRequest adrequest = new AdRequest.Builder().build();
adview.loadAd(adrequest);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
This is activity_main.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.trial.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
<com.google.android.gms.ads.AdView android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-00000000000000000/1111111111"/>
</RelativeLayout>
ANother file I modified is AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.trial"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
</application>
</manifest>
I have added google-play-services_lib properly in my project buildpath.
Project in eclipse shows no error as such. But It is not showing ad after running app.
Internet connection is proper (Checked by running browser on android emulator)
Can someone suggest what might have gone wrong ?
I am new to admob. I have created ad unit default setting and using its id. Is there anything else to be done ??
update - when I removed these two lines
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
It showed error in box where ad is supposed to be placed. That means view has been created ??
Enabled logcat from here -
How to enable LogCat/Console in Eclipse for Android?
Solved problem using this -
Not enough space to show ad (AdMob)
Thanks #William !!!
i have wrote SDL game and ported it to andorid
and now I tried to integrate it with admob but i failed
AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<!-- Replace org.libsdl.app with the identifier of your game below, e.g.
com.gamemaker.game
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.libsdl.zomibeshooter"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="auto">
<!-- Create a Java class extending SDLActivity and place it in a
directory under src matching the package, e.g.
src/com/gamemaker/game/MyGame.java
then replace "SDLActivity" with the name of your class (e.g. "MyGame")
in the XML below.
An example Java class can be found in README-android.txt
-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:allowBackup="true"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:hardwareAccelerated="true" >
<activity android:name="mygame"
android:label="#string/app_name"
android:configChanges="keyboardHidden|orientation"
android:screenOrientation="landscape"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="#android:style/Theme.Translucent" />
</application>
<!-- Android 2.3.3 -->
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
<!-- OpenGL ES 2.0 -->
<uses-feature android:glEsVersion="0x00020000" />
<!-- Allow writing to external storage -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="xxxxx" />
</LinearLayout>
my SDLActivity.java
// Setup
#Override
protected void onCreate(Bundle savedInstanceState) {
Log.v("SDL", "onCreate():" + mSingleton);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Prepare the Interstitial Ad
interstitial = new InterstitialAd(SDLActivity.this);
// Insert the Ad Unit ID
interstitial.setAdUnitId("xxxxxxx");
//Locate the Banner Ad in activity_main.xml
AdView adView = (AdView) this.findViewById(R.id.adView);
// Request for Ads
AdRequest adRequest = new AdRequest.Builder()
// Add a test device to show Test Ads
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("CC5F2C72DF2B356BBF0DA198")
.build();
// Load ads into Banner Ads
adView.loadAd(adRequest);
// Load ads into Interstitial Ads
interstitial.loadAd(adRequest);
// Prepare an Interstitial Ad Listener
interstitial.setAdListener(new AdListener() {
public void onAdLoaded() {
// Call displayInterstitial() function
displayInterstitial();
}
});
SDLActivity.initialize();
// So we can call stuff from static callbacks
mSingleton = this;
// Set up the surface
mSurface = new SDLSurface(getApplication());
if(Build.VERSION.SDK_INT >= 12) {
mJoystickHandler = new SDLJoystickHandler_API12();
}
else {
mJoystickHandler = new SDLJoystickHandler();
}
mLayout = new AbsoluteLayout(this);
mLayout.addView(mSurface);
setContentView(mLayout); #########// if i comment this i can see the ad but the game is not show!
}
public void displayInterstitial() {
// If Ads are loaded, show Interstitial else show nothing.
if (interstitial.isLoaded()) {
Log.v("ad","displayed");
interstitial.show();
}
}
if i comment this line i can see the ad but not the game ! :
setContentView(mLayout);
So how i can show the ad from starting my game until it exit ?
I'm developing a android app cappable of acessing the maps API, but i'm stuck on error:
Google Maps Android API﹕ Failed to load map. Error contacting Google
servers. This is probably an authentication issue (but could be due to
network errors).
Already did the key and activate everithing in google API console.
These are my files:
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="hflopes.mapas" >
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"></uses-permission>
<uses-feature android:glEsVersion="0x00020000"
android:required="true"></uses-feature>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBTObQnY1mxYwXw1g8txH5ApBu8ovxv730" />
<activity android:name=".MostraAlunosProximos"></activity>
<activity
android:name=".mapas"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
mapas_layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/mapa"/>
</LinearLayout>
Class for Loading the map:
package hflopes.mapas;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.AttributeSet;
import android.view.View;
/**
* Created by HFLopes on 24/07/2014.
*/
public class MostraAlunosProximos extends FragmentActivity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapa_layout);
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.mapa, new MapaFragment());
transaction.commit();
}
}
Any Idea?
Thanks for the help
I have done the same.
Try this in your MostraAlunosProximos class oncreate,
int status = GooglePlayServicesUtil
.isGooglePlayServicesAvailable(getBaseContext());
// Showing status
if (status != ConnectionResult.SUCCESS) { // Google Play Services
// are
// not available
int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status,
this, requestCode);
dialog.show();
} else { // Google Play Services are available
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.mapa);
// Getting GoogleMap object from the fragment
if (fm != null) {
googleMap = fm.getMap();
}
// Enabling MyLocation Layer of Google Map
googleMap.setMyLocationEnabled(true);
}
And add this line android:name="com.google.android.gms.maps.SupportMapFragment" inside fragment of your xml file.
And also i see there are two metadeta for google play service remove that.
Hope this helps
I did this and got to work on my device. Try it.
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="br.com.example.mapsexample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:maxSdkVersion="20"
android:minSdkVersion="17"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- Required OpenGL ES 2.0. for Maps V2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="br.com.example.mapsexample.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Goolge API Key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="your_api_key_here" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
Class for loading map
package br.com.example.mapsexample;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
public class MainActivity extends Activity {
GoogleMap mGoogleMap;
#Override
protected void onCreate( final Bundle savedInstanceState ) {
super.onCreate( savedInstanceState );
this.setContentView( R.layout.activity_main );
try {
this.initializeMap();
} catch ( final Exception e ) {
// TODO: handle exception
}
}
#Override
protected void onResume() {
super.onResume();
this.initializeMap();
}
private void initializeMap() {
if ( this.mGoogleMap == null ) {
this.mGoogleMap = ( ( MapFragment ) this.getFragmentManager().findFragmentById( R.id.mapFragment ) ).getMap();
if ( this.mGoogleMap == null ) {
Toast.makeText( this.getApplicationContext(), "Is not possible load the map", Toast.LENGTH_SHORT ).show();
}
}
}
}
Layout Maps
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<fragment
android:id="#+id/mapFragment"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
Solved it!
it was missing this on build.graddle
signingConfigs {
debug {
storeFile file("debug.jks")
}
}
Thanks for the help