我正在使用BroadCaastReceiver来允许用户执行离线事件。问题是,如果我在点击beenThereView后几秒钟尝试打开wifi,它永远不会进入intent.getAction().equals("beenthereclicked")
内部。但是它确实进入了{{1}每当我打开wifi时,我都无法理解为什么if (wifi.isAvailable() || mobile.isAvailable())
和intent.setAction()
无效。我可以在我的日志中看到intent.getAction()
但在我的日志中看不到wificonnected
我在onReceive- beenthereclicked
里面写了这个..然后我在日志中得到了Log.e("NetworkChangeReceiver","intent"+intent.getAction());
intentandroid.net.conn.CONNECTIVITY_CHANGE
NetworkChangeReceiver.java
beenThereView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent();
Bundle extras = new Bundle();
extras.putString("Is_been_there", video.getIs_been_there());
extras.putString("videoid", video.getId());
intent.putExtras(extras);
intent.setAction("beenthereclicked");
mContext.sendBroadcast(intent);
}
}
AndroidManifest
public class NetworkChangeReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, final Intent intent) {
if (wifi.isConnected() || mobile.isAvailable())
{
Log.e("NetworkChangeReceiver", "wificonnected");
Log.e("NetworkChangeReceiver","intent"+intent.getAction());//returns android.net.conn.CONNECTIVITY_CHANGE
if (intent.getAction().equals("beenthereclicked")) {
Log.e("NetworkChangeReceiver", "beenthereclicked");
Bundle extras = intent.getExtras();
String isbeenthere = extras.getString("Is_been_there");
String videoid = extras.getString("videoid");
if (isbeenthere.equals("false"))
{
BeenThereAPI.unlike(context, videoid, new APIResponseListener() {
@Override
public void onResponse(Object response) {
}
@Override
public void onError(VolleyError error) {
}
});
}
else
{
BeenThereAPI.like(context, videoid, new APIResponseListener()
{
@Override
public void onResponse(Object response)
{
}
@Override
public void onError(VolleyError error)
{
}
});
}
}
}