some codes about broadcast intent
来源:互联网 发布:powerdvd是什么软件 编辑:程序博客网 时间:2024/05/18 03:39
//sending broadcast
package cn.micoder.broadcastintent;import android.support.v7.app.ActionBarActivity;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;//need to importimport android.content.Intent;import android.view.View;public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } //BROADCAST public void sendbroadcast(){ Intent i = new Intent(); i.setAction("MyFirstBroadCst"); i.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);//Android OS 的改变导致必须加上这一行代码,以保证在不同版系统的机器上运行 sendBroadcast(i); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); }}
//------------------------------------------------
//receiving broadcast
package cn.micoder.receivebroadcast;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.widget.Toast;public class MyReceiver extends BroadcastReceiver { public MyReceiver() { } @Override public void onReceive(Context context, Intent intent) { Toast.makeText(context,"I Received the broadcast!",Toast.LENGTH_LONG).show(); }}
//过滤广播
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cn.micoder.receivebroadcast" > <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <receiver android:name=".MyReceiver" android:enabled="true" android:exported="true" > <intent-filter> <action android:name="MyFirstBroadCast"></action> </intent-filter> </receiver> </application></manifest>
0 0
- some codes about broadcast intent
- some code about intent
- Some functions and codes about date
- Broadcast Email Bounce Codes
- some js codes
- Some useful java codes
- Some CV Codes
- Some important codes
- swift class inheritance * some codes
- Some words about ICE...
- About some techno-words
- some links about UML
- Some tutorial about geometry
- Some videos about Avalon
- Some Tips about Interbase
- some understanding about Java
- Some words about Computer
- some function about TIVOLI
- Shell编程-字符处理命令
- NGUI不规则形状点击
- 郁金香汇编逆向与外挂(60)
- CSDN-markdown编辑器语法——字体、字号与颜色
- spring配置tomcat的jndi数据源
- some codes about broadcast intent
- C++作业4.22
- 开始刷leetcode day12:Linked List Cycle II
- hihoCoder#1093 最短路径·三-SPFA算法
- Linux/Windows 下字符编码转换
- linux应用开发-守护进程
- Ganglia监控Hadoop集群的安装部署
- 使用ctags+vim工具察看源代码
- IOS开发小问题