android_4.2.2\frameworks\base\core\java\android\content\Intent.java

添加自己的intent代号,如下:

    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)    public static final String ACTION_MY_TEST = "android.intent.action.MY_TEST";


在需要发送这个intent的APP中添加:

Intent myTest = new Intent(Intent.ACTION_MY_TEST);mContext.sendBroadcast(myTest);


在需要接收这个intent的APP中注册使用:

mIntentFilter = new IntentFilter(Intent.ACTION_MY_TEST);getActivity().registerReceiver(mReceiver, mIntentFilter);

记得import下面两个头文件:

import android.content.Intent;import android.content.IntentFilter;

注册接收这个消息的函数然后处理它:

    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {        @Override        public void onReceive(Context context, Intent intent) {            String action = intent.getAction();            if (Intent.ACTION_MY_TEST.equals(action)) {            Log.d("intent_test", "this is my intent test");            }        }    };



 

更多相关文章

  1. 代号Pie!Android 9.0那些开发者必须知道的事
  2. 谷歌 Android 3.0计划四季度推出:代号姜饼
  3. Android版本号以及对应的API Level和版本代号
  4. android版本及版本代号对照
  5. Android SDK 1-23各版本代号和别名
  6. Android各版本代号
  7. Android历代版本的代号
  8. android各个版本的代号
  9. Android各版本代号和API级别对照表

随机推荐

  1. Activity使用Dialog样式导致点击空白处自
  2. Android中socket的实例分析(二)
  3. android4启程
  4. java Android(安卓)OKHttp HTTPS 请求证
  5. Android学习之旅(三)----Activity及其生
  6. Android(安卓)TabLayout简单使用
  7. android小项目----基于mnn的mtcnn人脸检
  8. Android(安卓)完全退出当前应用程序
  9. Android(安卓)4高级编程(第3版)
  10. Android(安卓)开发 Tip 15 -- can be rep