有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

JavaE/MemoryLeakMonitorManager:MemoryLeakMonitor。罐子不存在!安卓工作室

我目前正在我的广播监听服务中开发一个安卓应用程序,当我收到通知时,我会取消它,然后重新发送。当我用Facebook messenger通知测试它时,它会一直工作,直到我收到来自不同来源(Facebook上的不同朋友)的通知。一旦发生这种情况,我的应用程序在OnNotificationPosted()结束时崩溃。这是崩溃发生时我收到的错误:

> 5973/com.example.js.backgroundnotificationreciever
> E/MemoryLeakMonitorManager: MemoryLeakMonitor.jar is not exist!
> 
> 2019-03-10 19:55:30.014
> 5973-5973/com.example.js.backgroundnotificationreciever E/Minikin:
> Could not get cmap table size!

这是我的通知侦听器

public class NotificationService extends NotificationListenerService {
    private static int SUMMARY_ID = 0;
    public NotificationManager notificationManager;
    @Override
    public IBinder onBind(Intent intent) {
        notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        return super.onBind(intent);
    }

    @Override
    public void onNotificationPosted(StatusBarNotification sbn){
        HushNotification notif = new HushNotification(sbn);
        int code = notif.getNotifcationCode();

        if(code != 5) {
            double priority = notif.setPriority(notif);
            if (priority > 0.5 && priority < 3.0) {
                notificationManager.cancel(sbn.getTag(), sbn.getId());
                cancelNotification(sbn.getKey());
                sendNotifcation(notif, sbn);
            } else if (priority < 0.5 && priority > 0.0) {
                notificationManager.cancel(sbn.getTag(), sbn.getId());
                cancelNotification(sbn.getKey());
            }
        }

    }



    public void addToDataset(HushNotification notif){
        Firebase ref = new Firebase("https://hush-808f8.firebaseio.com/");
        DatabaseNotification c_notif = new DatabaseNotification(notif);
        ref.child("Notifications").push().setValue(c_notif);
    }

    @RequiresApi(api = Build.VERSION_CODES.O)
    private void sendNotifcation(HushNotification notif, StatusBarNotification sbn){
        Notification notification = notif.getNotification();

        notification.priority = Notification.PRIORITY_LOW;
        Notification notificationBuild = recoverBuilder(this, notification)
                .setChannelId("bucket")
                .build();
        int id = notif.getId();
        String tag = sbn.getTag();

        notificationManager.notify(tag, id, notificationBuild);


    }

}

这是我的丈夫通知课

public class HushNotification {
    @Exclude
    private Notification notification = new Notification();

    private int notification_code = 0;
    private String source;
    private double priority = 0;
    private String message;
    private long time = 0;
    private String title;
    private int id;
    private StatusBarNotification status_notif;
    private int cancelReason = 0;
    private int code = 0;
    private int rows = 0;

    //Constructor
    public HushNotification(StatusBarNotification sbn){
        status_notif = sbn; //
        time = sbn.getPostTime();
        notification = sbn.getNotification();
        message = notification.extras.getCharSequence(Notification.EXTRA_TEXT).toString();
        title = notification.extras.getCharSequence(Notification.EXTRA_TITLE).toString();
        source = sbn.getPackageName();
        notification_code = getAppCode(source);
        id = sbn.getId();

    }

    public static final class ApplicationPackageNames {
        public static final String FACEBOOK_PACK_NAME = "com.facebook.katana";
        public static final String FACEBOOK_MESSENGER_PACK_NAME =  "com.facebook.orca";
        public static final String WHATSAPP_PACK_NAME = "com.whatsapp";
        public static final String INSTAGRAM_PACK_NAME = "com.instagram.安卓";
        public static final String SNAPCHAT_PACK_NAME = "com.snapchat.安卓";
        public static final String HUSH_PACK_NAME = "com.example.jonathanstroz.backgroundnotificationreciever";
    }

    public static final class InterceptedNotificationCode {
        public static final int FACEBOOK_CODE = 1;
        public static final int WHATSAPP_CODE = 2;
        public static final int INSTAGRAM_CODE = 3;
        public static final int SNAPCHAT_CODE = 4;
        public static final int HUSH_CODE = 5;
        public static final int FACEBOOK_MESSENGER_CODE = 6;
        public static final int OTHER_NOTIFICATIONS_CODE = 0;

        public static int[] getNotificationCodes(){
            int[] temp = {OTHER_NOTIFICATIONS_CODE, FACEBOOK_CODE, WHATSAPP_CODE, INSTAGRAM_CODE, SNAPCHAT_CODE, HUSH_CODE, FACEBOOK_MESSENGER_CODE};
            return temp;
        }
    }

    public static final class ApplicationNames {
        public static final String FACEBOOK_NAME = "Facebook";
        public static final String WHATSAPP_NAME = "Whatsapp";
        public static final String INSTAGRAM_NAME = "Instagram";
        public static final String SNAPCHAT_NAME = "Snapchat";
        public static final String HUSH_NAME = "Hush";
        public static final String FACEBOOK_MESSENGER_NAME = "Messenger";
        public static final String OTHER_NOTIFICATIONS_NAME = "Other";

