I have an application with AdMob advertisement. I have created an account and have an application_id. It is all right, the application sends requests for server, server fixes it. But the application doesn't show me a banner. My code:
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/linear"
android:orientation="vertical" >
</LinearLayout>
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nda.ad"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name=".AdmobActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
</application>
</manifest>
And code of my activity:
package com.nda.ad;
import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
public class AdmobActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout layout = (LinearLayout)findViewById(R.id.linear);
// Create the adView
// Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID
AdView adView = new AdView(this, AdSize.BANNER, "a14eb6c98335a35");
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
AdRequest request = new AdRequest();
request.setTesting(true);
adView.loadAd(request);
}
}
Where have I made a mistake?
Related
EDIT: Man this is awkward, MKer is right, I corrected the code and now can see the ScaleBar. No luck yet with the my location issue.
I have been trying for a few days and I'm starting to pull my hair. Noob at Android and Osmdroid.
I can build and have done so, with success, osmdroid demo apps. Also tried the OSMbonuspack and had the navigator working with the "find me" overlay, scale, etc.
Problem is whenever I make my own app, the only overlay that shows up and works in my map is the compass. I guess I am doing something wrong but can't find any info on the subject.
I have tested this with Genymotion virtual devices (there not even the compass shows) amd my 6.0 mobile where compass works, but no MyLocation or even Scale.
I have given the app permissions, and all I see in the android log are messages about tiles loading when moving the map. Plus this error which I haven't found much info about except in chinese.
E/IzatSvc_PassiveLocListener: E/Exiting with error virtual void izat_manager::IzatPassiveLocationListener::onLocationChanged(const izat_manager::IzatLocation*, izat_manager::IzatLocationStatus) line 113 "1"
Any help welcome!
Here is my manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.anemptyappmap">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<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/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Here is MainActivity.java
package com.example.anemptyappmap;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import org.osmdroid.api.IMapController;
import org.osmdroid.tileprovider.constants.OpenStreetMapTileProviderConstants;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.ScaleBarOverlay;
import org.osmdroid.views.overlay.compass.CompassOverlay;
import org.osmdroid.views.overlay.compass.InternalCompassOrientationProvider;
import org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider;
import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay;
public class MainActivity extends AppCompatActivity {
//Vars para mapa
private MyLocationNewOverlay mLocationOverlay;
private CompassOverlay mCompassOverlay=null;
//private MinimapOverlay mMinimapOverlay;
private ScaleBarOverlay mScaleBarOverlay;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Context context = getApplicationContext();
final DisplayMetrics dm = context.getResources().getDisplayMetrics();
OpenStreetMapTileProviderConstants.setUserAgentValue(BuildConfig.APPLICATION_ID);
String cachePath = getCacheDir().getAbsolutePath();
org.osmdroid.tileprovider.constants.OpenStreetMapTileProviderConstants.setCachePath(cachePath);
//important! set your user agent to prevent getting banned from the osm servers
//Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));
MapView mMapView = (MapView) findViewById(R.id.mMapView);
mMapView.setTileSource(TileSourceFactory.MAPNIK);
//map.setBuiltInZoomControls(true);
mMapView.setMultiTouchControls(true);
mLocationOverlay = new MyLocationNewOverlay(new GpsMyLocationProvider(context),mMapView);
mLocationOverlay.enableMyLocation();
mLocationOverlay.setDrawAccuracyEnabled(true);
//mLocationOverlay.setPersonIcon();
mLocationOverlay.enableMyLocation();
mMapView.getOverlays().add(this.mLocationOverlay);
mCompassOverlay = new CompassOverlay(context, new InternalCompassOrientationProvider(context), mMapView);
mCompassOverlay.enableCompass();
mMapView.getOverlays().add(this.mCompassOverlay);
mScaleBarOverlay = new ScaleBarOverlay(mMapView);
mScaleBarOverlay.setScaleBarOffset(dm.widthPixels / 2, 10);
mScaleBarOverlay.setCentred(true);
mMapView.getOverlays().add(this.mScaleBarOverlay);
//this.mScaleBarOverlay.setAlignBottom(true);
//this.mScaleBarOverlay.setCentred(true);
this.mScaleBarOverlay.enableScaleBar();
//this.mMinimapOverlay = new MinimapOverlay();
IMapController mapController = mMapView.getController();
mapController.setZoom(13);
GeoPoint startPoint = new GeoPoint(43.3600, -8.2800);
mapController.setCenter(startPoint);
// mMapView.invalidate();
}
}
And the layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="com.example.anemptyappmap.MainActivity">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/crossfade_content"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<org.osmdroid.views.MapView android:id="#+id/mMapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
I am developing a game in libgdx. I read the official docs and tried to integrate MobClix Ads in my App but eclipse can't resolve this constructor for ADView class: (for Example):
AdView ad = new AdView(this, AdSize.BANNER, "a14d91b10f12454");
This line of code give me an error.
Maybe my import is not correct? I import this:
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
And the same for:
adView.loadAd(new AdRequest());
I tried to search for an answer but I coudn't find, Does somone know how to resolve this?
Sorry for my poor english.
Put this code to mainactivity
import android.app.Activity;
import android.os.Bundle;
import com.startapp.android.publish.StartAppAd;
public class MainActivity extends Activity {
private StartAppAd add = new StartAppAd(this);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StartAppAd.init(this, "105158220", "205151606");
//StartAppSearch.init(this, "105158220", "205151606");
setContentView(R.layout.activity_main);
if(add.isReady())
{
add.showAd(); // show the ad
add.loadAd();
}
//a.loadAd(AdMode.FULLPAGE);
}
#Override
public void onResume(){
super.onResume();
add.onResume();
}
#Override
public void onBackPressed() {
add.onBackPressed();
super.onBackPressed();
}
#Override
public void onPause() {
super.onPause();
add.onPause();
}
}
put this into your xml file
<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"
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=".MainActivity" >
<com.startapp.android.publish.banner.banner3d.Banner3D
android:id="#+id/startApp3DBanner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
put this into ur Manifest file
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.GET_TASKS" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.start_up_app.MainActivity"
android:configChanges="keyboard|keyboardHidden|orientation"
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.startapp.android.publish.list3d.List3DActivity"
android:taskAffinity="com.example.start_up_app.AppWall"
android:theme="#android:style/Theme" />
<activity
android:name="com.startapp.android.publish.AppWallActivity"
android:configChanges="orientation|keyboardHidden"
android:taskAffinity="com.example.start_up_app.AppWall"
android:theme="#android:style/Theme.Translucent" />
</application>
</manifest>
for you have to use StartAppCommon-1.0.1.jar and StartAppInApp-2.0.7.jar
my xml code is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.google.android.maps.MapView
android:id="#+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enable="true"
android:clickable="true"
android:apiKey="0THdCiXY7jaJ9Br1ZQahFE4Lu1xTv1hAiVJBvxQ"
/>
</RelativeLayout>
and manifest is:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.haha"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application android:icon="#drawable/icon" android:label="#string/app_name">
<uses-library android:name="com.google.android.maps"/>
<activity android:name=".NewActivity"
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>
And this is main code:
package com.google.haha;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import android.app.Activity;
import android.os.Bundle;
public class NewActivity extends MapActivity {
/** Called when the activity is first created. */
MapController mControl;
GeoPoint GeoP;
MapView mapV;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapV=(MapView)findViewById(R.id.mapView);
mapV.displayZoomControls(true);
mapV.setBuiltInZoomControls(true);
double lat=21.00;
double longi=79.00;
GeoP=new GeoPoint((int)(lat*1E6),(int)(longi*1E6));
mControl=mapV.getController();
mControl.animateTo(GeoP);
mControl.setZoom(12);
}
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
Everything is fine but I am getting error an on line:
mapV=(MapView)findViewById(R.id.mapView);
id field is not recognised.
try to clean and rebuild your project, because that problem comes up sometimes on Eclipse IDE , the id of your MapView is not recognised on your R.java file :
Project ==> Clean ==> Choose your Project and Clic OK
<com.google.android.maps.MapView
android:id="#+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
**android:enable="true"** MUST BE android:enabled="true"
android:clickable="true"
android:apiKey="0THdCiXY7jaJ9Br1ZQahFE4Lu1xTv1hAiVJBvxQ"
/>
</RelativeLayout>
I tried to write a simple google map application to display simple map but doesn't give me any output.
I pasted my code below:
AnroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.HelloGoogleMaps"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application android:icon="#drawable/icon" android:label="#string/app_name">
<uses-library android:name="com.google.android.maps" />
<activity android:name=".HelloGoogleMaps"
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>
My layout file is:
map.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<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="0Z1oyeAgSpj4FSEtenPqiL7RsCXA_pVPQhvtpdA"
/>
</LinearLayout>
And my java class file is:
HelloGoogleMaps.java
package org.HelloGoogleMaps;
import com.google.android.maps.MapView;
import android.app.Activity;
import android.os.Bundle;
public class HelloGoogleMaps extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
}
protected boolean isRouteDisplayed() {
return false;
}
}
I can't see your layout file, but have you set a proper API key?
http://code.google.com/android/maps-api-signup.html
Your HelloGoogleMaps should inherit the MapsActivity
Just change your code to
public class HelloGoogleMaps extends MapActivity {
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
i have a little trouble with the android mapview. It simply crashes every time i try to open the app!
Code:
package com.jappapps.android.travelbuddy;
import android.os.Bundle;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
public class TravelBuddy extends MapActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); // changed to lowercase
MapView mapView = (MapView) findViewById(R.id.mapview); // match id in main.xml
mapView.setBuiltInZoomControls(true);
}
#Override
protected boolean isRouteDisplayed() {
return false;
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jappapps.android.travelbuddy"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".TravelBuddy"
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>
<uses-sdk android:minSdkVersion="3" />
<uses-library android:name="com.google.android.maps" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>
Main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<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="0QrW-CcUIzU_fxIS_9O-BkFnuPC-rTj-7t3Q0xw"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello"
/>
</LinearLayout>
The <uses-library android:name="com.google.android.maps" /> line should be inside the <application> tags