RTC_WAKEUP不工作 [英] RTC_WAKEUP is not working

查看:1577
本文介绍了RTC_WAKEUP不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我工作的一个广播接收器的应用程序,其中我提出后,我们进入秒,这应该显示一个消息报警。我用RTC_WAKEUP,这意味着它应该显示该消息时,该设备上,它应该是打开设备,然后显示该消息时,该设备处于关闭状态。我的问题是,它RTC_WAKEUP却不包含在我的设备,但它正常工作时,设备处于开启状态。我贴我的应用程序的code。在我的应用程序有两班。

MainActivity

 公共类MainActivity延伸活动{


    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);
    }

    公共无效startAlert(查看视图){
        文字的EditText =(EditText上)findViewById(R.id.time);
        INT I =的Integer.parseInt(text.getText()的toString());
        意向意图=新的意图(这一点,MyBroadcastReceiver.class);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(),23432424,意向,0);
        AlarmManager alarmManager =(AlarmManager)getSystemService(ALARM_SERVICE);
        alarmManager.set(AlarmManager.RTC_WAKEUP,System.currentTimeMillis的()
                +(I * 1000),pendingIntent);
        Toast.makeText(这一点,报警设置在+ I +秒,
                Toast.LENGTH_LONG).show();
    }
}
 

和另一种是

MyBroadcastReceiver

 公共类MyBroadcastReceiver扩展的BroadcastReceiver {
      @覆盖
      公共无效的onReceive(上下文的背景下,意图意图){
        Toast.makeText(背景下,Jaago磨憨Pyarreee !!!!
            Toast.LENGTH_LONG).show();
      }
    }
 

清单

 <舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=com.example.broadcastreceiver
    安卓版code =1
    机器人:VERSIONNAME =1.0>

    <用途-SDK
        安卓的minSdkVersion =8
        机器人:targetSdkVersion =15/>
    <使用-权限的Andr​​oid:名称=android.permission.VIBRATE/>
    <使用-权限的Andr​​oid:名称=android.permission.WAKE_LOCK/>

    <应用
        机器人:图标=@可绘制/ ic_launcher
        机器人:标签=@字符串/ APP_NAME
        机器人:主题=@风格/ AppTheme>
        <活动
            机器人:名称=。MainActivity
            机器人:标签=@字符串/ title_activity_main>
            <意向滤光器>
                <作用机器人:名称=android.intent.action.MAIN/>

                <类机器人:名称=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
        < /活性GT;
         <接收机器人:MyBroadcastReceiverNAME =>
        < /接收器>
    < /用途>

< /舱单>
 

解决方案

RTC_WAKEUP不会在屏幕上的开关,它的作用是唤醒你的CPU,这样你的工作就完成了。对于屏幕被打开,您需要获取一个完整wakelock。

  PowerManager的PM =(电源管理器)mContext.getSystemService(Context.POWER_SERVICE);
 PowerManager.WakeLock WL = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK
                                      | PowerManager.ON_AFTER_RELEASE,
                                      起床);
 wl.acquire();
 // ... 做工作...
//显示toask
 wl.release();
 

Currently i am working on a Broadcast Receiver application, in which i am making an Alarm which should display a message after we enter the seconds. I used RTC_WAKEUP, which means it should display the message when the device is on and it is supposed to turn on the device and then display the message when the device is off. MY PROBLEM IS THAT IT RTC_WAKEUP DOESN'T ON MY DEVICE but it is working properly when device is on. i am pasting the code of my application. In my application there are two classes.

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();
    }
}

and other is

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>

解决方案

RTC_WAKEUP will not switch on the screen, all it does is wakes up thee cpu so that your job is done. For the Screen to be turned on you need a FULL wakelock to be acquired.

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();

这篇关于RTC_WAKEUP不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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