        public static String[] getApplicationNames(){
            String[] temp = {OTHER_NOTIFICATIONS_NAME, FACEBOOK_NAME, WHATSAPP_NAME, INSTAGRAM_NAME, SNAPCHAT_NAME, HUSH_NAME, FACEBOOK_MESSENGER_NAME};
            return temp;
        }
    }

    public static final class ApplicationImages {
        public static final int FACEBOOK_IMAGE_EXTRA_SMALL = R.drawable.facebook_logo_extra_small;
        public static final int FACEBOOK_IMAGE_SMALL = R.drawable.facebook_logo_small;
        public static final int INSTAGRAM_IMAGE_EXTRA_SMALL = R.drawable.instagram_logo_extra_small;
        public static final int INSTAGRAM_IMAGE_SMALL = R.drawable.instagram_logo_small;
        public static final int DEFAULT_IMAGE = R.drawable.hush_logo_full_no_background;

        public static int[] getApplicationImages() {
            int[] temp = {DEFAULT_IMAGE, FACEBOOK_IMAGE_EXTRA_SMALL, DEFAULT_IMAGE, INSTAGRAM_IMAGE_EXTRA_SMALL, DEFAULT_IMAGE, DEFAULT_IMAGE, DEFAULT_IMAGE};
            return temp;
        }
    }

    private int getAppCode(String source){
        if(source.equals(ApplicationPackageNames.FACEBOOK_PACK_NAME)){
            return(InterceptedNotificationCode.FACEBOOK_CODE);
        }
        else if(source.equals(ApplicationPackageNames.INSTAGRAM_PACK_NAME)){
            return(InterceptedNotificationCode.INSTAGRAM_CODE);
        }
        else if(source.equals(ApplicationPackageNames.WHATSAPP_PACK_NAME)){
            return(InterceptedNotificationCode.WHATSAPP_CODE);
        }
        else if(source.equals(ApplicationPackageNames.SNAPCHAT_PACK_NAME)){
            return(InterceptedNotificationCode.SNAPCHAT_CODE);

        }else if(source.equals(ApplicationPackageNames.HUSH_PACK_NAME)){
            return(InterceptedNotificationCode.HUSH_CODE);

        }else if(source.equals(ApplicationPackageNames.FACEBOOK_MESSENGER_PACK_NAME)){
            return(InterceptedNotificationCode.FACEBOOK_MESSENGER_CODE);
        }
        else{
            return(InterceptedNotificationCode.OTHER_NOTIFICATIONS_CODE);
        }
    }

    public double getPriority(){
        return priority;
    }

    public int getRow(){
        return rows;
    }

    public double setPriority(HushNotification notification){
        //make sure it is one of the apps that is set up with the user
        AppFeaturesHolder appHolder = MainActivity.mDatabaseHelper.getAppFeatures(notification_code);
        ArrayList<String> features = appHolder.getFeatureNames();
        ArrayList<Integer> feature_importance = appHolder.getFeatureImportances();
        int feature_chosen_importance = -1;
        String title = notification.getTitle();
        String text = notification.getMessage();

        for (int i = 1; i < features.size();i++){
            if(title.contains(features.get(i)) ||  text.contains(features.get(i))){
                feature_chosen_importance = feature_importance.get(i);
            }
        }

        int app_importance = feature_importance.get(0);

        if ( feature_chosen_importance == -1){
            feature_chosen_importance = app_importance;
        }

        // talk about possibility of modes

        //App importance set to id 1

        double priority = ((feature_chosen_importance + app_importance)/10.00) * 3.00;

        if(notification_code == InterceptedNotificationCode.OTHER_NOTIFICATIONS_CODE){
            priority = -1;
        }

        return priority;
    }

    public String getSource(){return source;}
    public long getTime(){
        return time;
    }
        public String getMessage(){
        return message;
    }
    public int getNotifcationCode(){
        return notification_code;
    }
    public int getCancelReason(){
        return cancelReason;
    }
    public String getTitle(){
        return title;
    }
    public int getId() { return id;}

    @Exclude public Notification getNotification() {return notification;} // Exclude Notification Feild

    public StatusBarNotification getStatus_notif() {return status_notif;}
    public void setCancelReason(int reason){
        if(reason == 1 || reason == 2 || reason == 3){
            cancelReason = reason;
        }else{
            cancelReason = 0;
        }
        // REASON_CLICK: User clicks on the app (1)
        // REASON_CANCEL: User swipes (2)
        // REASON_CANCEL_ALL: USer cancels all notfications (3)
    }
}

这是我的档案器的图像(无泄漏) Crash at the end with no spike

我使用的是Huewei荣誉6X api级别26

我尝试过更新类路径,但仍然崩溃 classpath'com。安卓工具。建造:渐变:3.3.1'

为什么我会出现这些错误,为什么我的应用程序会崩溃


共 (0) 个答案