我在Android中有一个项目,我用eclipse开发。我想在我的项目中添加推送通知。
新的解决方案是Firebase云消息传递,我想使用它。但是所有文档和示例都是使用Android Studio编码的,但由于某些依赖性,我无法转移到Android Studio。
我无法在eclipse中解决这个问题。有没有办法将Firebase Cloud Messaging集成到我的Eclipse项目中?
答案 0 :(得分:1)
我认为这不可行。在docs中,它声明:
要编写Firebase云消息传递Android客户端应用,请使用FirebaseMessaging API和 Android Studio 1.4或更高版本与Gradle 。
答案 1 :(得分:0)
免责声明:我没有对此进行过测试,并鼓励任何遇到这个问题的人节省无数个小时并继续使用Android Studio。
从Android SDK Manager下载最新的Google Play服务库(至少v9.0.0)并将其导入Eclipse项目。
由于您无法使用google-services
gradle插件,因此您必须自行设置Firebase。在您的自定义Application.onCreate
电话中:
FirebaseOptions options = new FirebaseOptions.Builder()
// Setup here.
.build();
FirebaseApp.initializeApp(this, options);
设置选项:https://firebase.google.com/docs/reference/android/com/google/firebase/FirebaseOptions.Builder
您需要至少设置API密钥,应用程序ID和GCM发件人ID,您可以在Firebase / Google Dev Console中找到所有这些ID。
更新AndroidManifest.xml
:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<permission android:name="${applicationId}.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE"/>
<application>
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
<!-- FirebaseMessagingService performs security checks at runtime,
no need for explicit permissions despite exported="true" -->
<service android:name="com.google.firebase.messaging.FirebaseMessagingService" android:exported="true">
<intent-filter android:priority="-500">
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
</application>
值来自Play服务库v9.6.1。将${applicationId}
替换为您的应用ID。
Rant:您想知道为什么我们使用Android Studio和Gradle吗?因为那时我们不必做任何这个****,它会随着每个新版本的库自动更新。
更新您的proguard规则:
# Proguard flags for consumers of the Google Play services SDK
# https://developers.google.com/android/guides/setup#add_google_play_services_to_your_project
# Keep SafeParcelable value, needed for reflection. This is required to support backwards
# compatibility of some classes.
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
public static final *** NULL;
}
# Needed for Parcelable/SafeParcelable classes & their creators to not get renamed, as they are
# found via reflection.
-keepnames class * implements android.os.Parcelable
-keepclassmembers class * implements android.os.Parcelable {
public static final *** CREATOR;
}
# Keep the classes/members we need for client functionality.
-keep @interface android.support.annotation.Keep
-keep @android.support.annotation.Keep class *
-keepclasseswithmembers class * {
@android.support.annotation.Keep <fields>;
}
-keepclasseswithmembers class * {
@android.support.annotation.Keep <methods>;
}
# Keep the names of classes/members we need for client functionality.
-keep @interface com.google.android.gms.common.annotation.KeepName
-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
@com.google.android.gms.common.annotation.KeepName *;
}
# Keep Dynamite API entry points
-keep @interface com.google.android.gms.common.util.DynamiteApi
-keep @com.google.android.gms.common.util.DynamiteApi public class * {
public <fields>;
public <methods>;
}
# Needed when building against pre-Marshmallow SDK.
-dontwarn android.security.NetworkSecurityPolicy
# Needed when building against Marshmallow SDK.
-dontwarn android.app.Notification
# Needed for isDeviceProtectedStorage when building against a pre-Nougat SDK.
-dontwarn android.content.Context
继续https://firebase.google.com/docs/cloud-messaging/android/client的Android Studio和Gradle教程。