我有一个问题,当我将数据发送到应用程序,我只收到消息,但我要像等改变按键的形状,但它不工作广播接收器的一些代码将不会工作
package com.pioneer.it.gcmpro;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class PushReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String title="P";
String text="T";
if(intent.getStringExtra("message")!=null)
text=intent.getStringExtra("message");
Intent i=new Intent(context,MainActivity.class);
PendingIntent pi=PendingIntent.getActivity
(context,0,i,PendingIntent.FLAG_UPDATE_CURRENT);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.activity_main,null);
Button b = (Button) v.findViewById(R.id.button);
b.setText("" + text);
Toast.makeText(context, "" + text, Toast.LENGTH_SHORT).show();
}
}
这条线仅适用于Toast.makeText(上下文,“”+ text,Toast.LENGTH_SHORT).show();
但这行不行b.setText(“”+ text);
为什么?
我不明白你有问题的解决方案 –
请参阅@ meikiem的回答 – Aenadon