每天修复时间,应在Android中显示Toast消息

时间:2016-11-23 05:50:54

标签: android service

我想要一个简单的干杯消息" Helloo everyone"每天上午11:30显示。为此,我有两个类MainActivity和AlarmReceiver     我尝试了很多解决方案,但未找到答案。     请帮帮我。

代码: -

public class AlarmReceiver extends BroadcastReceiver {
    int MID = 0;
    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub


            // For our recurring task, we'll just display a message
            Toast.makeText(context, "Hello everyone", Toast.LENGTH_SHORT).show();

        }

    }

AlarmReceiver.java

<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
    <receiver android:name="com.example.alarmmanagernotifcation.AlarmReceiver"/>
    <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">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <receiver android:name=".AlarmReceiver"></receiver>
    </application>

Mainfest

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

driver = webdriver.Chrome()
driver.maximize_window()
driver.get('http://www.espn.com/mens-college-basketball/scoreboard/_/date/20161122')

el2=driver.find_element_by_xpath("//header[@class='automated-header']//button[.='Top 25']")
action = ActionChains(driver)
action.move_to_element(el2).click().perform()

driver.find_element_by_link_text('NCAA Division I').click()

1 个答案:

答案 0 :(得分:0)

像这样制作你的闹钟。

Calendar calendar = Calendar.getInstance();
 calendar.set(Calendar.HOUR_OF_DAY, 18);
 calendar.set(Calendar.MINUTE, 30);
 calendar.set(Calendar.SECOND, 0);
 Intent intent1 = new Intent(MainActivity.this, AlarmReceiver.class);
 PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0,intent1, PendingIntent.FLAG_UPDATE_CURRENT);
 AlarmManager am = (AlarmManager) MainActivity.this.getSystemService(MainActivity.this.ALARM_SERVICE);
 am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);

显示权限。

 <uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
 <receiver android:name="com.example.alarmmanagernotifcation.AlarmReceiver"/> 

enter image description here