AlarmManager没有调用任务? [英] AlarmManager not invoking the task?

查看:90
本文介绍了AlarmManager没有调用任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程序中每天晚上10点以后执行一次自动注销,因为我已经实现了AlarmManager任务,但没有调用。出于测试目的,我给出了其他计时。(例如

I want to execute a auto-logout after 10 PM everyday in my application, for that that I have implemented a AlarmManager task but it is not invoking .For testing purpose I have given the other timing .(e.g

calendar.set(Calendar.HOUR_OF_DAY,15);
                    calendar.set(Calendar.MINUTE,59);
                    calendar.set(Calendar.SECOND,30);


AlarmManager代码:

) AlarmManager Code:

 sign_in_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                hideKeyboard(LoginActivity.this);
                //implementation of auto logout
                checkSuiteSession = new CheckSuiteSession(getApplicationContext());
                checkSuiteSession.check_attendance_flag("true");
                Calendar calendar = Calendar.getInstance();
                calendar.set(Calendar.HOUR_OF_DAY,15);
                calendar.set(Calendar.MINUTE,59);
                calendar.set(Calendar.SECOND,30);
                Intent autoLogoutIntent = new Intent(getApplicationContext(),AutoLogoutRecevier.class);
                PendingIntent pendingIntent =
                        PendingIntent.getBroadcast(getApplicationContext(),100,autoLogoutIntent,PendingIntent.FLAG_UPDATE_CURRENT);

                AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
                alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(),AlarmManager.INTERVAL_DAY,pendingIntent);

我的广播接收器类别:

public class AutoLogoutRecevier extends BroadcastReceiver {
    CheckSuiteSession checkSuiteSession;
    @Override
    public void onReceive(Context context, Intent intent) {
        checkSuiteSession = new CheckSuiteSession(context);
        //calling logout function
        checkSuiteSession.logoutUser();
        Log.d("LOGOUT","auto logout executed");
        checkSuiteSession.check_attendance_flag("false");


    }
}

我的清单文件(我添加了以下权限):

My manifest file (I have added the following permission) :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.fresherguru.checksuite">

    <!-- To auto-complete the email text field in the login form with the user's emails -->
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.READ_PROFILE" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <uses-permission android:name="android.permission.WAKE_LOCK"/>

    <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"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service
            android:name=".fcm.MyFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
        </service>
        <service android:name=".fcm.MyFirebaseInstanceIDService">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
            </intent-filter>
        </service>

        <receiver android:name=".autoLogoutReceiver.AutoLogoutRecevier">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
        </intent-filter>
        </receiver>

        <receiver android:name=".autoLogoutReceiver.ActivateLogin">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
            </intent-filter>
        </receiver>

        <receiver android:name=".autoLogoutReceiver.ChangeDialogStatus"
            android:process=":remote"/>
        <receiver android:name=".autoLogoutReceiver.ScreenUnlockReceiver">
            <intent-filter>
                <action android:name="android.intent.action.USER_PRESENT" />
                <!--<action android:name="android.intent.action.ACTION_SHUTDOWN" />-->
            </intent-filter>
            </receiver>


        <receiver android:name=".autoLogoutReceiver.DeviceBootReceiver"
            android:enabled="false">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
                <action android:name="android.intent.action.REBOOT"/>
            </intent-filter>
        </receiver>
        <service android:name=".service.CallHandleAlarmService"
            android:enabled="true"/>

        <activity
            android:name=".home.LoginActivity"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity
            android:name=".home.HomeActivity"
            android:theme="@style/AppTheme.NoActionBar" />

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />


        <activity
            android:name=".home.CheckSuiteForm"
            />
    </application>

</manifest>


推荐答案

您放了

< receiver android:name =。AutoLogoutRecevier />

in您的清单?

这篇关于AlarmManager没有调用任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