报警管理器执行方法

时间:2018-06-18 06:35:32

标签: java android xml

这是我从google和youtube结合在一起的代码的一部分,用于执行" turnOnLed"当闹钟响起时。由于某种原因,它没有执行,我不知道如何使它工作。有人可以帮忙吗?我是谷歌,但没有成功。

谢谢。

 private void startAlarm(Calendar c)
    {
      AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    if (c.before(Calendar.getInstance()));
    {
    c.add(Calendar.DATE, 1);
    }

    Intent intent = new Intent(this, Control.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this,0,intent, 0);
    alarmManager.set(AlarmManager.RTC_WAKEUP,c.getTimeInMillis(), pendingIntent);

    }

public class Control extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) 
    {
     turnOnLed(); //method to turn on
    }
}

Manifest.xml文件:

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>



<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <activity
        android:name="art.control4.IntroScreen"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="art.control4.DeviceList"
        android:label="@string/app_name">
    </activity>
    <activity
        android:name="art.control4.ledControl"
        android:label="@string/app_name">
    </activity>
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
    </activity>

    <receiver android:name=".ledControl$Control"
     android:process=":remote"/>

0 个答案:

没有答案