android - SOLVED_Android: Crash start application using api google maps -
hi i'm following https://developers.google.com/maps/documentation/android/start#installing_the_google_maps_android_v2_api learn use google map api.
this manifest:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.dude.uniplaces" android:versioncode="1" android:versionname="1.0" > <uses-feature android:glesversion="0x00020000" android:required="true"/> <uses-sdk android:minsdkversion="8" android:targetsdkversion="17" /> <permission android:name="com.dude.uniplaces.permission.c2d_message" android:protectionlevel="signature" /> <uses-permission android:name="com.dude.uniplaces.permission.c2d_message" /> <uses-permission android:name="com.google.android.c2dm.permission.receive" /> <uses-permission android:name="android.permission.get_accounts" /> <uses-permission android:name="android.permission.wake_lock" /> <uses-permission android:name="android.permission.vibrate" /> <uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.access_network_state" /> <uses-permission android:name="android.permission.access_fine_location" /> <uses-permission android:name="android.permission.access_mock_location" /> <uses-permission android:name="android.permission.access_coarse_location" /> <uses-permission android:name="com.google.android.providers.gsf.permission.read_gservices"/> <uses-permission android:name="android.permission.write_external_storage"/> <permission android:name="com.dude.uniplaces.permission.maps_receive" android:protectionlevel="signature"/> <uses-permission android:name="com.dude.uniplaces.permission.maps_receive"/> <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <uses-library android:name="com.google.android.maps" /> <receiver android:name="com.google.android.gcm.gcmbroadcastreceiver" android:permission="com.google.android.c2dm.permission.send" > <intent-filter> <action android:name="com.google.android.c2dm.intent.receive" /> <action android:name="com.google.android.c2dm.intent.registration" /> <category android:name="com.dude.uniplaces" /> </intent-filter> </receiver> <service android:name="com.dude.uniplaces.gcmintentservice" /> <activity android:name="com.dude.uniplaces.index" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name="com.dude.uniplaces.dude" android:label="dude" > </activity> <activity android:name="com.dude.uniplaces.sendmess" android:label="sendmess" > </activity> <meta-data android:name="com.google.android.maps.v2.api_key" android:value="aizasybuo0v3_phsrxfngyj68aezkcuthinw6oa"/> </application> </manifest>
this xml file of main activity:
<?xml version="1.0" encoding="utf-8"?> <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" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context=".index" > <button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="invia messaggio" android:onclick="sendmex" /> <fragment android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" android:name="com.google.android.gms.maps.mapfragment"/> </relativelayout>
this main activity :
package com.dude.uniplaces; import static com.dude.uniplaces.commonutilities.display_message_action; import static com.dude.uniplaces.commonutilities.extra_message; import static com.dude.uniplaces.commonutilities.sender_id; import java.util.hashmap; import java.util.map; import android.app.activity; import android.app.progressdialog; import android.content.broadcastreceiver; import android.content.context; import android.content.intent; import android.content.intentfilter; import android.location.criteria; import android.location.location; import android.location.locationmanager; import android.os.asynctask; import android.os.bundle; import android.provider.settings; import android.view.view; import android.widget.toast; import com.google.android.gcm.gcmregistrar; public class index extends activity { progressdialog progressbar; asynctask<void, void, void> mregistertask; @override public void oncreate(bundle savedinstancestate){ super.oncreate(savedinstancestate); setcontentview(r.layout.index); // phone ready gcmregistrar.checkdevice(this); // checking manifest gcmregistrar.checkmanifest(this); registerreceiver(mhandlemessagereceiver, new intentfilter(display_message_action)); // ottieni il registration id final string regid = gcmregistrar.getregistrationid(this); // controllo se sono registrato if (regid.equals("")) { // mi registro gcmregistrar.register(this, sender_id); } else { // sono registrato if (!gcmregistrar.isregisteredonserver(this)) { // provo registrarmi ancora final context context = this; mregistertask = new asynctask<void, void, void>() { @override protected void doinbackground(void... params) { serverutilities.register(context, regid); return null; } @override protected void onpostexecute(void result) { mregistertask = null; } }; mregistertask.execute(null, null, null); } } /* here should registred */ /* time take gps coordinates */ locationmanager service = (locationmanager) getsystemservice(location_service); boolean enabled = service.isproviderenabled(locationmanager.gps_provider); // check if enabled , if not send user gsp settings // better solution display dialog , suggesting // go settings if (!enabled) { intent intent = new intent(settings.action_location_source_settings); startactivity(intent); } locationmanager locationmanager = (locationmanager) getsystemservice(context.location_service); map<string, string> params = new hashmap<string, string>(); criteria criteria = new criteria(); string provider = locationmanager.getbestprovider(criteria, false); location location = locationmanager.getlastknownlocation(provider); string message="x"; string id = gcmregistrar.getregistrationid(this); if( location != null) message = string.format("%1$s \n%2$s \n%3$s",id, location.getlongitude(), location.getlatitude() ); if(location == null ) params.put("one", "bonaa"); else params.put("one", message); serverutilities su = new serverutilities(); su.go("http://unipiapp.altervista.org/cord.php",params); } /** * ricevo notifica push * */ private final broadcastreceiver mhandlemessagereceiver = new broadcastreceiver() { @override public void onreceive(context context, intent intent) { string newmessage = intent.getextras().getstring(extra_message); // sveglia il telefono se รจ in stand-by wakelocker.acquire(getapplicationcontext()); // visualizza il messaggio toast.maketext(getapplicationcontext(), "new message: " + newmessage, toast.length_long).show(); // rilascia il wavelocker wakelocker.release(); } }; @override protected void ondestroy() { if (mregistertask != null) { mregistertask.cancel(true); } try { unregisterreceiver(mhandlemessagereceiver); gcmregistrar.ondestroy(this); } catch (exception e) { } super.ondestroy(); } /* function call clickin on button */ public void sendmex(view w) { intent intent = new intent(index.this, sendmess.class); startactivity(intent); } } /* end class */
i downloaded google play service , add workspace, when try start application in phone, crashes:
05-04 20:11:24.441: e/androidruntime(11190): fatal exception: main 05-04 20:11:24.441: e/androidruntime(11190): java.lang.runtimeexception: unable start activity componentinfo{com.dude.uniplaces/com.dude.uniplaces.index}: android.view.inflateexception: binary xml file line #19: error inflating class fragment
can me, please?
best regards
edit: modified index.xml saw me, added (think) in right way google libs can see in attache image, still take crash!
http://img442.imageshack.us/img442/3539/73174342.png
last edit:
i solved adding import android.support.v4.app.fragmentactivity; , chancing extends activity fragmentactivity
thanks all
right click on project , select android tools -> add support library ...
and change this
<fragment android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" android:name="com.google.android.gms.maps.mapfragment"/>
to this
<fragment android:id="@+id/map" android:name="com.google.android.gms.maps.supportmapfragment" android:layout_width="match_parent" android:layout_height="match_parent" />
and confirm have included google play services correctly right click on project , select properties. in left tab select android. in botton of right pane shoud see frame label library. if google play added correctly appear green check mark. make sure google play project open in workspace.
Comments
Post a Comment