Android GCM信息返回填写表

Android GCM信息返回填写表,android,android-activity,fill,google-cloud-messaging,Android,Android Activity,Fill,Google Cloud Messaging,嗨,我是开发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

嗨,我是开发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"));
    }
正在登录name和fone,但我想在我的表单字段中输入“message”

<?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>

我怎么能做到?(获取活动、获取字段、填充字段…

一旦在您的
gcminentservice
中获得“消息”,您可以通过多种方式将其内容传递给其他应用程序组件

在GCM演示应用程序中,他们创建了一个通知(请参阅“generateNotification”方法)。

如果您想在
活动
中显示内容,那么您需要向该
活动
发出
意图
,并将所需数据作为“额外信息”

您不需要在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"));

  // 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");
正如我所说的,这个例子过于简单(在使用它之前,您需要检查数据是否确实存在,在您的服务和活动中,您可能希望使用其他数据类型并具有默认值,根据需要有其他方法来交换数据),但您还是应该开始使用它。

一旦您收到“消息”在您的
gcminentservice
中,有几种方法可以将其内容传递给其他应用程序组件

在GCM演示应用程序中,他们创建了一个通知(请参阅“generateNotification”方法)。

如果您想在
活动
中显示内容,那么您需要向该
活动
发出
意图
,并将所需数据作为“额外信息”

您不需要在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"));

  // 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");

正如我所说的,这个示例过于简单(在使用数据之前,您需要检查数据是否确实存在,在您的服务和活动中,您可能希望使用其他数据类型并具有默认值,根据需要,还有其他方法来交换数据),但这应该会让你开始学习。

还有一个小问题,如果我的设备没有添加google帐户,只有添加公司帐户,我可以在这个设备中使用gcm?如果这里的答案对你有帮助,你可能会想标记为“接受”。至于是否使用google帐户,那将是另一个问题,请继续并为此提交一个新问题。欢迎来到SO!更多一个小问题如果我的设备没有添加谷歌帐户,只有添加公司帐户,我可以在这个设备中使用gcm?如果这里的答案对你有帮助,你可能希望将其标记为“接受”。至于是否使用谷歌帐户,这将是另一个问题,请继续并提交一个新问题。欢迎来到SO!