स्क्रीन बंद होने पर (लॉक) होने पर मैं वाईफाई बंद करने की कोशिश कर रहा हूं, और स्क्रीन चालू होने पर इसे फिर से चालू कर सकता हूं (अनलॉक)।ACTION_SCREEN_ON और ACTION_SCREEN_OFF काम नहीं कर रहे हैं?
मैंने BroadcastReceiver
बनाया; इस कोड को प्रकट में डाल:
<receiver android:name="MyIntentReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.SCREEN_OFF" />
<action android:name="android.intent.action.SCREEN_ON" />
<action android:name="android.intent.action.USER_PRESENT" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</receiver>
और इस वर्ग के MyIntentReceiver
है:
package org.androidpeople.boot;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class MyIntentReceiver extends BroadcastReceiver {
// Called when boot completes
public static boolean startup;
@Override
public void onReceive(Context context, Intent intent) {
// Set what activity should launch after boot completes
System.out.println("Intent Action: " + intent.getAction());
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
System.out.println("locked : ACTION_SCREEN_OFF");
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
System.out.println("not locked : ACTION_SCREEN_ON ");
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
System.out.println("User Unlocking it ");
}
else if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
// this to indicate that program is running
// automaticlly not manually by user
startup = true;
System.out.println("Automatic BOOT at StartUp");
Intent startupBootIntent = new Intent(context, LaunchActivity.class);
startupBootIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(startupBootIntent);
}
}
}
और परिणाम है - दोनों ACTION_SCREEN_ON
और ACTION_SCREEN_OFF
निकाल दिया कभी नहीं! USER_PRESENT
और BOOT_COMPLETED
ठीक काम किया लेकिन दूसरा नहीं था। मैं एक एमुलेटर का उपयोग कर रहा हूं, वास्तविक उपकरण नहीं - क्या इससे समस्या हो सकती है?
कोई मदद? बैटरी बचाने के लिए वाईफाई को सक्षम/अक्षम करने के लिए मुझे स्क्रीन को चालू और बंद करने की आवश्यकता है।
अग्रिम धन्यवाद
http://thinkandroid.wordpress.com/2010/01/24/handling-screen-off-and-screen-on-intents/ –