import
android.content.Intent
;
import
android.support.v7.app.AppCompatActivity
;
import
android.os.Bundle
;
import
android.view.View
;
import
android.widget.EditText
;
import
android.widget.Toast
;
public
class
MainActivity
extends
AppCompatActivity
{
private
EditText
et_main_content
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_main
);
et_main_content
=
(
EditText
)
findViewById
(
R
.
id
.
et_main_content
);
}
public
void
send
(
View
view
){
//获取要发送的内容
String
content
=
et_main_content
.
getText
().
toString
();
Intent
intent
=
new
Intent
();
//指定广播的名字
intent
.
setAction
(
"com.example.android21_sender.SY"
);
//指定广播的内容
intent
.
putExtra
(
"content"
,
content
);
//发送无序广播
// sendBroadcast(intent);
//发送无序黏性广播
// sendStickyBroadcast(intent);
//发送有序广播
sendOrderedBroadcast
(
intent
,
null
);
Toast
.
makeText
(
this
,
"发送成功"
+
content
,
Toast
.
LENGTH_SHORT
).
show
();
}
}