我在按钮单击时创建了警报管理器。但在电话重启后无法使用。我的AlarmbroadcastReceiver不会在电话重启时拨打电话。它工作时,电话锁定,应用程序死亡,但不工作后,手机重新启动我创建了一个进度条,开始点击按钮和警报广播后开始停止,但不会停止时,手机重新启动。我已经将我的按钮单击事件和广播接收器类Alarmmanager在电话重启之后不工作
按钮单击事件
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pb1.setVisibility(View.VISIBLE);
progress_edit.putBoolean("progress_one", true);
progress_edit.apply();
AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intnt = new Intent(getApplicationContext(), AlarmbroadcastReceiver.class);
intnt.setAction("com.ex.Alarm");
PendingIntent pending = PendingIntent.getBroadcast(getApplicationContext(), 0, intnt, 0);
manager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 120000, pending);
Log.d("Broadcast ","Fired");
}
});
广播接收器类
@Override
public void onReceive(Context context, Intent intent) {
Log.d("inside","broadcast receive");
if(intent.getAction().equalsIgnoreCase("com.ex.Alarm"))
{
enterSys_progress_edit.putBoolean("progress_one", false);
enterSys_progress_edit.apply();
Toast.makeText(context,"Receive",Toast.LENGTH_LONG).show();
}
}
我的清单文件
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.krutarth.alarm">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".AlarmbroadcastReceiver" android:enabled="true" android:exported="false" android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter >
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
</application>
</manifest>
个
可能是重复的http://stackoverflow.com/questions/26296270/alarmmanager-not-trigger-after-the-phone-reset – sasikumar