विकसित करें मैं एक अलार्म एप्लिकेशन विकसित करना चाहता हूं। आवेदन इस तरह काम करना चाहिए:अलार्म एप्लिकेशन
- लांच यह
- गतिविधि मुझे समय
- मैं अलार्म
- मैं आवेदन
- जब अलार्म समय आता है बंद कर सकते हैं सेट कर सकते हैं दिखाने के लिए, यह एक गतिविधि शुरू करता है (भले ही डिवाइस लॉक हो)
मैंने इस नमूना https://github.com/commonsguy/cwac-wakeful को अनुकूलित करने का प्रयास किया है लेकिन मैं अलार्म समय आने पर एक गतिविधि लॉन्च नहीं कर सकता है।
मैं (परीक्षण के लिए मैं गतिविधि का एक onCreate
विधि पर इस कोड डाला है) अलार्म स्थापना के लिए इस कोड का उपयोग:
public class OnAlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.i(ClockActivity.LOG_TAG, "OnAlarmReceiver::onReceive");
WakefulIntentService.sendWakefulWork(context, AlarmService.class);
}
}
यह है:
Intent intent = new Intent(this, OnAlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
Calendar cal = Calendar.getInstance();
cal.add(Calendar.SECOND, 10);
AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, cal.getTimeInMillis(),
pendingIntent);
इस OnAlarmReceiver वर्ग है सेवा वर्ग:
public class AlarmService extends WakefulIntentService {
public AlarmService(String name) {
super(name);
}
@Override
protected void doWakefulWork(Intent intent) {
Log.i(ClockActivity.LOG_TAG, "AlarmService::doWakefulWork");
Intent newIntent = new Intent(getApplicationContext(), ClockActivity.class);
newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
newIntent.setAction(ClockActivity.ALARM_ACTION);
getApplicationContext().startActivity(newIntent);
}
}
यह घोषणापत्र का हिस्सा है जहां सेतु पी सेवा और रिसीवर:
<receiver android:name=".OnAlarmReceiver"></receiver>
<service android:name=".AlarmService"></service>
doWakefulWork विधि कभी नहीं कहा जाता है!
पोस्ट अपने कोड, खासकर जहां आप अपनी गतिविधि का शुभारंभ, और यह भी किसी भी त्रुटि है कि आपके हो रही रिपोर्ट करने के लिए प्रयास करें ... कि मदद करेंगे हम आपकी मदद करते हैं। – st0le
स्क्रीन चालू होने पर यह काम करता है? मैं सिर्फ यह पता लगाने की कोशिश कर रहा हूं कि क्या समस्या वेक लॉक – Andrew
से संबंधित है @PayPal_Tim ने "उत्तर" में पूछा (यहां कोई टिप्पणी जोड़ने के बजाय) 'Log.i (ClockActivity.LOG_TAG, "OnAlarmReceiver :: onReceive"); 'रन? –