1

如果没有人打电话,一切都会好起来的。如果我使用 Opera、Gmail 或其他应用程序,那就没问题了。并及时目标警报意图启动。

Intent i2 = new Intent();
i2.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP  | Intent.FLAG_ACTIVITY_SINGLE_TOP);
pIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, i2, 0);

curtimeset = System.currentTimeMillis();
am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, curtimeset + full, pIntent); //full time in mills when alarm will be on even from lock mode

当计时器开始和当前时间等于目标时间时。应用启动意图。从前台加载它。

public void instanceinitiale() {
    Intent resumeIntent = new Intent(getApplicationContext(), Main.class);
    resumeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
            | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    startActivity(resumeIntent);

}

在任何情况下如何加载我的警报?)

4

1 回答 1

0

当需要报警时,系统会调用您的应用程序。系统将向您发送相同的意图(您在创建警报时使用)。如果您在创建数据时放置数据,则可以获取它

public class AlarmService extends BroadcastReceiver {

private final static String action="android.intent.action.ALARMHANDLERACTIVITY";
public AlarmService(){
}

@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    if(intent.getAction().compareTo(action)==0){
        context.startActivity(intent);
    }
}




public void createAlarm(){
    Intent intent=new Intent("android.intent.action.ALARMHANDLERACTIVITY");
    intent.putExtra("eventID", Integer.valueOf(id));

    PendingIntent pendingIntent=PendingIntent.getActivity(context, 0, intent,0);
    AlarmManager aManager=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);


    aManager.set(AlarmManager.RTC_WAKEUP, temp.getStartDate().getTimeInMillis(), pendingIntent);
}

}

要定义您的接收器,请将其写入清单的应用程序块:

    <receiver android:name=".alarmService.AlarmService">
        <intent-filter android:priority="200">
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
        </intent-filter>
    </receiver> 
于 2013-04-22T15:46:07.870 回答