RTC_WAKEUP not working

I am currently working on a Broadcast Receiver application in which I set an alarm that should display a message after entering seconds. I used RTC_WAKEUP, which means that it should display a message when the device is turned on, and it is supposed to turn on the device, and then display a message when the device is turned off. MY PROBLEM IS THAT THIS RTC_WAKEUP IS NOT ON MY DEVICE, but it works correctly when the device is turned on. I am embedding my application code. There are two classes in my application.

Mainactivity

public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void startAlert(View view) { EditText text = (EditText) findViewById(R.id.time); int i = Integer.parseInt(text.getText().toString()); Intent intent = new Intent(this, MyBroadcastReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 23432424, intent, 0); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (i * 1000), pendingIntent); Toast.makeText(this, "Alarm set in " + i + " seconds", Toast.LENGTH_LONG).show(); } } 

other

MyBroadcastReceiver

  public class MyBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Toast.makeText(context, "Jaago Mohan Pyarreee!!!!.", Toast.LENGTH_LONG).show(); } } 

manifest

 <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.broadcastreceiver" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" /> <uses-permission android:name="android.permission.VIBRATE"/> <uses-permission android:name="android.permission.WAKE_LOCK" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/title_activity_main" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name=".MyBroadcastReceiver" > </receiver> </application> </manifest> 
+6
source share
4 answers

RTC_WAKEUP will not turn on the screen, everything that it does wakes up from the processor so that your work is done. To turn on the screen, you will need a FULL wakelock.

 PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "wakeup"); wl.acquire(); // ... do work... //show toask wl.release(); 
+2
source

Do you have permission in your manifest?

 <uses-permission android:name="android.permission.WAKE_LOCK" /> 
+1
source

Correct your manifest. Instead

 <receiver android:name="MyBroadcastReceiver" > 

you need:

 <receiver android:name=".MyBroadcastReceiver" > 
0
source

Checked Google DesktopClock app: com.android.deskclock.alarms.AlarmStateManager (this is BroadcastReceiver)

In its onReceive function, goAsync () is used:

 @Override public void onReceive(final Context context, final Intent intent) { final PendingResult result = goAsync(); final PowerManager.WakeLock wl = AlarmAlertWakeLock.createPartialWakeLock(context); wl.acquire(); AsyncHandler.post(new Runnable() { @Override public void run() { handleIntent(context, intent); result.finish(); wl.release(); } }); } 

You must take a picture with this.

0
source

All Articles