重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
郑州app开发android有序广播发送和接收实例。下面是整理的java代码
创新互联-专业网站定制、快速模板网站建设、高性价比道里网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式道里网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖道里地区。费用合理售后完善,十余年实体公司更值得信赖。
MainActivity.java
package cn.xhhkj.cyd;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Activity;
import android.app.pendingIntent;
import android.content.broadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.Sharedpreferences;
import android.os.bundle;
import android.os.Handler;
import android.telephony.SmsManager;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private button btn;
@Override
protected void onCreate(bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn=findViewbyId(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction("cn.xhhkj.broadcast");
String receiverpermission = null;
broadcastReceiver resultReceiver = new FinalReceiver();
Handler scheduler = null;
String initialData = "中500万彩票,给你们发红包1万元";
sendOrderedbroadcast(intent, receiverpermission, resultReceiver, scheduler, Activity.RESULT_OK, initialData, null);
}
});
}
}
FinalReceiver.java
package cn.xhhkj.cyd;
import android.content.broadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
class FinalReceiver extends broadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String resultData = getResultData();
Toast.makeText(context, "final:"+resultData, Toast.LENGTH_SHORT).show();
}
}
由于篇幅有限,有序广播接收需要单独建个项目进行接收,在这里就不展示了。只展示一个
public class FarmerReceiver extends broadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String resultData = getResultData();
Toast.makeText(context, resultData, Toast.LENGTH_SHORT).show();
setResultData("郑州做app哪家好?");
}
}