我有一個問題,當我將數據發送到應用程序,我只收到消息,但我要像等改變按鍵的形狀,但它不工作廣播接收器的一些代碼將不會工作
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