Ste*_*ess 8 java android google-maps
我有一个非常奇怪的问题,我使用运行4.0.3操作系统的HTC One V开发了我的应用程序.现在应用程序在我的和其他很少的其他2.2和2.3和4+设备上工作非常好,但是在某些设备上,尽管它们上面有GooglePlayStore,应用程序启动并加载但不显示其他地图,尽管它们上面有GPStore应用程序崩溃说GPStore /服务不存在.
我试图在AVD Devies上测试应用程序,但没有一个安装了GooglePlayStore.我尝试使用Android 4.0模拟器上的Google Play将GPS推送给他们,但没有成功.
我的droid SDK已完全更新:

我编译我的应用程序

在我的主要活动中,我会检查Google Play服务/商店是否存在,以确定是否可以使用GoogleMaps:
public class Map extends FragmentActivity implements Observer
{
private MapAgent agent;
private Locator locator;
private Spinner spinner;
private Button gps;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Get a new instance of Locator agent
locator = new Locator();
// Register as Observer to Locator agent
locator.addObserver(this);
// Check if Internet connection is available
if(Services.connectivityServiceState(this))
{
// We have a working Internet connection
// Check if we have a GooglePS in operating mode
if(Services.playServiceState(this))
{
// Load the map
setContentView(R.layout.activity_map);
// Fetch dropdown list & gps button reference
spinner = (Spinner) findViewById(R.id.bankslist);
gps = (Button) findViewById(R.id.gpsbttn);
// Register event listener with gps button
gps.setOnClickListener(new GpsAction(this));
// Register event listener with spinner
spinner.setOnItemSelectedListener(new SpinnerAction());
// Fetch our map
agent = new MapAgent(this);
// Move map camera to initial position
agent.initialPosition();
} else {
// GooglePS is not in operating mode
Messages.playNotificationMessage(this);
}
} else {
// No Internet connection
// Prompt user to turn on WiFi or Mobile
Messages.internetConnectionRequestMessage(this);
}
}
Run Code Online (Sandbox Code Playgroud)
检查GooglePlay服务状态的方法位于我的Services.java中:
public class Services
{
/**
* OPERATING CODES
*/
private static final int GPS_ERR_REQUEST = 9000;
/**
* Test device for GooglePlayServices, required for
* GoogleMaps API V2.
*
* @param Activity
* @result boolean
*/
public static boolean playServiceState(Activity context)
{
// Fetch GooglePS operating code
int code = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
// Check if GooglePS is operating
if(code == ConnectionResult.SUCCESS)
{
// We have GooglePS in working condition
return true;
}
// We have an error, check if it can be resolved by user
/*if(GooglePlayServicesUtil.isUserRecoverableError(code))
{
// We can solve this error pull up GooglePS guide dialog
Dialog guide = GooglePlayServicesUtil.getErrorDialog(code, context, GPS_ERR_REQUEST);
// Show the guide dialog
guide.show();
// Dispose of our activity
context.finish();
}*/
// We do not have GooglePS in operating mode
// solve error and retry
return false;
}
/**
* Tests devices Wi-Fi and Mobile network for a
* working Internet connection.
*
* @param Activity
* @return boolean
*/
public static boolean connectivityServiceState(Activity context)
{
// Fetch a CM instance
ConnectivityManager con = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
// Test both carriers for a working Internet connection
NetworkInfo wifi = con.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
NetworkInfo mobi = con.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
// Check for Internet connection
if(wifi.isConnected() || mobi.isConnected())
{
// We have a working internet connection
return true;
}
// No internet connection
return false;
}
/**
* Test NETWORK service to determine if Google Location
* services are enabled or not.
*/
public static boolean networkServiceState(Activity context)
{
// Fetch a LM instance
LocationManager provider = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
// Return true for enabled GLS
return provider.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
}
/**
* Tests GPS service to determine if GPS
* is enabled or not.
*
* @param Activity
* @result boolean
*/
public static boolean gpsServiceState(Activity context)
{
// Fetch a LM instance
LocationManager provider = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
// Return true for enabled GPS
return provider.isProviderEnabled(LocationManager.GPS_PROVIDER);
}
/**
* Checks if a GPS Radio is present
* within the device.
*
* @param Activity
* @return boolean
*/
public static boolean hasGPS(Activity context)
{
// Refere to devices package manager for GPS service
return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);
}
}
Run Code Online (Sandbox Code Playgroud)
我的地图只是在我的MapAgent类中处理,没有什么令人印象深刻的只是处理标记.
public MapAgent(FragmentActivity context)
{
// Fetch the map support fragment
SupportMapFragment fragment = ((SupportMapFragment) context.getSupportFragmentManager().findFragmentById(R.id.map));
// Fetch map and view
map = fragment.getMap();
// Set initial zoom
zoom = 7;
// Check if this is the first run
final SharedPreferences prefs = context.getSharedPreferences("slo.bankomati.core", Context.MODE_PRIVATE);
if(prefs.getBoolean("firstrun", true))
{
// Check if database exists and delete it
if(Database.exists(context))
{
Database.delete(context);
}
prefs.edit().putBoolean("firstrun", false);
}
// Fetch all atms
try {
db = new Database(context);
atms = db.getAtms();
db.close();
} catch (Exception e) {
// TODO: Temporary solution
}
// Create an empty array for filtered results
filtered = new ArrayList<Atm>();
markers = new HashMap<Marker, Atm>();
// Reference the resources and context
this.resources = context.getResources();
this.context = context;
// Register camera & info window listener with the map
map.setOnCameraChangeListener(this);
//map.setOnInfoWindowClickListener(new ShowDetails(context, resources));
map.setOnMarkerClickListener(new ShowDetails(context));
}
Run Code Online (Sandbox Code Playgroud)
我没有想法我无法在AVD 2.2+上运行GooglePlay服务我尝试了AVD 4.4 Google Play API它来到GPService但是我不会显示地图.所以直接指出我的子问题:
1)如果从2.2到4.4的所有AVD都没有使用GooglePlay服务,那么我们如何在没有多个电话的情况下测试多个电话和操作系统版本的应用程序.
2)有没有一种确定的方法或更合适的方式在旧设备上显示GoogleMap我说的是Android 2.2+我用最简单的方式来显示我的地图我在我的Layout xml中有一个SupportMap Fragment元素.我遇到的问题是有些手机上有GooglePlayStore的2.2和2.3手机会打开应用程序但打开应用程序的手机不会显示地图,但它们会在底部显示地图缩放控件和Google徽标.
3)我添加了我的布局文件,但我没有我的Android手机,AVD不允许我测试需要GooglePlayServices的应用程序我的布局显示下面可能是由于叠加布局引起的问题.
我基本上在背景中有一个框架布局我有GoogleMap,在顶角的顶部我有一个微调器和一个按钮.当我上次测试这个应用程序时,它可以在我的手机HTC One V Android 4.0.3上运行.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/root_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<Button
android:id="@+id/gpsbttn"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:background="@drawable/gps"
android:minHeight="28dip"
android:minWidth="28dip"
android:text="" />
<Spinner
android:id="@+id/bankslist"
android:layout_width="match_parent"
android:layout_height="36dp"
android:layout_marginLeft="48dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:entries="@array/banks_list"
android:prompt="@string/banks_prompt" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
最简单的解决方案:
对于遇到这个无法通过AVD完全测试您的应用程序的问题的所有朋友,切换到Genymotion Emulator它是一个节省生命的人.它更快,更少的马车,它支持真正的手机所做的每一项功能,并使2.2以后的Android应用程序测试变得如此简单.
我去了Genny并且从未回头.
根据这个问题的答案:谷歌地图 - "应用程序将无法运行,除非您更新Google Play服务",该应用程序引用此Google+帖子:https://plus.google.com/+AndroidDevelopers/posts/Tyz491d96Ci,使用地图模拟器中不支持您的应用程序内; 该帖子中有许多痛苦的回复.
其中一个回复引用了这个问题:除非您更新Google Play服务(通过Bazaar),否则此应用程序将无法运行,该服务描述了一些模拟器黑客,如果没有其他工作正常,您可以尝试.
除了Scott提到的解决方法之外,根据Play服务文档,所有针对4.2.2或更高版本的AVD都将支持Play服务:http://developer.android.com/google/play-services/setup.html
还有一些人已经能够将Play服务安装到较旧的AVD上,但其合法性可能有问题:
| 归档时间: |
|
| 查看次数: |
493 次 |
| 最近记录: |