1

こんにちは、Androidアプリケーションの開発は初めてです。いくつか質問があります。

私のGCMは正常に動作します:

protected void onMessage(Context context, Intent intent) {
        Log.i(TAG, "Receenter code hereived message");
        Log.i(TAG, intent.getStringExtra("name"));
        Log.i(TAG, intent.getStringExtra("fone"));

        //google example (with this, the "message" ll be append in screen, like a miracle)
        displayMessage(context, intent.getStringExtra("nome") + " " + intent.getStringExtra("telefone"));
    }

名前と名前を記録しますが、フォームフィールドにその「メッセージ」を入力したいと思います。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="8dip" >

    <TableLayout
        android:id="@+id/TableLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="8dp" >

         <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="8dp" >



        <TextView
            android:id="@+id/display"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        </TableRow>

        <EditText
            android:id="@+id/name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="10" >

            <requestFocus />
        </EditText>

        <EditText
            android:id="@+id/fone"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="10" />
    </TableLayout>

</ScrollView>

どうすればいいですか?(アクティビティを取得し、フィールドを取得し、フィールドに入力します...)

4

1 に答える 1

1

「メッセージ」をGCMIntentService受け取ったら、その内容を他のアプリケーションコンポーネントに配信する方法がいくつかあります。

GCMデモアプリでは、通知を作成します(「generateNotification」メソッドを参照)。 https://code.google.com/p/gcm/source/browse/samples/gcm-demo-client/src/com/google/android/gcm/demo/app/GCMIntentService.java

の内容を表示したい場合は、必要なデータを「エクストラ」として使用して、その内容Activityを起動する必要があります。IntentActivity

GCMサービスで「アクティビティを取得」するのではなく、「インテント」を指定すると、システムはActivityそれを処理するために正しいものを呼び出します。詳細については、intents / intentfiltersのドキュメントを参照してください:http://developer.android.com/guide/components/intents-filters.html

単純化しすぎた例を次に示します。

protected void onMessage(Context context, Intent intent) {
  Log.i(TAG, "Receenter code hereived message");
  Log.i(TAG, intent.getStringExtra("name"));
  Log.i(TAG, intent.getStringExtra("fone"));

  // create ANOTHER intent to fire off the data to YOUR activity
  Intent i = new Intent(this, MyActivity.class);
  i.putExtra("nome", intent.getStringExtra("nome"));
  i.putExtra("fone", intent.getStringExtra("fone"));
  startActivity(i);      

}

次に、MyActivityで次のようなことを行います。

 String nome = getIntent().getStringExtra("nome");

私が言ったように、この例は単純化されすぎています(データを使用する前に、データが実際に存在することを確認する必要があります。サービスとアクティビティの両方で、他のデータ型を使用し、デフォルトを設定する必要があります。交換する方法は他にもあります。要件に応じたデータ)が、それでも開始できるはずです。

于 2013-03-07T15:12:07.360 に答える