Я пишу приложение для Android, которое использует карты Google APIv2. Он работает практически на всех устройствах. Но есть проблема с Android 4.0.4 и 4.2.2. Сбой приложений во время инициализации карты.Google Maps APIv2
В Android 4.0.4 он работает после перезагрузки, на 4.2.2 он не работает.
Вот код инициализации:
public class MyMapActivity extends FragmentActivity implements LocationListener
{
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_map);
// Getting Google Play availability status
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
// Showing status
if(status!=ConnectionResult.SUCCESS)
{ // Google Play Services are not available
int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
dialog.show();
}
else
{// Google Play Services are available
// Getting reference to the SupportMapFragment of activity_main.xml
SupportMapFragment fm = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
// Getting GoogleMap object from the fragment
map = fm.getMap();
// Enabling MyLocation Layer of Google Map
map.setMyLocationEnabled(true);
}
}
}
activity_my_map.xml:
<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"
tools:context=".MainActivity" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
Используйте LogCat для проверки трассировки стека Java, связанной с вашим сбоем. Если вы не можете определить, что такое трассировка стека, отредактируйте свой вопрос и вставьте трассировку стека в вопрос. – CommonsWare