草庐IT

java - AVD 无法使用 AVD 测试任何应用程序

coder 2023-11-23 原文

我在使用运行 4.0.3 操作系统的 HTC One V 开发我的应用程序时遇到了一个非常奇怪的问题。现在,该应用程序在我的和其他一些随机的 2.2、2.3 和 4+ 设备上运行良好,但在某些设备上,尽管它们上面安装了 GooglePlayStore,应用程序启动并加载,但在其他设备上不显示 map ,尽管它们上面安装了 GPSstore 应用程序崩溃说 GPSstore/Service 不存在。

我尝试在 AVD Devies 上测试该应用程序,但它们都没有安装 GooglePlayStore。我试过 Google Play on Android 4.0 emulator将 GPSstore 推给他们的方法,但没有成功。

我的机器人 SDK 已完全更新:

我用

在我的主要 Activity 中,我检查是否存在 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);
    }
  }

检查 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);
  }
}

我的 map 只是在我的 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));
  }

我没有任何想法我无法让 GooglePlay 服务在 AVD 2.2+ 上运行我尝试了 AVD 4.4 Google Play API 它带有 GPService 但我不会显示 map 。所以直接指出我的子问题:

1) 如果从 2.2 到 4.4 的所有 AVD 都没有使用 GooglePlay 服务,那么我们如何在没有多部手机的情况下测试多部手机和操作系统版本的应用程序。

2) 是否有确定的方式或更合适的方式在旧设备上显示 GoogleMap 我说的是 Android 2.2+ 我使用最简单的方式来显示我的 map 我的布局 xml 中有一个 SupportMap Fragment 元素。我遇到的问题是,某些带有 GooglePlayStore 的 2.2 和 2.3 手机会或不会打开应用程序,那些打开应用程序的手机不会显示 map ,但会在底部显示 map 缩放控件和 Google Logo 。

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>

最简单的解决方案:
对于遇到无法通过 AVD 完全测试您的应用程序这个问题的所有 friend ,请切换到 Genymotion 模拟器,它可以挽救生命。它速度更快,错误更少,并且支持真实手机的每一个功能,并使自 2.2 以来的 Android 应用程序测试变得更加容易。

我去了 Genny,再也没有回头。

最佳答案

根据这个问题的答案:Google Maps - "App won't run unless you update Google Play services" ,它引用了这篇 Google+ 帖子:https://plus.google.com/+AndroidDevelopers/posts/Tyz491d96Ci ,模拟器不支持在您的应用程序中使用 map ;该帖子中有许多尖刻的回复。

其中一个回复提到了这个问题:This app won't run unless you update Google Play Services (via Bazaar)其中描述了一些模拟器黑客攻击,如果没有其他方法可以尝试。

关于java - AVD 无法使用 AVD 测试任何应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20226181/

有关java - AVD 无法使用 AVD 测试任何应用程序的更多相关文章

  1. ruby - 如何使用 Nokogiri 的 xpath 和 at_xpath 方法 - 2

    我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div

  2. ruby - 使用 RubyZip 生成 ZIP 文件时设置压缩级别 - 2

    我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看ruby​​zip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d

  3. ruby - 为什么我可以在 Ruby 中使用 Object#send 访问私有(private)/ protected 方法? - 2

    类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc

  4. ruby-on-rails - 使用 Ruby on Rails 进行自动化测试 - 最佳实践 - 2

    很好奇,就使用ruby​​onrails自动化单元测试而言,你们正在做什么?您是否创建了一个脚本来在cron中运行rake作业并将结果邮寄给您?git中的预提交Hook?只是手动调用?我完全理解测试,但想知道在错误发生之前捕获错误的最佳实践是什么。让我们理所当然地认为测试本身是完美无缺的,并且可以正常工作。下一步是什么以确保他们在正确的时间将可能有害的结果传达给您? 最佳答案 不确定您到底想听什么,但是有几个级别的自动代码库控制:在处理某项功能时,您可以使用类似autotest的内容获得关于哪些有效,哪些无效的即时反馈。要确保您的提

  5. ruby - 在 Ruby 中使用匿名模块 - 2

    假设我做了一个模块如下:m=Module.newdoclassCendend三个问题:除了对m的引用之外,还有什么方法可以访问C和m中的其他内容?我可以在创建匿名模块后为其命名吗(就像我输入“module...”一样)?如何在使用完匿名模块后将其删除,使其定义的常量不再存在? 最佳答案 三个答案:是的,使用ObjectSpace.此代码使c引用你的类(class)C不引用m:c=nilObjectSpace.each_object{|obj|c=objif(Class===objandobj.name=~/::C$/)}当然这取决于

  6. ruby - 使用 ruby​​ 和 savon 的 SOAP 服务 - 2

    我正在尝试使用ruby​​和Savon来使用网络服务。测试服务为http://www.webservicex.net/WS/WSDetails.aspx?WSID=9&CATID=2require'rubygems'require'savon'client=Savon::Client.new"http://www.webservicex.net/stockquote.asmx?WSDL"client.get_quotedo|soap|soap.body={:symbol=>"AAPL"}end返回SOAP异常。检查soap信封,在我看来soap请求没有正确的命名空间。任何人都可以建议我

  7. ruby - 在 Ruby 程序执行时阻止 Windows 7 PC 进入休眠状态 - 2

    我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0

  8. python - 如何使用 Ruby 或 Python 创建一系列高音调和低音调的蜂鸣声? - 2

    关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。

  9. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  10. ruby-on-rails - 'compass watch' 是如何工作的/它是如何与 rails 一起使用的 - 2

    我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t

随机推荐