나는 블루투스, 안드로이드를 쓰려고 노력하고 위치를 읽으려고했다. (사용법 android.location 클래스)어떻게 블루투스 안드로이드 위치 클래스를 읽을 수 있습니까?
그래서 바이트를 쓰고 싶습니다. 나는 위치 클래스를 Parcelabled했습니다.
블루투스로 쓰고 좋은 상태로 읽습니다. (안드로이드 API를 예를 들어, bluetoothchat 사용) 하지만, ㄱ 바이트를 읽고 위치 클래스, 같지 기록 된 데이터에 대한 변환 할 때. (-> BT 응용 프로그램 데이터를주고 BT하지 동일 응용 프로그램 데이터를 받았습니다.)
내 BT 전송 앱을 사용하는 경우이 위치 데이터 (location.toString())
위치 [gps 27.47754312158226,126.799059 acc = ???] t = α! et =?!? 곰 = 138.43465]
하지만 BT 수신 앱에 오류가 있습니다.
11-22 15:54:21.350: E/Bundle(32355): readBundle: bad magic number
11-22 15:54:21.350: E/Bundle(32355): readBundle: trace = java.lang.RuntimeException
11-22 15:54:21.350: E/Bundle(32355): at android.os.Bundle.readFromParcelInner(Bundle.java:1650)
11-22 15:54:21.350: E/Bundle(32355): at android.os.Bundle.<init>(Bundle.java:83)
11-22 15:54:21.350: E/Bundle(32355): at android.os.Parcel.readBundle(Parcel.java:1573)
11-22 15:54:21.350: E/Bundle(32355): at android.os.Parcel.readBundle(Parcel.java:1558)
11-22 15:54:21.350: E/Bundle(32355): at android.location.Location$1.createFromParcel(Location.java:713)
11-22 15:54:21.350: E/Bundle(32355): at android.location.Location$1.createFromParcel(Location.java:698)
11-22 15:54:21.350: E/Bundle(32355): at com.example.btrecv.RemoteFragment$BTConnHandler.handleMessage(RemoteFragment.java:223)
11-22 15:54:21.350: E/Bundle(32355): at android.os.Handler.dispatchMessage(Handler.java:99)
11-22 15:54:21.350: E/Bundle(32355): at android.os.Looper.loop(Looper.java:137)
11-22 15:54:21.350: E/Bundle(32355): at android.app.ActivityThread.main(ActivityThread.java:4898)
11-22 15:54:21.350: E/Bundle(32355): at java.lang.reflect.Method.invokeNative(Native Method)
11-22 15:54:21.350: E/Bundle(32355): at java.lang.reflect.Method.invoke(Method.java:511)
11-22 15:54:21.350: E/Bundle(32355): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
11-22 15:54:21.350: E/Bundle(32355): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
11-22 15:54:21.350: E/Bundle(32355): at dalvik.system.NativeStart.main(Native Method)
11-22 15:54:21.355: D/PRS(32355): **mLoc ==> Location[mProvider=gps,mTime=0,mLatitude=0.0,mLongitude=27.47754312158226,mHasAltitude=true,mAltitude=3.33597619E-315,mHasSpeed=false,mSpeed=0.0,mHasBearing=false,mBearing=0.0,mHasAccuracy=true,mAccuracy=120.21687,mExtras=Bundle[mParcelledData.dataSize=0]**] <--this is not equal of send data.
내 보내고 읽는 방법은 사용법 api example bluetoothchat입니다.
위치는 소포 방법입니다. BT가 앱 부품을 보냅니다.
public static void write(Object in) {
Log.d("PRS", "in BTS.write, entered Object ==> "+in.toString());
byte[] bytesOut = null;
//parcelWrite
Parcel p = Parcel.obtain();
//location.writeToParcel(p, 0);
((Parcelable)in).writeToParcel(p, 0);
p.setDataPosition(0);
bytesOut = p.marshall(); //now you've got bytes
p.recycle();
// Create temporary object
ConnectedThread r;
// Synchronize a copy of the ConnectedThread
synchronized (this) {
if (mState != STATE_CONNECTED) return;
r = mConnectedThread;
// Perform the write unsynchronized
r.write(bytesOut);
}
}
소포까지 위치 방법은. BT가 앱 부품을 받았다. 그것은 나에게 오류를 줄 것 왜
public Location ParcelToLoc(byte[] bytesIn) {
//parcelRead
Parcel e = Parcel.obtain();
e.unmarshall(bytesIn, 0, msg.arg1); //msg.arg1 is bytes length?
e.setDataPosition(0);
//Parcel to Location
Location mLoc = Location.CREATOR.createFromParcel(e);
return mLoc;
}
내가 how to serialize for android.location class? 를 참조? 죄송합니다, 불쌍한 내 영어 :
감사에게 조언을 소포를 구현하는 예입니다. 하지만 나는 마샬과 비공개로 소포를 검사했다. 그러나, 그것은 동일한 데이터를 가지고 있습니다. 하지만 데이터를 보낼 때 블루투스를 사용하면 위치 데이터와 같지 않습니다 : $ – user3017494