-2

私は(BroacastReceiverを使用して)イベントにフックしており、ドキュメント(http://developer.android.com/reference/android/net/ConnectivityManager.html)から特定のオブジェクトを「余分に」取得する必要があります:

The NetworkInfo for the affected network is sent as an extra

the NetworkInfo for the new network is also passed as an extra.

私の質問は次のとおりです。私のブロードキャストレシーバーには、次のイベントが発生します。

public void onReceive(Context context, Intent intent) {

そして、私が理解しているように、意図からこれら2つの「エクストラ」を取得できるはずですか?

どうやってやるの?

マウスオーバーのデバッグモードでEclipseのオブジェクトを検査しようとしintentました(私はEclipseでまったく新しいので、実行時に変数を検査する他の方法を知りません)が、それは私に多くの情報を与えませんでした....

4

3 に答える 3

1

インテントから取得するデータのタイプによって異なります。たとえば、intまたはbooleanを使用する場合:

Bundle extras = intent.getExtras();
int exampleInt = extras.getInt('Name of the extra corresponding to that variable');
boolean exampleBoolean = extras.getBoolean('Name of this other extra');
于 2013-09-27T17:53:13.330 に答える
1
public void onReceive(Context context, Intent intent) {
     int i = intent.getExtras().getInt("keyName");
     String s = intent.getExtras().getString("keyName");

...
于 2013-09-27T17:53:23.420 に答える
1

次のようにできます。

public void onReceive(Context context, Intent intent) {

    int id = intent.getExtra.getInt("id");
    String name = intent.getExtra.getString("name");

   .......
}

インテントから extra の任意のデータ型を取得できます。インテントを使用して取得できるデータ型のリストについては、INTENTをご覧ください。

于 2013-09-27T17:50:56.813 に答える