7
votes

I build my app with API17 as target and minSDK 12 now I have to make the app works on andorid.2.2 (API8) devices I chang the minSDK to 8 and the target SDK to 8 also I fix some errors but I don't know how to fix this

map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

(error : getFragmentManager() is undefined ) how to use google map v2
I added these to the Activity

import android.support.v4.app.* ;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.FragmentManager;

what else should I do to fix this ??

3
you have to use getSupportFragmentManager() also extend FragmentActivity instead of Activity - Raghunandan

3 Answers

14
votes

You class must extend FragmentActivity. Make sure you have added support library.

SupportMapFragment fm = (SupportMapFragment)   getSupportFragmentManager().findFragmentById(R.id.map);
mMap = fm.getMap(); 

Also in your xml

<fragment
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

Also make sure you have imported

 import android.support.v4.app.FragmentActivity;  
 import com.google.android.gms.maps.SupportMapFragment;  
0
votes

you need getSupportFragmentManager() as described in this document