package com.example.bootcomplete;

import android.os.Bundle;

import android.app.Activity;

import android.content.Context;

import android.content.Intent;

import android.view.Menu;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

public class MainActivity extends Activity implements OnClickListener{

private Button btn;

public Context context;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

context = MainActivity.this;

btn = (Button) findViewById(R.id.button1);

btn.setOnClickListener(this);

}

@Override

public void onClick(View arg0) {

// TODO Auto-generated method stub

if(arg0.equals(btn)){

Intent intent = new Intent("android.intent.action.MY_BROADCAST");

intent.putExtra("broadcast", "abcd");

sendBroadcast(intent);

}

}

}

package com.example.bootcomplete;

import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;

import android.os.Bundle;

import android.util.Log;

import android.widget.Toast;

public class BootCompleteReceiver extends BroadcastReceiver {

private static final String TAG = "android.intent.action.MY_BROADCAST";

@Override

public void onReceive(Context context, Intent intent) {

if(intent.getAction().equals(TAG)){

Toast.makeText(context, TAG, Toast.LENGTH_LONG).show();

Log.v("Boot", TAG);

}

}

}

//manifest声明

    package="com.example.bootcomplete"

    android:versionCode="1"

    android:versionName="1.0" >

   

        android:minSdkVersion="8"

        android:targetSdkVersion="18" />

   

        android:allowBackup="true"

        android:icon="@drawable/ic_launcher"

        android:label="@string/app_name"

        android:theme="@style/AppTheme" >

       

            android:name="com.example.bootcomplete.MainActivity"

            android:label="@string/app_name" >

      

       

        //通过这一句

//来判断发送的是不是自己想要的广播

  

//layout布局

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

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:paddingBottom="@dimen/activity_vertical_margin"

    android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    tools:context=".MainActivity" >

   

        android:id="@+id/textView1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="@string/hello_world" />

   

        android:id="@+id/button1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignLeft="@+id/textView1"

        android:layout_below="@+id/textView1"

        android:layout_marginLeft="55dp"

        android:layout_marginTop="142dp"

        android:text="send" />


更多相关文章

  1. android广播 demo
  2. 【Android】判断某个App是否安装并启动(queryIntentActivities),
  3. Android(安卓)获取系统自带相机的照片
  4. Android布局中添加条横线
  5. android 判断 无线是否可用
  6. Android(安卓)搜索框自动提示及其保存历史记录
  7. Android转盘抽奖的简单实现
  8. Android判断网络连接
  9. Android--一段兼容居中和满屏满屏的布局

随机推荐

  1. 2020上半年百度Android岗(初级到高级)面试
  2. android中导入数据
  3. Android —— SQLite数据库简易使用
  4. 【Android】进程间通信IPC——AIDL
  5. 谷歌二季度发布Android5.0:捆绑Chrome系统
  6. 个人开发者如何通过Android应用赚外快
  7. Android 组件硬知识点
  8. Android屏幕计量单位详解
  9. Android使用Thread的interrupt与sleep,重
  10. android第一天-------环境搭建