gpt4 book ai didi

android - ParseUtils 中的 NoClassDefFoundError

转载 作者:太空宇宙 更新时间:2023-11-03 12:49:29 25 4
gpt4 key购买 nike

我正在使用解析推送通知我收到以下错误

   java.lang.NoClassDefFoundError: notifications.ParseUtils$1
at notifications.ParseUtils.registerParse(ParseUtils.java:33)
at com.techieweb.solutions.pickeronline.MyApplication.onCreate(MyApplication.java:20)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1017)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4590)
at android.app.ActivityThread.access$1400(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5317)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)

我用这个作为引用 http://www.androidhive.info/2015/06/android-push-notifications-using-parse-com/

这是我的 ParseUtils.java 类

  public class ParseUtils {

private static String TAG = ParseUtils.class.getSimpleName();

public static void verifyParseConfiguration(Context context) {
if (TextUtils.isEmpty(AppConfig.PARSE_APPLICATION_ID) || TextUtils.isEmpty(AppConfig.PARSE_CLIENT_KEY)) {
Toast.makeText(context, "Please configure your Parse Application ID and Client Key in AppConfig.java", Toast.LENGTH_LONG).show();
((Activity) context).finish();
}
}

public static void registerParse(Context context) {
// initializing parse library
Parse.initialize(context, AppConfig.PARSE_APPLICATION_ID, AppConfig.PARSE_CLIENT_KEY);
ParseInstallation.getCurrentInstallation().saveInBackground();
//Shows error heree
ParsePush.subscribeInBackground(AppConfig.PARSE_CHANNEL, new SaveCallback() {
@Override
public void done(ParseException e) {
Log.e(TAG, "Successfully subscribed to Parse!");
}
});
}

public static void subscribeWithEmail(String email) {
ParseInstallation installation = ParseInstallation.getCurrentInstallation();

installation.put("email", email);

installation.saveInBackground();

Log.e(TAG, "Subscribed with email: " + email);
}
}

这是我的应用程序

    public class MyApplication extends Application {

private static MyApplication mInstance;

@Override
public void onCreate() {
super.onCreate();
mInstance = this;

// register with parse
ParseUtils.registerParse(this);
}


public static synchronized MyApplication getInstance() {
return mInstance;
}
}

这是 NotificationUtils 类

public class NotificationUtils {

private String TAG = NotificationUtils.class.getSimpleName();

private Context mContext;

public NotificationUtils() {
}

public NotificationUtils(Context mContext) {
this.mContext = mContext;
}

public void showNotificationMessage(String title, String message, Intent intent) {

// Check for empty push message
if (TextUtils.isEmpty(message))
return;

if (isAppIsInBackground(mContext)) {
// notification icon
int icon = R.mipmap.ic_launcher;

int smallIcon = R.drawable.ic_push;

int mNotificationId = AppConfig.NOTIFICATION_ID;

PendingIntent resultPendingIntent =
PendingIntent.getActivity(
mContext,
0,
intent,
PendingIntent.FLAG_CANCEL_CURRENT
);

NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
mContext);
Notification notification = mBuilder.setSmallIcon(smallIcon).setTicker(title).setWhen(0)
.setAutoCancel(true)
.setContentTitle(title)
.setStyle(inboxStyle)
.setContentIntent(resultPendingIntent)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), icon))
.setContentText(message)
.build();

NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(mNotificationId, notification);
} else {
intent.putExtra("title", title);
intent.putExtra("message", message);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
mContext.startActivity(intent);
}
}

/**
* Method checks if the app is in background or not
*
* @param context
* @return
*/
public static boolean isAppIsInBackground(Context context) {
boolean isInBackground = true;
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) {
List<ActivityManager.RunningAppProcessInfo> runningProcesses = am.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo processInfo : runningProcesses) {
if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
for (String activeProcess : processInfo.pkgList) {
if (activeProcess.equals(context.getPackageName())) {
isInBackground = false;
}
}
}
}
} else {
List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
ComponentName componentInfo = taskInfo.get(0).topActivity;
if (componentInfo.getPackageName().equals(context.getPackageName())) {
isInBackground = false;
}
}

return isInBackground;
}
}

请帮帮我。

最佳答案

通过删除解决了错误

  ParsePush.subscribeInBackground(AppConfig.PARSE_CHANNEL, new SaveCallback() {
@Override
public void done(ParseException e) {
Log.e(TAG, "Successfully subscribed to Parse!");
}
});

并且只使用

  ParseInstallation.getCurrentInstallation().saveInBackground();

https://teamtreehouse.com/community/pushservicesetdefaultpushcallback-has-now-been-depreciated-what-can-be-used

关于android - ParseUtils 中的 NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34588991/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com