why is my intent not useful?

Posted by user1634887 on Stack Overflow See other posts from Stack Overflow or by user1634887
Published on 2012-08-30T03:36:18Z Indexed on 2012/08/30 3:38 UTC
Read the original article Hit count: 165

Filed under:
|

This is my first to ask here. I write the code for a Broadcast A start another Broadcast B. But the Broadcast B didn't get the intent's value.

Broadcast A:get the sms contain message and start B

public void onReceive(Context context, Intent intent) {
    Object[] pdus=(Object[])intent.getExtras().get("pdus");

    for(Object pdu:pdus)
    {
        byte[] date=(byte[])pdu;
        SmsMessage message=SmsMessage.createFromPdu(date);

        String sender=message.getOriginatingAddress();
        String body=message.getMessageBody();

        if(sender.equals(AppUtil.herPhone)&&body.regionMatches(0, AppUtil.herSmsText, 0, 18))
        {
            Toast.makeText(context, body, Toast.LENGTH_LONG).show();
            String [] bodyArray=body.split(" ");
            String longitude=bodyArray[1];
            String latitude=bodyArray[2];

            **Intent uiIntent=new Intent();
            Bundle bundle=new Bundle();
            bundle.putString("longitude", longitude);
            bundle.putString("latitude", latitude);

            uiIntent.putExtras(bundle);
            uiIntent.setAction("android.janmac.location");
            context.sendBroadcast(uiIntent);**

            abortBroadcast();

        }
    }

}

Boardcast B: it nest in an Activity. register:

    button.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            AppUtil.SendMessage(MainActivity.this);

            uiReceiver=new UIReceiver();
            IntentFilter filter=new IntentFilter();
            filter.addAction("android.janmac.location");
            registerReceiver(uiReceiver, filter);
        }
    });

extend: private class UIReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.v("location","uireceiver????!");

        **Bundle bundle=new Bundle();
        bundle=intent.getExtras();
        herLongitude=Double.valueOf(bundle.getString("longitude"));
        herLatitude=Double.valueOf(bundle.getString("latitude"));**

    }

}

but the bundle couldn't get any values.

here is log:

08-30 11:17:40.494: D/AndroidRuntime(2359): Shutting down VM 08-30 11:17:40.514: W/dalvikvm(2359): threadid=1: thread exiting with uncaught exception (group=0x40018560) 08-30 11:17:40.544: E/AndroidRuntime(2359): FATAL EXCEPTION: main 08-30 11:17:40.544: E/AndroidRuntime(2359): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.janmac.location (has extras) } in com.example.locationclient.MainActivity$UIReceiver@40513690 08-30 11:17:40.544: E/AndroidRuntime(2359): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:722) 08-30 11:17:40.544: E/AndroidRuntime(2359): at android.os.Handler.handleCallback(Handler.java:587) 08-30 11:17:40.544: E/AndroidRuntime(2359): at android.os.Handler.dispatchMessage(Handler.java:92) 08-30 11:17:40.544: E/AndroidRuntime(2359): at android.os.Looper.loop(Looper.java:130) 08-30 11:17:40.544: E/AndroidRuntime(2359): at android.app.ActivityThread.main(ActivityThread.java:3835) 08-30 11:17:40.544: E/AndroidRuntime(2359): at java.lang.reflect.Method.invokeNative(Native Method) 08-30 11:17:40.544: E/AndroidRuntime(2359): at java.lang.reflect.Method.invoke(Method.java:507) 08-30 11:17:40.544: E/AndroidRuntime(2359): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864) 08-30 11:17:40.544: E/AndroidRuntime(2359): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622) 08-30 11:17:40.544: E/AndroidRuntime(2359): at dalvik.system.NativeStart.main(Native Method) 08-30 11:17:40.544: E/AndroidRuntime(2359): Caused by: java.lang.NumberFormatException 08-30 11:17:40.544: E/AndroidRuntime(2359): at org.apache.harmony.luni.util.FloatingPointParser.parseDblImpl(Native Method) 08-30 11:17:40.544: E/AndroidRuntime(2359): at org.apache.harmony.luni.util.FloatingPointParser.parseDouble(FloatingPointParser.java:283) 08-30 11:17:40.544: E/AndroidRuntime(2359): at java.lang.Double.parseDouble(Double.java:318) 08-30 11:17:40.544: E/AndroidRuntime(2359): at java.lang.Double.valueOf(Double.java:356) 08-30 11:17:40.544: E/AndroidRuntime(2359): at com.example.locationclient.MainActivity$UIReceiver.onReceive(MainActivity.java:231) 08-30 11:17:40.544: E/AndroidRuntime(2359): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:709) 08-30 11:17:40.544: E/AndroidRuntime(2359): ... 9 more enter code here

© Stack Overflow or respective owner

Related posts about android

Related posts about android-intent