java AVD无法使用AVD测试任何应用程序
我有一个非常奇怪的问题,我用运行4.0.3操作系统的HTC One V开发了我的应用程序。现在,该应用程序在我的和其他一些随机的2.2、2.3和4+设备上运行得非常好,但在一些设备上,尽管它们上有Google PlayStore,但应用程序启动并加载,但不会在其他设备上显示地图,尽管它们上有GPStore,应用程序崩溃,称GPStore/服务不存在
我试图在AVD设备上测试该应用程序,但没有一个安装了Google PlayStore。我尝试了Google Play on Android 4.0 emulator方法将GPStore推向他们,但没有成功
我的droid SDK已完全更新:
我用
在我的主要活动中,我会检查Google Play服务/商店是否存在,以确定是否可以使用Google地图:
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);
}
}
检查Google Play服务状态的方法位于“我的服务”中。java bellow:
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);
}
}
我的地图是在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));
}
我没有主意了,我无法在AVD 2.2+上运行Google Play服务,我尝试了AVD 4.4 Google Play API,它提供GPService,但我不会显示地图。所以直接指出我的子问题:
1)如果从2.2到4.4的所有AVD都没有使用GooglePlay服务,那么我们如何在没有多部手机的情况下测试多部手机和操作系统版本的应用程序
2)是否有一种确定的方法或更合适的方法在旧设备上显示Google地图我说的是Android 2.2+我使用了最简单的方法来显示我的地图我的布局xml中有一个SupportMap片段元素。我遇到的问题是,一些2.2和2.3手机上安装了Google PlayStore,它们会或不会打开应用程序。那些打开应用程序的手机不会显示地图,但它们会在底部显示地图缩放控件和Google徽标
3)我添加了布局文件,但我没有安卓手机,AVD不允许我测试需要Google PlayServices的应用程序。我下面显示的布局是否可能是由于覆盖布局导致的问题
我基本上在背景中有一个框架布局,我有谷歌地图,在上面的上角我有一个微调器和一个按钮。我上次测试这个应用程序时,它在我的手机HTC One V Android 4.0.3上运行
<FrameLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:tools="http://schemas.安卓.com/tools"
xmlns:map="http://schemas.安卓.com/apk/res-auto"
安卓:id="@+id/root_view"
安卓:layout_width="fill_parent"
安卓:layout_height="fill_parent"
安卓:orientation="vertical" >
<fragment
安卓:id="@+id/map"
安卓:name="com.google.安卓.gms.maps.SupportMapFragment"
安卓:layout_width="fill_parent"
安卓:layout_height="fill_parent"
/>
<Button
安卓:id="@+id/gpsbttn"
安卓:layout_width="28dp"
安卓:layout_height="28dp"
安卓:layout_marginLeft="10dp"
安卓:layout_marginTop="10dp"
安卓:background="@drawable/gps"
安卓:minHeight="28dip"
安卓:minWidth="28dip"
安卓:text="" />
<Spinner
安卓:id="@+id/bankslist"
安卓:layout_width="match_parent"
安卓:layout_height="36dp"
安卓:layout_marginLeft="48dp"
安卓:layout_marginRight="10dp"
安卓:layout_marginTop="10dp"
安卓:entries="@array/banks_list"
安卓:prompt="@string/banks_prompt" />
</FrameLayout>
最简单的解决方案:
对于所有遇到无法通过AVD完全测试应用程序这一问题的朋友,切换到Genymotion Emulator是一个救命稻草。它速度更快,故障更少,支持真实手机的每一项功能,并使自2.2以来的Android应用测试变得更加容易
我去了Genny,再也没有回头
# 1 楼答案
除了Scott提到的解决方案外,根据Play Services文档,所有针对4.2.2或更高版本的AVD都将支持Play Services:http://developer.android.com/google/play-services/setup.html
也有一些人能够在旧的AVD上安装Play服务,但其合法性可能值得怀疑:
# 2 楼答案
根据对这个问题的回答:Google Maps - "App won't run unless you update Google Play services",它引用了Google+post:https://plus.google.com/+AndroidDevelopers/posts/Tyz491d96Ci,emulator不支持在应用程序中使用地图;在那篇帖子里有许多尖刻的回复
其中一个回复提到了这个问题:This app won't run unless you update Google Play Services (via Bazaar),它描述了一些仿真器黑客攻击,如果没有其他方法可以尝试