【问题标题】:How to receive params in intent for broadcast如何接收广播意图中的参数
【发布时间】:2014-11-12 19:17:30
【问题描述】:
Integer id_user = 1;
Intent registration= new Intent("com.google.android.c2dm.intent.REGISTER");
                                registration.putExtra("app", PendingIntent.getBroadcast(getBaseContext(),0,new Intent(),0));
                                registration.putExtra("sender",project_number);
                                startService(registration);

我需要添加更多类似的

registration.putExtra("id_user",id_user);

并被广泛接受

public class resquest extends BroadcastReceiver {

NEED CATCH HERE..... a USER_ID

    @Override
    public void onReceive(Context context, Intent intent) {
      .....Code here 
    }
}

问候!

【问题讨论】:

  • id_user 是什么类型?您是在问如何获取 id_user,还是如何获取您在示例中发布的其他两个参数?
  • 您好,我需要在类 resquest 中获取 id_user

标签: java android broadcast android-broadcast


【解决方案1】:

首先,您需要发送用户 ID 才能获取它:

Integer id_user = 1;
Intent registration= new Intent("com.google.android.c2dm.intent.REGISTER");
                            registration.putExtra("app", PendingIntent.getBroadcast(getBaseContext(),0,new Intent(),0));
                            registration.putExtra("sender",project_number);
                            registration.putExtra("id_user", id_user.intValue());
                            startService(registration);

那你就可以这样获取了

public class resquest extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        int id_user = i.getExtras().getInt("id_user");
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多