我正在尝试使用教程在应用程序中集成FireBase云消息:
https://www.simplifiedcoding.net/firebase-cloud-messaging-tutorial-android/
下面是logcat:
java.lang.NullPointerException: Attempt to invoke virtual method
'boolean com.google.android.gms.common.ConnectionResult.isSuccess()' on a null object reference
at com.google.android.gms.common.internal.zzd$zzi.zzh(Unknown Source)
at com.google.android.gms.common.internal.zzd$zzk.zztp(Unknown Source)
at com.google.android.gms.common.internal.zzd$zza.zzc(Unknown Source)
at com.google.android.gms.common.internal.zzd$zza.zzw(Unknown Source)
at com.google.android.gms.common.internal.zzd$zze.zztr(Unknown Source)
at com.google.android.gms.common.internal.zzd$zzd.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
这是我的建筑格拉德尔:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
//FireBase dependency
classpath 'com.google.gms:google-services:3.0.0'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(include: '*.jar', dir: 'libs')
//FireBase dependency
compile 'com.google.firebase:firebase-messaging:10.0.1'
}
android {
compileSdkVersion 20
buildToolsVersion '23.0.3'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
lintOptions {
abortOnError false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
productFlavors {
x86 {
ndk {
abiFilter "x86"
}
}
arm {
ndk {
abiFilters "armeabi-v7a", "armeabi"
}
minSdkVersion 17
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/license.txt'
exclude 'META-INF/notice.txt'
}
defaultConfig {
minSdkVersion 17
applicationId "com.nytshft.evyt"
}
}
//FireBase
apply plugin: 'com.google.gms.google-services'
注意:我的应用程序中没有应用程序模块。我只有一个建筑.梯度文件。
跟建筑有关吗?在官方站点中,他们说要在应用文件夹中复制json文件。不幸的是,我的应用程序没有这样的文件夹。下面是ProjectView的截图。他们还说要在应用程序的build.gradle中添加一些依赖项。因为我没有任何app文件夹,所以我在项目的build.gradle文件中做了这些更改。
MyFireBaseInstanceIDService.java:
class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
private static final String TAG = "MyFirebaseIIDService";
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
sendRegistrationToServer(refreshedToken);
}
private void sendRegistrationToServer(String token) {
// TODO: Implement this method to send token to your app server.
}
MyFirebaseMessagingService.java
class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "From: " + remoteMessage.getFrom());
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
//Calling method to generate notification
//sendNotification(remoteMessage.getNotification().getBody());
}
Toast.makeText(getApplicationContext(), "Push notification: " + remoteMessage.getNotification().getBody(), Toast.LENGTH_LONG).show();
}
/**
* Create and show a simple notification containing the received FCM message.
* This method is only generating push notification.
* @param messageBody FCM message body received.
*/
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.androidwidget_logo)
.setContentTitle("FCM Message")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
我的应用程序有问题,我想解决它,但我无法访问解决方案,请帮助我,,,
我正在尝试实现一个外部色轮,它应该出现在的片段一直在崩溃我的应用程序。我想我明白为什么会发生这种情况,但是在尝试修复它大约6个小时后,我就要放弃了。我知道之前有人问过这个问题,但是我无法为我的特定问题导出一个修复程序。下面是我的代码: 这是Logcat错误: 如果有人能帮我解决这个问题,那就太好了。提前谢谢^^ 编辑:这是我的XML,按要求:
我正在发布我的应用程序的新版本,并使用谷歌的测试实验室。现在我第一次遇到了一个问题,这是在一段代码中引发的,与所有以前的版本(运行完美)相比,我没有改变代码: 只有在Galaxy S6与Android 5.1(12个设备)我得到以下错误: 问题:java。lang.NullPointerException:尝试调用虚拟方法的布尔com。谷歌。Android芬斯基。应用程序编程接口。模型DfeToc
我将使用库,并尝试在应用程序启动时使用以下方法获取令牌。 应用程序在发布时崩溃 AndroidManifest Build.Gradle: 此外,我尝试在SharedPreferences中缓存令牌,但似乎从未调用onNewToken()。 会有什么问题?
我将要制作android应用程序,但是由于致命的异常:main java.lang.NullPointerException应用程序没有保存数据,请在这里帮助我 这是我的EditNoteActivity 这是我的Logcat错误
我正在使用下面的代码从playstore中获取versionName,通过使用jsoup,我正在获取详细信息,但它会引发一些异常。 我的密码是 请有人帮我解决这个问题。