• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps One application base on GoogleMapsAPI,has some problems

kukudan

Lurker
It works well on the Emulator,but when I apply it on my XT800,2.2.1ROM.
It broken down.
Here is my code and logcat.Please help me to solve the problems.Thanks!

Code:
package net.learn2develop.GoogleMaps;
 
import java.io.IOException;
import java.util.List;
import java.util.Locale;
 
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
 
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import com.google.android.maps.MapView.LayoutParams;
 
import android.telephony.SmsMessage;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;
 
public class MapsActivity extends MapActivity {
        MapView mapView;
        MapController mc;
        GeoPoint p;
        public static final String PREF_FILE_NAME = "PrefFile";
        String[] coordinates = new String[2];
        String[] location = new String[2];
        String temp;
        Bundle bundle;
 
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
 
                mapView = (MapView) findViewById(R.id.mapView);
                LinearLayout zoomLayout = (LinearLayout) findViewById(R.id.zoom);
                View zoomView = mapView.getZoomControls();
 
                zoomLayout.addView(zoomView, new LinearLayout.LayoutParams(
                                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                mapView.displayZoomControls(true);
 
                // mapView.setSatellite(true); /**显示卫星视图
                // mapView.setStreetView(true); /**显示街道视图
 
                mc = mapView.getController();
 
                bundle = getIntent().getExtras();
                
                try {
                        if (bundle == null) {
                                temp = "40.849165,123.328739";
                        } else {
                                temp = bundle.getString("location");
                        }
                        location = temp.split(",");
                } catch (NumberFormatException e) {
                        e.toString();
                }
                
                
 
                for (int i = 0; i < location.length; i++) {
                        coordinates[i] = location[i];
                }
 
                double lat = Double.parseDouble(coordinates[0]);
                double lng = Double.parseDouble(coordinates[1]);
 
                p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
 
                mc.animateTo(p);
 
                mc.setZoom(17);
                MapOverlay mapOverlay = new MapOverlay();
                List<Overlay> listOfOverlays = mapView.getOverlays();
                listOfOverlays.clear();
                listOfOverlays.add(mapOverlay);
 
                mapView.invalidate();
 
        }
 
 
        class MapOverlay extends com.google.android.maps.Overlay {
                @Override
                public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
                                long when) {
                        super.draw(canvas, mapView, shadow);
 
                        // ---translate the GeoPoint to screen pixels---
                        Point screenPts = new Point();
                        mapView.getProjection().toPixels(p, screenPts);
 
                        // ---add the marker---
                        Bitmap bmp = BitmapFactory.decodeResource(getResources(),
                                        R.drawable.icon);
                        canvas.drawBitmap(bmp, screenPts.x, screenPts.y - 50, null);
                        return true;
                }
 
                public boolean onTouchEvent(MotionEvent event, MapView mapView) {
                        // ---when user lifts his finger---
                        if (event.getAction() == 1) {
                                GeoPoint p = mapView.getProjection().fromPixels(
                                                (int) event.getX(), (int) event.getY());
 
                                /** &#36890;&#36807;&#33719;&#21462;&#22352;&#26631;&#26469;&#25343;&#21040;&#22320;&#29702;&#21517;&#31216;&#21152;&#19978;&#22352;&#26631;&#26174;&#31034; **/
                                Geocoder geoCoder = new Geocoder(getBaseContext(),
                                                Locale.getDefault());
                                try {
                                        List<Address> addresses = geoCoder.getFromLocation(
                                                        p.getLatitudeE6() / 1E6, p.getLongitudeE6() / 1E6,
                                                        1);
 
                                        String add = "";
                                        if (addresses.size() > 0) {
                                                for (int i = 0; i < addresses.get(0)
                                                                .getMaxAddressLineIndex(); i++)
                                                        add += addresses.get(0).getAddressLine(i) + "\n"
                                                                        + p.getLatitudeE6() / 1E6 + ","
                                                                        + p.getLongitudeE6() / 1E6 + "\n";
                                        }
 
                                        Toast.makeText(getBaseContext(), add, Toast.LENGTH_SHORT)
                                                        .show();
                                } catch (IOException e) {
                                        e.printStackTrace();
                                }
 
                                /**
                                 * &#36890;&#36807;&#24050;&#30693;&#30340;&#22320;&#21517;&#25214;&#20986;&#20301;&#32622; Geocoder geoCoder = new
                                 * Geocoder(getBaseContext(), Locale.getDefault()); try {
                                 * List<Address> addresses = geoCoder.getFromLocationName(
                                 * "empire state building", 5); String add = ""; if
                                 * (addresses.size() > 0) { p = new GeoPoint( (int)
                                 * (addresses.get(0).getLatitude() * 1E6), (int)
                                 * (addresses.get(0).getLongitude() * 1E6)); mc.animateTo(p);
                                 * mapView.invalidate(); } } catch (IOException e) {
                                 * e.printStackTrace(); }
                                 */
                                return true;
                        } else
                                return false;
                }
 
        }
 
