Adding advertising in the application? - java

I am using this code:
<com.google.android.gms.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="MY_AD_UNIT_ID"
ads:adSize="BANNER"/>
But is in error :
Description Resource Path Location Type error: No resource identifier
found for attribute 'loadAdOnCreate' in package 'com.teste.teste1'
activity_teste.xml /Teste/res/layout line 120 Android AAPT Problem

You need to add your unique ad unit id. To get this you need to create a new banner ad in your AdMob profile after you set up a new application for monetization.
EDIT:
Remove "loadAdOnCreate" attribute on the 120th line since it can not be used as XML attribute.
EDIT 2:
Possible new solutions:
Add xmlns:ads="http://schemas.android.com/apk/res-auto to your parentl ayout in XML.
Add Google Play services to your dependencies:
compile 'com.google.android.gms:play-services:6.+'
Add a meta tag in your application's manifest:
<!--This meta-data tag is required to use Google Play Services.-->
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Add config changes and theme for adactivity in your application's manifest:
<!--Include the AdActivity configChanges and theme. -->
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="#android:style/Theme.Translucent" />

Related

Getting started with Google Play Services, Cannot Resolve Symbol

I am developing a Android Studio project using gradle 2.2 and Google Play Services 12.0.1. I am now trying to add functionality from Google Play Services.
The thing is I am unable to import the Google Play Service library. When I try the following line.
import com.google.android.gms.games.Games;
Or anything similar i get "Cannot resolve symbol Games", Android Studio proposes "Add library <...> to classpath" but that does not seem to change anything.
What I have done so far
I started out following this setup guide. Which simply says to update your build.gradle. My top-level build.gradle contains this,
project(":android") {
apply plugin: "android"
apply plugin: 'com.android.application'
configurations { natives }
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
< ... >
compile "com.google.android.gms:play-services-games:12.0.1"
}
}
I have also ensured that the buildscript section contains the maven link. I have also checked that Google Play Services are installed from the "SDK Tools" pane in the SDK manager. In addition to this I have added the correct version of Play Services as a dependency in Project structure -> Modules -> Dependencies. Someone suggested on earlier Stack Overflow questions that adding
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
to the AndroidManifest might help, so my Manifest looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="wizard_team.wizards_tale" >
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="27" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/GdxTheme" >
<activity
android:name="wizard_team.wizards_tale.AndroidLauncher"
android:label="#string/app_name"
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|navigation|orientation|screenSize">
<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" />
</application>
I do not receive any error messages when I resync and I have tried to update and restart Android Studio several times. I have also tried "Invalidate chaches/restart..".
During my quest on Google I have found several people experiencing the same problem and I have tried their solutions but nothing has worked. I have spent way to long with this problem, does anyone have any suggestions?
Solved it. As I do not have much experience creating apps I tried importing google play services into the core-module part of my app. For anyone else just getting started, the android specific code such as this should go in android -> java -> [package-name].
Might seem trivial, but as a beginner using this setup tool this problem kept me searching for hours.

Multiple Google api keys in manifest file (Android)

I am trying to add two api keys i.e Google places api key and google maps api key.
But I am not able to add both at same time to manifest file.How can I achieve the same.Any help would be appreciated.
Thanks in advance.
The error I am getting is
Caused by: java.lang.RuntimeException: The API key can only be specified once. It is recommended that you use the meta-data tag with the name: com.google.android.geo.API_KEY in the element of AndroidManifest.xml
I am including api keys like this
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="xxxxx" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="xxxx"/>
Use following meta-data in your manifest. there is no need to create another api key for places api if you already have api key for google map.
If you are using both Maps & Places Api in your application then you only need to specify geo api key.and just enable Places Api.
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="api_key" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Rather than adding two different API keys, for the same project enable both keys and copy down the same key as follows for single project which you want currently
<!-- Goolge Maps API Key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaS******************WDaKCEHP" />
<!-- Google Places API Key -->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaS******************WDaKCEHP" />
Whats your Error log saying
Caused by: java.lang.RuntimeException: The API key can only be
specified once. It is recommended that you use the meta-data tag with
the name: com.google.android.geo.API_KEY in the element of
AndroidManifest.xml
Just remove
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="xxxx"/>
Make sure you have below permissions . Enough for Map Showing .
<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="#string/common_google_api_key" />
<uses-library
android:name="com.google.android.maps"
android:required="false" />
Read
Getting error "java.lang.RuntimeException: Unable to start activity" in my app

AndroidManifest.xml not working properly

we are sooooo close to finishing our game, it is ready to be published through google play but we are having problems making any of the game services work.
we have a simple achievement button that should call the achievement UI, same goes for logging in. but we do not get any prompts when we are running it on our android device.
we have
PlayGamesPlatform.Activate();
in our start function
Social.localUser.Authenticate((bool success) => {
// handle success or failure
});
connected to a log in button
and
Social.ShowAchievementsUI();
on our show achievement button.
our email is connected as a tester on google play and the game service API's are all enabled
my real question is about the AndroidManifest that the game play service for unity created.
this is it:
<?xml version="1.0" encoding="utf-8"?>
<!-- This file was automatically generated by the Google Play Games plugin for Unity
Do not edit. -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.example.games.mainlibproj"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" />
<application>
<!-- Required for Nearby Connections API -->
<meta-data android:name="com.google.android.gms.nearby.connection.SERVICE_ID"
android:value="" />
<!-- the space in these forces it to be interpreted as a string vs. int -->
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="\ 606268116612" />
<meta-data android:name="com.google.android.gms.appstate.APP_ID"
android:value="\ 606268116612" />
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity android:name="com.google.games.bridge.NativeBridgeActivity"
android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
</application>
</manifest>
i have read online that the package name should be our package name but shouldnt this be created when we run android set up using our ID number for our game? should i physically change this in code in the manifest even though it says i shouldnt edit it?
also OUR.ID i have replaced just for this question and in the real manifest has our actual ID No
Many Thanks In Advance
I always have the same package name (at application level) than my hierarchy in the project. In my opinion is a good practice to set the root at the folder where you have all your activities.
On the other hand, you can sign your app for market with the ID you want setting it in your gradle file.
You can see a good reference here.
I hope this would help you.

