我搞砸了System_server服务吗?

时间:2017-04-26 00:58:10

标签: android logging alarmmanager android-notifications

我的手机正在生成一个不停的Log.d输出。关于每秒1200次,以下一遍又一遍地重复。

04-25 15:58:04.883 1542-5012/? D/NetworkStatsCollection: getHistory:mUID 10266 isVideoCallUID: false

PID 1542是System_server,我已经了解它管理一系列Android服务。在我正在开发的应用程序中,我使用Alarm Manager和Notification服务,如下所示。有什么我可以做的让这项服务以它的方式作出反应吗?

public void scheduleNotification(Context context, long alarmTime, int notificationId, String setOrCancel) {
    EditText questionView = (EditText)findViewById(R.id.question);
    String questionText = questionView.getText().toString();
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setContentTitle(context.getString(R.string.app_name))
            .setContentText(questionText)
            .setAutoCancel(true)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setLargeIcon(((BitmapDrawable) context.getResources().getDrawable(R.mipmap.ic_launcher)).getBitmap())
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));

    Intent intent = new Intent(context, DashboardActivity.class);
    PendingIntent activity = PendingIntent.getActivity(context, notificationId, intent, PendingIntent.FLAG_CANCEL_CURRENT);
    builder.setContentIntent(activity);

    Notification notification = builder.build();

    Intent notificationIntent = new Intent(context, TrackerNotificationService.class);
    notificationIntent.putExtra(TrackerNotificationService.NOTIFICATION_ID, notificationId);
    notificationIntent.putExtra(TrackerNotificationService.NOTIFICATION, notification);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, notificationId,
            notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    if (setOrCancel.equals("set")) {
        alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTime, pendingIntent);
        Log.d("Check it", "scheduleNotification: " + alarmTime);
    }else{
        alarmManager.cancel(pendingIntent);
    }

}

TrackerNotificationService.java

import android.app.Notification;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class TrackerNotificationService extends BroadcastReceiver {


    public static String NOTIFICATION_ID = "notification_id";
    public static String NOTIFICATION = "notification";

    @Override
    public void onReceive(final Context context, Intent intent) {

        NotificationManager notificationManager = (NotificationManager) 
                context.getSystemService(Context.NOTIFICATION_SERVICE);

        Notification notification = intent.getParcelableExtra(NOTIFICATION);
        int notificationId = intent.getIntExtra(NOTIFICATION_ID, 0);
        notificationManager.notify(notificationId, notification);
    }
}

1 个答案:

答案 0 :(得分:1)

我有三星Galaxy S7 Edge,我注意到我的LogCat中的NetworkStatsCollection垃圾邮件也开始在我的设备上发生。

正如this帖所示,这似乎是一个核心操作系统进程。 设备制造商(在我的情况下为三星)必须在其最新的操作系统更新中进行一些修改并留下一些调试。 非常烦人,我必须补充一下。

使用this作为临时解决方法,但也请将其报告给离您最近的三星服务中心。希望有足够的报告,他们可以快速部署修复它的操作系统更新