This पृष्ठ पर आप जो खोज रहे हैं उस पर एक ट्यूटोरियल है।
कोड उस पृष्ठ से नकल (क्रम में एक लिंक केवल से चालू करने के लिए सीधे उपयोगी कुछ को जवाब):
1) अपने आवेदन आशय प्राप्त करने के लिए एक कक्षा बनाएं। उदाहरण के लिए, निम्नलिखित रिसीवर अकेला खड़ा है और एक स्थिर चर सेट भाग 2 में प्रयोग की जाने वाली:
2) अपनी गतिविधि को संशोधित/बंद घटनाओं पर स्क्रीन प्राप्त करने के लिए।
public class ExampleActivity extends Activity {
@Override
protected void onCreate() {
// initialize receiver
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
BroadcastReceiver mReceiver = new ScreenReceiver();
registerReceiver(mReceiver, filter);
// your code
}
@Override
protected void onPause() {
// when the screen is about to turn off
if (ScreenReceiver.wasScreenOn) {
// this is the case when onPause() is called by the system due to a screen state change
System.out.println("SCREEN TURNED OFF");
} else {
// this is when onPause() is called when the screen state has not changed
}
super.onPause();
}
@Override
protected void onResume() {
// only when screen turns on
if (!ScreenReceiver.wasScreenOn) {
// this is when onResume() is called due to a screen state change
System.out.println("SCREEN TURNED ON");
} else {
// this is when onResume() is called when the screen state has not changed
}
super.onResume();
}
}
@Yaniv:: अपने रिसीवर अपने प्रसारण रिसीवर में स्थिर चर की जाँच करेगा आशय आप अभी-अभी प्राप्त करने के लिए कारण पता करने के लिए "मैं/अपने आवेदन में पता करने के लिए स्क्रीन बंद जब डिवाइस नींद पर चला जाता है की जरूरत है। " -- क्यूं कर? 99.9 99% एंड्रॉइड अनुप्रयोगों की आवश्यकता नहीं है। ऐसा करने का एकमात्र तरीका कुछ उचित उपयोगकर्ता-विरोधी व्यवहार (उदाहरण के लिए, हमेशा चलने वाली सेवा) मानता है। तो, कृपया बताएं कि आप क्या हासिल करने की कोशिश कर रहे हैं, इसलिए हम एक बेहतर समाधान खोजने में मदद कर सकते हैं। – CommonsWare