i tried to using bluetooth, android write and read a Location. (usage android.location class)
so, i want to write a bytes, i was Parcelabled a Location class.
it's Bluetooth write and read that good condition. (use android Api example, bluetoothchat) but, when a read a bytes and convert to Location class, not equal data for written.(-->BT send app data and BT received app data not equals.)
if using my BT send app this Location data (location.toString())
Location[gps 27.47754312158226,126.799059 acc=??? t=?!? et=?!? bear=138.43465]
but, i have a that error in BT received app.
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.
my send and read method are usage api example bluetoothchat.
Location to Parcel method that. it's BT send app parts.
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);
}
}
Parcel to Location method that. it's BT received app parts.
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;
}
i referencing how to serialize for android.location class? Why it's give me an error? sorry, my poor english :)