how to solve IllegalStateException

I am developping an app and i wanna display a google map v2 on activity but it doesn't show
this is a snippet form logcat
11-30 19:14:56.681: E/AndroidRuntime(6062):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.cultural/com.example.cultural.MainActivity}:
android.view.InflateException: Binary XML file line #20: Error
inflating class fragment
11-30 19:14:56.681: E/AndroidRuntime(6062): Caused by:
java.lang.IllegalStateException: The meta-data tag in your app's
AndroidManifest.xml does not have the right value. Expected 6171000
but found 0. You must have the following declaration within the
element:
Make sure you add this to your manifest application tag :
<application
... >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="YOUR KEY HERE" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
and see comment below or check this :
Android Google Maps API "Error inflating class fragment"
Make sure you have the following inside the <application> element in your AndroidManifest.xml.
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>

Blank Screen Android 2.2 Google Maps v2

EDIT :
I transferred my 20+ projects that tries to use Google Maps for Android v2. After changing keys and stuff, now, it works. I don't know what made this work, but thank you all. I got one keystore, the key is right. I guess it magically fixed somehow. Well, thanks guys.
I'm doing searches for 2 days and I couldn't fix this problem. I did everything, yet, this application can not work.
I want my application to work on Android 2.2 and above. Like it says "if you create your app in level 8, it'll support 95% of market".
Here are my screenshots and source codes:
I'm pasting the source code which is the easiest to get. I took this from web.
Here's the output of the command
keytool -list -keystore <path>
***************** WARNING WARNING WARNING *****************
* The integrity of the information stored in your keystore *
* has NOT been verified! In order to verify its integrity, *
* you must provide your keystore password. *
***************** WARNING WARNING WARNING *****************
Keystore type: JKS Keystore provider: SUN
Your keystore contains 1 entry
androiddebugkey, 15.Mar.2013, PrivateKeyEntry,
Certificate fingerprint (SHA1): xxx
main.xml file:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="AIzaSyDim-x5Gxxx"
/>
manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidhive.googlemaps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<!-- Add Google Map Library -->
<uses-library android:name="com.google.android.maps" />
<activity
android:name=".AndroidGoogleMapsActivity"
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>
<!-- Allow to connect with internet -->
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
java file (no need to paste it all, but I guess it's best to paste it all)
http://pastebin.com/yF95Rcbd
Here are my screenshots:
http://i.imgur.com/gExHpUG.png
http://i.imgur.com/AMOXKhr.png
http://i.imgur.com/Aqon97Y.png
I'm trying to compile this app to Android 4.2.2, but I tried and want to make it work in 2.2 and above.
Here's the Android tab of the properties window just to make sure:
http://i.imgur.com/ht0CQwT.png
Here's my log
03-20 07:01:20.145: W/System.err(956): at java.lang.Thread.run(Thread.java:856)
03-20 07:01:20.665: W/System.err(956): IOException processing: 26
03-20 07:01:20.665: W/System.err(956): java.io.IOException: Server returned: 3
03-20 07:01:20.665: W/System.err(956): at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
03-20 07:01:20.675: W/System.err(956): at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
03-20 07:01:20.675: W/System.err(956): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
03-20 07:01:20.675: W/System.err(956): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
03-20 07:01:20.675: W/System.err(956): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
These lines repeat all the time.
Thank you very much.
Your post appears to contain code that is not properly formatted as code" error made
me delete the blank lines. Sorry for the messed up codes.
http://i.imgur.com/ht0CQwT.png
See the snapshot. You did not add Google Play Services library that is require for displaying Google Android Map V2. Please download and add that library and then try again.
Please also see the target. Your target is 4.2.2 and your are accessing it on 2.2. Change the target to 2.2 and use support fragment.
Thanks,
I have solved this issue,
Open your Google APIs Console
Choose API Access
Edit allowed Android apps from your API Key
Change the package name with your package name
Example: 00:06:A5:0E:04:A2:1E:8F:FE:6B:7F:46:23:C3:xx:xx:xx:xx:xx:xx;com.example.androidmapview
You are missing permissions and meta-data for API KEY.
Read this carefully: https://developers.google.com/maps/documentation/android/start
Working with android mapapi v2 ,the main reason is you must add play service to your app,like below :
<permission
android:name="com.example.androidmapview.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.androidmapview.permission.MAPS_RECEIVE" />
Use fragment class in Layout:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
And change your manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidmapview"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<permission
android:name="com.example.androidmapview.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.androidmapview.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<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" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.androidmapview.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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"></meta-data>
</application>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
</manifest>
in activity:
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.SupportMapFragment;
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SupportMapFragment fragment = new SupportMapFragment();
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, fragment).commit();
}
}
For more info check the link which will explain you in details about api v2
I solved my blank screen problem with zoom in/out buttons like that.(it happens after I changed my package name)
Delete the keystore file
Create a new keystore file
Get SHA1 fingerprint
Go to API Console
Create a new Android App.
Paste your fingerprint
Use the given API Key in your Manifest File
That worked for me

Categories