0
私のアプリケーションでプッシュ通知を実装しようとしていますが、 "setLatestEventInfo"でエラーが発生します。私は何をしているのですか? this.I希望を使用する必要がありますタイプ通知のメソッドsetLatestEventInfo(GcmMessageHandler、String、String、PendingIntent)が未定義です
public class GcmMessageHandler extends IntentService {
GoogleCloudMessaging gcm;
String regid;
NotificationManager nm;
static final int UniqueID=2154;
String mes,message;
private Handler handler;
public GcmMessageHandler() {
super("GcmMessageHandler");
}
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
handler = new Handler();
}
@Override
protected void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
// The getMessageType() intent parameter must be the intent you received
// in your BroadcastReceiver.
String messageType = gcm.getMessageType(intent);
mes = extras.getString("title");
message = extras.getString("message");
showToast();
Log.i("GCM", "Received : (" +messageType+") "+extras.getString("title"));
GcmBroadcastReceiver.completeWakefulIntent(intent);
nm=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
}
@SuppressWarnings("deprecation")
public void showToast(){
handler.post(new Runnable() {
public void run() {
Intent intent=new Intent(GcmMessageHandler.this, MainActivity.class);
PendingIntent pi=PendingIntent.getActivity(GcmMessageHandler.this, 0, intent, 0);
String sms=message;
String title="Message";
//Toast.makeText(getApplicationContext(), sms, Toast.LENGTH_LONG).show();
Notification n= new Notification(R.drawable.ic_launcher,sms,System.currentTimeMillis());
//here it gives error on "n.setLatestEventInfo"
//error is"The method setLatestEventInfo(GcmMessageHandler, String, String, PendingIntent) is undefined for the type Notification"
n.setLatestEventInfo(GcmMessageHandler.this, title, sms, pi);
n.defaults=Notification.DEFAULT_ALL;
nm.notify(UniqueID, n);
Toast.makeText(getApplicationContext(),message, Toast.LENGTH_LONG).show();
}
});
}
}
はあなたが取得しているエラーを投稿してください役立ちます。
は、ここに私のコード
GcmMessageHandler.java
です。 –