如何在 Eclipse 项目中使用 Firebase 云消息?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37792333/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I use Firebase cloud message in an eclipse project?
提问by b1065579
I have a project in eclipse. I need include firebaselibrary. If I was using Android Studio the steps would simply be:
我在 Eclipse 中有一个项目。我需要包含firebase库。如果我使用的是 Android Studio,步骤就是:
And its all, all library include.
它的全部,所有库都包括在内。
But I cant understand how include firebase cloud message to eclipse. I cant find how include it to eclipse.
但我无法理解如何将 firebase 云消息包含到 Eclipse 中。我无法找到如何将它包含在 Eclipse 中。
回答by usajnf
The new Firebase (9xx) libraries can be found in the Google Repository. You can install this with the Eclipse Android SDK Manager. Open the SDK manager and scroll down until you find Google Repository and install the package.
可以在 Google 存储库中找到新的 Firebase (9xx) 库。您可以使用 Eclipse Android SDK Manager 安装它。打开 SDK 管理器并向下滚动,直到找到 Google Repository 并安装该软件包。
The package will be installed in /extras/google/m2repository and you will find the Firebase files further down at /com/google/android/firebase.
该软件包将安装在 /extras/google/m2repository 中,您将在 /com/google/android/firebase 的下方找到 Firebase 文件。
You can rename the .aar files to .zip and extract the jar file, rename these from classes.jar and copy them to the project libs folder displayed in Eclipse (or copy outside Eclipse and then follow the instructions to import a project into Eclipse.)
您可以将 .aar 文件重命名为 .zip 并提取 jar 文件,从 classes.jar 重命名这些文件并将它们复制到 Eclipse 中显示的项目 libs 文件夹(或复制到 Eclipse 之外,然后按照说明将项目导入 Eclipse。 )
回答by usajnf
There is a move towards Android Studio with Gradle. The Eclipse solution to Firebase CM is not forthcoming. My feeling is we will all have to move to AS with Gradle soon. There are good books on it and very simple instructions on Google dev sites. We might as well start learning the new IDE and migrate.
使用 Gradle 正在向 Android Studio 迈进。Firebase CM 的 Eclipse 解决方案尚未推出。我的感觉是,我们都必须很快使用 Gradle 迁移到 AS。谷歌开发网站上有关于它的好书和非常简单的说明。我们不妨开始学习新的 IDE 并进行迁移。
回答by Yuw
You can add this on your Android Manifest
您可以将其添加到您的 Android 清单中
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<receiver
android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="YOUR PACKAGE NAME" />
</intent-filter>
</receiver>
<receiver
android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver"
android:exported="false" />
And then you can get the token and try to send Message on.
然后你可以获得令牌并尝试发送消息。
Dont forget also to build FirebaseApps on your code (in my case on my MainActivity)
也不要忘记在您的代码上构建 FirebaseApps(在我的情况下是在我的 MainActivity 上)
FirebaseOptions options = new FirebaseOptions.Builder()
.setApiKey("YOUR FIREBASE API KEY")
.setApplicationId("YOUR FIREBASE APP ID")
.setGcmSenderId("YOUR FIREBASE SENDER ID")
.build();
FirebaseApp myApp = FirebaseApp.initializeApp(getApplicationContext(), options);
token = FirebaseInstanceId.getInstance(myApp).getToken();
Hope it will get what you looking for on Eclipse.
希望它能得到你在 Eclipse 上寻找的东西。
回答by Dan Dar3
Have a look at the resources below. In short, it's about including the Firebase libraries into your project (see the GitHub project and the two videos at the end) and manually performing the steps that the plugin does for you in Android Studio / Gradle.
看看下面的资源。简而言之,就是将 Firebase 库包含到您的项目中(请参阅 GitHub 项目和最后的两个视频)并在 Android Studio/Gradle 中手动执行插件为您执行的步骤。
- Firebase libraries for Eclipse
https://github.com/dandar3/android-google-firebase-README - Eclipse: Integrating Firebase Analytics into your Android app
(same steps apply for other Firebase components, will write a post specifically for Cloud Messaging soon)
http://dandar3.blogspot.com/2016/11/eclipse-integrate-firebase-analytics.html
- Eclipse 的 Firebase 库
https://github.com/dandar3/android-google-firebase-README - Eclipse:将 Firebase Analytics 集成到您的 Android 应用程序中
(相同的步骤适用于其他 Firebase 组件,很快将专门针对云消息传递写一篇文章)
http://dandar3.blogspot.com/2016/11/eclipse-integrate-firebase-analytics。 html
回答by PCGALI ANDROID
Old code is working no need to change code in firebase only change is in server code you have to use Web API Key from firebase project and Sender ID as per old code style. and you have to replace gcm url in web script - https://fcm.googleapis.com/fcm/send
旧代码正在工作,无需更改 firebase 中的代码,仅更改服务器代码,您必须按照旧代码样式使用 firebase 项目中的 Web API 密钥和发件人 ID。并且您必须在网络脚本中替换 gcm url - https://fcm.googleapis.com/fcm/send
No Requirement of firebase library...
不需要firebase库...