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");
}
}
};