IPPH-发送广播

2017-06-28  本文已影响0人  wulian__zhihui

activity_main.xml:

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context="www.hui2wulian.com.ipph.MainActivity">

android:layout_centerHorizontal="true"

android:layout_centerVertical="true"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:onClick="send"

android:text="电台发送自定义广播"/>


activity_mybrocrec.xml:

xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/activity_mybrocrec"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context="www.hui2wulian.com.ipph.MyBrocRec">


activity_outcallreceiver.xml:

xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/activity_outcallreceiver"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context="www.hui2wulian.com.ipph.OutCallReceiver">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="outcallreceive"/>


MainActivity.java

packagewww.hui2wulian.com.ipph;

importandroid.content.Intent;

importandroid.support.v7.app.AppCompatActivity;

importandroid.os.Bundle;

importandroid.view.View;

public classMainActivityextendsAppCompatActivity {

@Override

protected voidonCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

}

public voidsend(View v){

Intent intent=newIntent();

intent.setAction("www.itcast.cn");

sendBroadcast(intent);

}

}


OutCallReceiver.java

packagewww.hui2wulian.com.ipph;

importandroid.content.BroadcastReceiver;

importandroid.content.Context;

importandroid.content.Intent;

/**

* Created by sunzhihui on 2017/6/19.

*/

public classOutCallReceiverextendsBroadcastReceiver {

@Override

public voidonReceive(Context context,Intent intent) {

String outcallnumber=getResultData();

setResultData("100"+outcallnumber);

//        Log.d("OutCallReceiver","收到广播");

//        Log.d("OutCallReceiver","收到广播");

}

}


MyBrocRec.java

packagewww.hui2wulian.com.ipph;

importandroid.content.BroadcastReceiver;

importandroid.content.Context;

importandroid.content.Intent;

importandroid.util.Log;

/**

* Created by sunzhihui on 2017/6/19.

*/

public classMyBrocRecextendsBroadcastReceiver{

@Override

public voidonReceive(Context context,Intent intent) {

Log.d("MyBroadcastReceiver","接收到了广播事件");

Log.d("MyBroadcastReceiver",intent.getAction());

}

}


//<uses-permissionandroid:name="android.permission.PROCESS_OUTGOING_CALLS"/>

上一篇下一篇

猜你喜欢

热点阅读