Joke Collection Website - Public benefit messages - Android 2. 1 The broadcast receiver cannot receive data. Why?

Android 2. 1 The broadcast receiver cannot receive data. Why?

License code:

& ltuses-permission Android:name = " Android . permission . receive _ SMS " & gt; & lt/uses-permission & gt;

Registered recipient:

& lt recipient android:name= ". GetData " & gt

& lt intention filter & gt

& ltaction Android:name = " Android . provider . telephony . SMS _ RECEIVED "/& gt;

& lt/intent-filter & gt;

& lt/receiver & gt;

Java class GetData:

Import android.content.broadcastreceiver;

Import android.content.context;

Import android.content.intent;

Import android.os.bundle;

Import android.telephony.SMS message;

Import android.widget.toast;

Public class GetData extends BroadcastReceiver {

private static final String MAC tion = " Android . provider . telephony . SMS _ RECEIVED ";

@ Overlay

Public void onReceive (context, intention) (

if(intent.getAction()。 Equal to (mACTION))

{

StringBuilder sb = new StringBuilder();

bundle bundle = intent . get extras();

If (bound! = empty)

{

Object[]obj =(Object[])bundle . get(" PDUs ");

//Create an information object

SMS message[]message = new SMS message[obj . length];

for(int I = 0; I < object length; i++)

{

message[I]= SMS message . createfrompdu((byte[])obj[I]);

}

Used for (SMS current message: message)

{

Sb.append ("received from: \ n");

//The sender's phone number

sb . append(current message . getdisplayoriginatingaddress());

sb . append(" \ n-");

//Information content sent

sb . append(current message . getdisplaymessagebody());

}

}

//Display incoming information with notification.

Toast.makeText(context,sb.toString(),Toast。 Length _ length). show();

//Return to the main program BroadCastTest.

Intent i=new Intent(context,test receiver . class);

//Run a brand-new task

i.addFlags(Intent。 Flag _ Activity _ New _ Task);

context . start activity(I);

}

}

}

Java class: TestReceiver

Import android.app.activity;

Import android.os.bundle;

Import android.widget.textview;

Public class TestReceiver extends Activity {

/* * Called when an activity is first created. */

@ Overlay

public void on create(Bundle saved instancestate){

super . oncreate(savedInstanceState);

setContentView(r . layout . main);

TextView txt =(TextView)findViewById(r . id . TextView 0 1);

Txt.setText ("waiting to receive ...");

}

}

The above code cannot receive the broadcast of SMS received by the system. Has anyone encountered this problem? Answer, thank you.

The reason has been found, so the problem is closed.

Because the foundation and eyes are not good enough

Put < receiver android:name= ". GetData " & gt

& lt intention filter & gt

& ltaction Android:name = " Android . provider . telephony . SMS _ RECEIVED "/& gt;

& lt/intent-filter & gt;

& lt/receiver & gt;

This paragraph is written outside the application label!

I looked for the reason of 1 day and a half, but I couldn't find it. Finally found it, depressed.