Pha*_*tHV 2 android broadcastreceiver
我有一个BroadcastReceiver添加前缀到拨出电话的电话号码和前缀由用户添加.
有没有办法将Prefix(String变量)传递给BroadcastReceiver?
我的意思是在我的应用程序被杀之后,这BroadcastReceiver仍然适用于用户想要添加的前缀.
这是我的注册代码 BroadcastReceiver
PackageManager pm = getApplicationContext().getPackageManager();
ComponentName componentName = new componentName(MyActivity.this,MyBroadcastReceiver.class);
pm.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_ENABLED,PackageManager.DONT_KILL_APP);
Run Code Online (Sandbox Code Playgroud)
请帮我解决这个问题.
通过意图你可以这样做 -
通过课程 -
Intent i = new Intent(passing.this, received.class);
Bundle b = new Bundle();
b.putString("keyvalue", "yourprefixvalue");
i.putExtras(b);
startActivity(i);
Run Code Online (Sandbox Code Playgroud)
收到的课程 -
在你的广播接收器类中包含onReceive方法并具有参数意图.这样它就可以用来从bundle中获取结果值.
@Override
public void onReceive(Context context, Intent intent)
{
String result = intent.getString("keyvalue");
// your method
}
Run Code Online (Sandbox Code Playgroud)
试试吧.我已经将一些价值观传递给了我的BroadcastReceiver班级.