gpt4 book ai didi

Android:我的 BOOTCOMPLETED 接收类没有启动我的闹钟

转载 作者:行者123 更新时间:2023-11-30 01:08:49 28 4
gpt4 key购买 nike

我有个问题一直没弄清楚。我有一个重复的警报广播接收器,我已经设置了另一个广播接收器来接收 BOOT_COMPLETE 信号,以便在启动时重新启动警报。代码看起来和我查过的其他人的一样,所以我不确定哪里出了问题。

我的启动接收器:

public class DeviceBootReceiver extends BroadcastReceiver {
Context context2;

public boolean fileExistance(String fname){
File file = context2.getApplicationContext().getFileStreamPath(fname);
return file.exists();
}




public String loadCurrentWhat (String filename){
FileInputStream fileInputStream;
String info = "";
try {
fileInputStream = context2.getApplicationContext().openFileInput(filename);
int count;
while ((count=fileInputStream.read()) != -1){
info += Character.toString((char)count);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return info;
}

@Override
public void onReceive(Context context, Intent intent) {
context2 = context;
if (fileExistance("number")){
/* Setting the alarm here */
Intent alarmIntent = new Intent(context, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0);

AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
int interval = 10000;
manager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), interval, pendingIntent);
}

}
}

我的重复闹钟:

public class AlarmReceiver extends BroadcastReceiver {


Context context2;

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

// For our recurring task, we update the character data in internal storage.
context2 = context.getApplicationContext();
UPDATE();

}
}

我的 list :

 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".CardFullView"/>

<receiver
android:name=".DeviceBootReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

<receiver
android:name=".AlarmReceiver">
</receiver>



</application>

最佳答案

据我目前所见,您需要将RECEIVE_BOOT_COMPLETED 权限放在应用程序 标签。

试试这个。这应该有效。

关于Android:我的 BOOTCOMPLETED 接收类没有启动我的闹钟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38626675/

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