IPPH-發(fā)送廣播

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="電臺發(fā)送自定義廣播"/>


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"/>

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容