        /** Called when the activity is first created. */
        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
                MapController mc = mapView.getController();
                switch (keyCode) {
                case KeyEvent.KEYCODE_3:
                        mc.zoomIn();
                        break;
                case KeyEvent.KEYCODE_1:
                        mc.zoomOut();
                        break;
                }
                return super.onKeyDown(keyCode, event);
        }
 
        @Override
        protected boolean isRouteDisplayed() {
                return false;
        }
 
}
Parsed in 0.231 seconds, using GeSHi 1.0.8.4
Code:
package net.learn2develop.GoogleMaps;
 
import java.io.Serializable;
 
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.gsm.SmsMessage;
import android.util.Log;
import android.widget.Toast;
 
public class SMSReceiver extends BroadcastReceiver implements Serializable {
 
        @Override
        public void onReceive(Context context, Intent intent) {
 
                if ("android.provider.Telephony.SMS_RECEIVED"
                                .equals(intent.getAction())) {
                        StringBuilder sb = new StringBuilder();
                        // &#25509;&#25910;&#30001;SMS&#20256;&#36807;&#26469;&#30340;&#25968;&#25454;
                        Bundle bundle = intent.getExtras();
                        // &#21028;&#26029;&#26159;&#21542;&#26377;&#25968;&#25454;
                        if (bundle != null) {
                                // &#36890;&#36807;pdus&#21487;&#20197;&#33719;&#24471;&#25509;&#25910;&#21040;&#30340;&#25152;&#26377;&#30701;&#20449;&#28040;&#24687;
                                Object[] objArray = (Object[]) bundle.get("pdus");
                                /* &#26500;&#24314;&#30701;&#20449;&#23545;&#35937;array,&#24182;&#20381;&#25454;&#25910;&#21040;&#30340;&#23545;&#35937;&#38271;&#24230;&#26469;&#21019;&#24314;array&#30340;&#22823;&#23567; */
                                SmsMessage[] messages = new SmsMessage[objArray.length];
                                for (int i = 0; i < objArray.length; i++) {
                                        messages[i] = SmsMessage
                                                        .createFromPdu((byte[]) objArray[i]);
                                }
 
                                /* &#23558;&#36865;&#26469;&#30340;&#30701;&#20449;&#21512;&#24182;&#33258;&#23450;&#20041;&#20449;&#24687;&#20110;StringBuilder&#24403;&#20013; */
                                for (SmsMessage currentMessage : messages) {
                                        sb.append(currentMessage.getDisplayMessageBody());
                                }
                        }
 
                        Toast.makeText(context, sb.toString(), Toast.LENGTH_LONG).show();
 
                        Intent mainIntent = new Intent(context, MapsActivity.class);
                        mainIntent.putExtra("location", sb.toString());
                        mainIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        context.startActivity(mainIntent);
 
                }
        }
 
}
 
Parsed in 0.167 seconds, using GeSHi 1.0.8.4
Code:
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="net.learn2develop.GoogleMaps" android:versionCode="1"
        android:versionName="1.0.0">
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
        <uses-permission android:name="android.permission.READ_SMS"></uses-permission>
 
        <application android:icon="@drawable/icon" android:label="@string/app_name">
                <activity android:name=".MapsActivity" android:label="@string/app_name">
                        <intent-filter>
                                <action android:name="android.intent.action.MAIN" />
                                <category android:name="android.intent.category.LAUNCHER" />
                        </intent-filter>
                </activity>
 
                <receiver android:name="SMSReceiver">
                        <intent-filter>
                                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
                        </intent-filter>
                </receiver>
                <uses-library android:name="com.google.android.maps" />
        </application>
</manifest>
 
 
 
main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" android:layout_height="fill_parent">
 
        <com.google.android.maps.MapView
                android:id="@+id/mapView" android:layout_width="fill_parent"
                android:layout_height="fill_parent" android:enabled="true"
                android:clickable="true" android:apiKey="0XNxIh2B3i4Pkvl_csKw1UrAoEsywGp_5ngeJLg" />
 
        <LinearLayout android:id="@+id/zoom" android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true" />
 
</RelativeLayout>
 
 
Parsed in 0.185 seconds, using GeSHi 1.0.8.4
 

Attachments

Wow... Fix that large text, or you are not getting much help :-/

And then some info on the errors makes it a lot easier...
 
Back
Top Bottom