被调用方:
1、写静态接收广播:
public class MyBroadcastReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent receiverIntent) {
//可以接收 上个 调用传来的数据
String userId = receiverIntent.getStringExtra("username");
//创建一个新的
Intent intent = new Intent(context, TRTCVideoRoomActivity.class);
//插入要传递的数据
intent.putExtra(TRTCVideoRoomActivity.KEY_USER_ID, userId);
//这里必须使用 FLAG_ACTIVITY_NEW_TASK 否则会报错
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
2、添加权限 注册广播
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<receiver android:name=".MyBroadcastReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.tencent.liteav.demo.MyBroadcastReceiver"/>
</intent-filter>
</receiver>
调用方
public void myClick(View v){
Intent intent = new Intent("com.tencent.liteav.demo.MyBroadcastReceiver");
intent.setFlags(Intent. FLAG_INCLUDE_STOPPED_PACKAGES);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
intent.putExtra("username",nameStr);
sendBroadcast(intent);
}
来源:CSDN
作者:没事偷着乐琅
链接:https://blog.csdn.net/zhanglinlang/article/details/104667634