2

I want to check the time every minute to make alarm app but when I but this in receiver

<action android:name="android.intent.ACTION_TIME_CHANGED"/>
                <action android:name="android.intent.ACTION_TIME_TICK"/>
                <action android:name="android.intent.action.TIME_TICK"/>

and put this in broadcast receiver

@Override
    public void onReceive(Context context, Intent intent)
    {
        Toast.makeText(context,"changed",Toast.LENGTH_LONG)
            .show();

    }

My app don't work or do any thing I searched more and more but nothing was useful I hope someone help me

Zoe
  • 27,060
  • 21
  • 118
  • 148
user11019720
  • 43
  • 1
  • 4

1 Answers1

1

From the way you wrote <action android:name="android.intent.ACTION_TIME_CHANGED"/>, it appears that you're trying to register your BroadcastReceiver in the Manifest.xml.

However, I'll quote this straight from the documentation:

ACTION_TIME_TICK

Broadcast Action: The current time has changed. Sent every minute. You cannot receive this through components declared in manifests, only by explicitly registering for it with Context.registerReceiver().

--https://developer.android.com/reference/android/content/Intent.html#ACTION_TIME_TICK

You can only receive this broadcast by registering the BroadcastReceiver through the registerReceiver() method in either something like your Activity or Service.

However, I do want to mention that you should avoid using this broadcast if your intention is to create an Alarm app.

Constantly fetching the time every minute can become quite battery draining, especially if the alarm takes a while to ring.

Instead, you should consider scheduling your alarm through services like JobScheduler or AlarmManager.

Jackey
  • 3,184
  • 1
  • 11
  • 12