Java 为什么我的闹钟不能与启动一起工作
当我的android没有重新启动时,我的应用程序工作,但当我关闭android时,尽管我添加了BOOT_已完成,但应用程序仍不工作 我曾寻找过类似的问题,但所有问题都和我一样有效,我不知道出了什么问题 显示Java 为什么我的闹钟不能与启动一起工作,java,android,android-studio,alarmmanager,android-alarms,Java,Android,Android Studio,Alarmmanager,Android Alarms,当我的android没有重新启动时,我的应用程序工作,但当我关闭android时,尽管我添加了BOOT_已完成,但应用程序仍不工作 我曾寻找过类似的问题,但所有问题都和我一样有效,我不知道出了什么问题 显示 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.proyec
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.proyect.d.alarm">
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.SET_ALARM" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<service android:name=".BootService" />
<receiver
android:name=".RestartAlarmsReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<receiver
android:name=".MyAlarmReceiver"
android:process=":remote" />
</application>
BootService:它等于我的主警报服务
public class BootService extends IntentService {
public BootService(String name) {
super(name);
}
private NotificationManager notificationManager;
private final int NOTIFICATION_ID = 1010;
private AdminSQLiteOpenHelper admin;
private Cursor fila;
private SQLiteDatabase bd;
private String alarm, descrip, title;
@Override
protected void onHandleIntent(@Nullable Intent intent) {
Calendar calenda = Calendar.getInstance();
int hour, min, day, m, year;
String cadenaF, cadenaH, date_system, time_system;
day = calenda.get(Calendar.DAY_OF_MONTH);
m = calenda.get(Calendar.MONTH) + 1;
year = calenda.get(Calendar.YEAR);
hour = calenda.get(Calendar.HOUR_OF_DAY);
min = calenda.get(Calendar.MINUTE);
date_system = m + "-" + day + "-" + year + " ";
time_system = hour + ":" + min;
admin = new AdminSQLiteOpenHelper(getApplicationContext(), vars.bd, null, vars.version);
bd = admin.getWritableDatabase();
if (bd != null) {
fila = bd.rawQuery("SELECT * FROM alarma WHERE datea='" + date_system + "' AND timea= '" + time_system + "'", null);
if (fila.moveToFirst()) {
alarm = fila.getString(0);
title = fila.getString(1);
descrip = fila.getString(2);
triggerNotification(getApplicationContext(), title + "\n" + descrip);
}
}
bd.close();
}
private void triggerNotification(Context contexto, String t) {
Intent notificationIntent = new Intent(contexto, MainActivity.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(contexto, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Uri defaultSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
long[] pattern = new long[]{2000, 1000, 2000};
NotificationCompat.Builder builder = new NotificationCompat.Builder(contexto);
builder.setContentIntent(contentIntent)
.setTicker("")
.setContentTitle("alarm ")
.setContentTitle("")
.setContentText(t)
.setContentInfo("Info")
.setLargeIcon(BitmapFactory.decodeResource(contexto.getResources(), R.drawable.ic_launcher_background))
.setSmallIcon(R.drawable.ic_launcher_background)
.setAutoCancel(true)
.setSound(defaultSound)
.setVibrate(pattern);
Notification notificacion = new NotificationCompat.BigTextStyle(builder)
.bigText(t)
.setBigContentTitle("example")
.setSummaryText("more example")
.build();
notificationManager = (NotificationManager) contexto.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID, notificacion);
}
}
谢谢您能将您的接收器更改为添加导出和类别吗
<receiver android:name=".RestartAlarmsReceiver" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
根据官方文件
android:导出
广播接收器是否可以从其应用程序之外的源接收消息-如果可以,则为true,如果不能,则为false。如果为false,则广播接收器只能接收由相同应用程序的组件或具有相同用户ID的应用程序发送的消息。
默认值取决于广播接收器是否包含意图过滤器。缺少任何筛选器意味着只能由指定其确切类名的意图对象调用它。这意味着接收器仅用于应用程序内部使用,因为其他人通常不知道类名。因此,在本例中,默认值为false。另一方面,至少一个滤波器的存在意味着广播接收器打算接收由系统或其他应用程序广播的意图,因此默认值为真
此属性不是限制广播接收器外部曝光的唯一方法。您还可以使用权限限制可以向其发送消息的外部实体。请参见权限属性
希望这将有助于从字符串中删除您的引号。安卓Intent.action.BOOT_已完成。它仍然不工作
<receiver android:name=".RestartAlarmsReceiver" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>