2017-05-16 1 views
2

내 Android 앱에 firebase를 사용하여 푸시 알림을 보내고 있습니다. 메시지를 보내고 앱이 종료되면 알림이 수신되고 의도가 작동하며 모든 것이 정상입니다. 응용 프로그램이 열려 내가 메시지를 보낼 때, 그것은 getColor() 방법에서이 오류로 충돌 :fcm이 전송되고 앱이 열릴 때 Android 앱이 다운 됨

Exception java.lang.NoSuchMethodError: No virtual method getColor(I)I in class Lcom/kinectafrica/android/service/FirebaseMessagingService; or its super classes (declaration of 'com.kinectafrica.android.service.FirebaseMessagingService' appears in /data/app/com.kinectafrica.android-1/base.apk) 
com.kinectafrica.android.service.FirebaseMessagingService.sendNotification (FirebaseMessagingService.java:45) 
com.kinectafrica.android.service.FirebaseMessagingService.onMessageReceived (FirebaseMessagingService.java:33) 
com.google.firebase.messaging.FirebaseMessagingService.zzo() 
com.google.firebase.messaging.FirebaseMessagingService.zzn() 
com.google.firebase.messaging.FirebaseMessagingService.zzm() 
com.google.firebase.iid.zzb$2.run() 
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1112) 
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:587) 
java.lang.Thread.run (Thread.java:818) 

이 내 FirebaseMessagingService 클래스 :이 원인이 될 수있는 것을

package com.kinectafrica.android.service; 

import android.app.NotificationManager; 
import android.app.PendingIntent; 
import android.content.Intent; 
import android.media.RingtoneManager; 
import android.net.Uri; 
import android.support.v4.app.NotificationCompat; 
import android.util.Log; 

import com.google.firebase.messaging.RemoteMessage; 
import com.kinectafrica.android.R; 
import com.kinectafrica.android.activity.SplashScreenActivity; 

/** 
* Made by acefalobi on 5/16/2017. 
*/ 

public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService { 

    int notifyId = 0; 
    @Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 
     Log.d("Service", "From: " + remoteMessage.getFrom()); 

     if (remoteMessage.getData().size() > 0) { 
      Log.d("Service", "Message data payload: " + remoteMessage.getData()); 
     } 

     if (remoteMessage.getNotification() != null) { 
      Log.d("Service", "Message notification: " + remoteMessage.getNotification().getBody()); 
     } 
     sendNotification(remoteMessage.getData().get("message")); 
    } 

    private void sendNotification(String message) { 
     Intent intent = new Intent(this, SplashScreenActivity.class); 
     intent.putExtra("isNotify", true); 
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); 

     Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
     NotificationCompat.Builder builder = new NotificationCompat.Builder(this) 
       .setSmallIcon(R.drawable.ic_stat_notify) 
       .setColor(getColor(R.color.colorAccent)) 
       .setContentTitle("Kinect") 
       .setWhen(System.currentTimeMillis()) 
       .setContentText(message) 
       .setAutoCancel(true) 
       .setSound(uri) 
       .setContentIntent(pendingIntent) 
       .setStyle(new NotificationCompat.BigTextStyle().bigText(message)) 
       .setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 }); 
     NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
     notificationManager.notify(notifyId, builder.build()); 
     notifyId++; 
    } 
} 

어떤 생각? 감사.

+1

log cat of crash plzz –

답변

1

.setColor (ContextCompat.getColor (이, R.color.colorAccent))를 시도;

+0

감사합니다. 나를 위해 일했다. –

0

라인은 :

.setColor(getColor(R.color.colorAccent)) 

문제를 일으키는 원인이된다. FirebaseMessagingService 클래스 내에서 호출하기 때문에 Android는 해당 메소드를 찾고 있습니다. 활동 컨텍스트를 참조하려면이를 사용해야 할 수 있습니다.