При рефакторинге стало выдавать такую проблему в AndroidManifest.xml:"This class should provide a default constructor (a public constructor with no arguments) (`com.santana.doxxo.broadcastReceiver.AlarmService`)"
Скриншот фрагмента кода удалён модератором.
Исходный код "AndroidManifest.xml":
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.santana.doxxo">
<application
android:name="com.santana.doxxo.AppController"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.santana.doxxo.activity.AlarmActivity"></activity>
<activity android:name="com.santana.doxxo.activity.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.santana.doxxo.broadcastReceiver.AlarmBroadcastReceiver"
android:enabled="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
<service android:name="com.santana.doxxo.broadcastReceiver.AlarmService"
android:enabled="true"
android:exported="true"/>
</application>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
</manifest>
Исходный код "AlarmService.java":
package com.santana.doxxo.broadcastReceiver;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
import com.santana.doxxo.R;
import com.santana.doxxo.activity.MainActivity;
public class AlarmService extends Service {
private static final int NOTIFICATION_ID = 3;
public AlarmService(String name) {
super();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
onHandleIntent(intent);
return super.onStartCommand(intent, flags, startId);
}
protected void onHandleIntent(Intent intent) {
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel("YOUR_CHANNEL_ID",
"YOUR_CHANNEL_NAME",
NotificationManager.IMPORTANCE_DEFAULT);
channel.setDescription("YOUR_NOTIFICATION_CHANNEL_DESCRIPTION");
mNotificationManager.createNotificationChannel(channel);
}
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext(), "YOUR_CHANNEL_ID")
.setSmallIcon(R.mipmap.ic_launcher) // notification icon
.setContentTitle("title") // title for notification
.setContentText("Message")// message for notification
.setAutoCancel(true); // clear notification after click
Intent i = new Intent(getApplicationContext(), MainActivity.class);
PendingIntent pi = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(pi);
mNotificationManager.notify(0, mBuilder.build());
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
}