2016-09-01 3 views
1

에서 중포 기지를 사용하여 알림을받지 이클립스를 사용하는 경고없이 중포 기지 건물을 가지고있다 (관련 참조 : Unable to find obfuscated Firebase class in Eclipse)이클립스

내가하지만 난 아무것도받지 못했습니다, 테스트 알림을 보내려고. 나는 도서관 프로젝트도 사용하고있다.

public class MyFirebaseInstanceIdService extends FirebaseInstanceIdService { 

    private static final String TAG = "Firebase"; 
    private static final String FRIENDLY_ENGAGE_TOPIC = "friendly_engage"; 

    /** 
    * The Application's current Instance ID token is no longer valid 
    * and thus a new one must be requested. 
    */ 
    @Override 
    public void onTokenRefresh() { 
     // If you need to handle the generation of a token, initially or 
     // after a refresh this is where you should do that. 
     String token = FirebaseInstanceId.getInstance().getToken(); 
     Log.d(TAG, "FCM Token: " + token); 

     // Once a token is generated, we subscribe to topic. 
     FirebaseMessaging.getInstance().subscribeToTopic(FRIENDLY_ENGAGE_TOPIC); 
    } 
} 

내가 통해 메시지를 보내

<application /> 
    ... 
    <!-- ================================== 
       FIREBASE 
    =================================== --> 
    <service 
     android:name=".MyFirebaseMessagingService" 
     android:exported="false"> 
     <intent-filter> 
      <action android:name="com.google.firebase.MESSAGING_EVENT" /> 
     </intent-filter> 
    </service> 

    <service 
     android:name=".MyFirebaseInstanceIdService" 
     android:exported="false"> 
     <intent-filter> 
      <action android:name="com.google.firebase.INSTANCE_ID_EVENT" /> 
     </intent-filter> 
    </service> 
.... 
</application> 

이 파일은 샘플에서 실질적으로 직선

의 AndroidManifest.xml :

public class MyFirebaseMessagingService extends FirebaseMessagingService { 

    public static final String PUSH_NOTIFICATION_TEXT = "pushnotificationtext"; 

    private static final String TAG = "Firebase"; 

    public static final int NOTIFICATION_ID = 1; 

    @Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 
     // Handle data payload of FCM messages. 
     String messageId = remoteMessage.getMessageId(); 
     RemoteMessage.Notification notification = remoteMessage.getNotification(); 
     Map<String, String> data = remoteMessage.getData(); 

     Log.d(TAG, "FCM Message Id: " + messageId); 
     Log.d(TAG, "FCM Notification Message: " + notification); 
     Log.d(TAG, "FCM Data Message: " + data); 

     sendNotification(this, notification.toString()); 

    } 

    // Put the GCM message into a notification and post it. 
    private void sendNotification(Context context, String message) { 

     NotificationManager mNotificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); 

     final Intent intent = new Intent(context, Splash.class); 
     //intent.putExtras(bundle); 
     intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); 

     //Save push notification message to show when app starts 
     SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); 
     sp.edit().putString(PUSH_NOTIFICATION_TEXT, message).commit(); 

     PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT); 

     final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) 
      .setAutoCancel(true) 
      .setVibrate(new long[] { 0, 500, 200, 500, 200, 500 }) 
      .setContentIntent(contentIntent) 
      .setContentTitle(context.getString(R.string.app_name)) 
      .setSmallIcon(R.drawable.ic_launcher) 
      .setStyle(new NotificationCompat.BigTextStyle().bigText(message)) 
      .setContentText(message) 
      .setWhen(System.currentTimeMillis()).setOngoing(false); 

     mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); 
    } 

} 

다른 클래스이 내 코드입니다 패키지 이름을 타겟으로하는 Firebase 콘솔. 나는이 일을하기 위해 내가 무엇을해야하는지 불확실하다. 어떤 방식 으로든 google-services.json 파일을 사용해야합니까?

감사합니다.

+0

Android Studio 사용 –

+0

안타깝게도 할 수 없습니다. – zundi

답변

0

저는 Eclipse를 사용하지 않으며 이러한 단계가 작동하는지 확인할 수 없습니다. 나는 그들이 당신을 올바른 길로 인도하기를 바랍니다.

Firebase 프레임 워크는 FirebaseInitProvider으로 초기화됩니다. 당신은 그것을 구현하거나 서브 클래스 할 필요가 없다. 매니페스트에 선언하십시오.

<provider 
     android:authorities="${applicationId}.firebaseinitprovider" 
     android:name="com.google.firebase.provider.FirebaseInitProvider" 
     android:exported="false" 
     android:initOrder="100" /> 

FirebaseInitProvider 프로젝트의 구성 값을 포함하는 문자열 리소스를 찾을 것으로 예상됩니다. Android Studio 및 Google Services Gradle Plugin으로 빌드 된 앱에서 리소스 값은 google-services.json 파일에서 생성됩니다. AS와 플러그인을 사용하고 있지 않으므로 res 폴더에 이러한 리소스를 정의해야합니다. 값은 Firebase 콘솔의 프로젝트 설정이나 google-service.json file에서 찾을 수 있습니다. 메시징에만 관심이 있으 G로 일부 값은 필요하지 않을 수 있습니다. 안전을 기하기 위해 초기에 모두 정의하십시오.

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <string name="default_web_client_id" translatable="false">8888888888888-ooqodhln4cjj4qst7b4sadfiousdf7.apps.googleusercontent.com</string> 
    <string name="firebase_database_url" translatable="false">https://project-888888888888888.firebaseio.com</string> 
    <string name="gcm_defaultSenderId" translatable="false">888888888888</string> 
    <string name="google_api_key" translatable="false">AIzaSyB0Bhr1sfsydfsdfnwelhkOYifak_Go2xU</string> 
    <string name="google_app_id" translatable="false">1:888888888888:android:526f9740dfg987sdfg</string> 
    <string name="google_crash_reporting_api_key" translatable="false">AIzaSyDkG-g8hH7T4TV7Rrsdfgiopudfmn234897</string> 
    <string name="google_storage_bucket" translatable="false">project-8888888888888888888888.appspot.com</string> 
</resources> 

당신은 당신의 주요 활동의 onCreate() 방법이 코드를 넣어 성공 초기화가 있음을 확인할 수 있습니다,

유효한 결과가 기록되는 경우
FirebaseOptions opts = FirebaseApp.getInstance().getOptions(); 
    Log.i(TAG, "onStart: ID=" + opts.getApplicationId()); 
    Log.i(TAG, "onStart: SenderId=" + opts.getGcmSenderId()); 
    Log.i(TAG, "onStart: Key=" + opts.getApiKey()); 

, 그것은 FirebaseApp가 초기화 된 기본을 나타내며 당신은 메시지를받을 수 있어야합니다.

+0

좋은 물건, 나는 이것을 지금 시험해보고있다. JSON 파일은 어떻게 XML로 변환됩니까? 예를 들어 { "project_info": { "project_number": "75794", "firebase_url": "https://this-is-a-test-project.firebaseio.com"등의 값을보고 있습니다. – zundi

+0

@ zundi : 찾고있는 매핑이 Google 서비스 Gradle Plugin 문서에 있습니다. 제 대답에 링크되어 있습니다. –

+0

@ zundi : 이것의 최종 결과는 무엇입니까? 너에게 효과가 있었 니? –