मैं ब्रॉडकास्ट रिसीवर का उपयोग करने की कोशिश कर रहा हूं लेकिन यह काम नहीं कर रहा है, कृपया इस समस्या को हल करने में मेरी सहायता करें। काम नहीं कर रहा MyReceiver.javaस्क्रीन पर चालू/बंद करने के लिए ब्रॉडकास्ट रिसीवर
package com.example.broadcast_receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Log.i("[BroadcastReceiver]", "MyReceiver");
if(intent.getAction().equals(Intent.ACTION_SCREEN_ON)){
Log.i("[BroadcastReceiver]", "Screen ON");
}
else if(intent.getAction().equals(Intent.ACTION_SCREEN_OFF)){
Log.i("[BroadcastReceiver]", "Screen OFF");
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.broadcast_receiver"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<receiver android:name=".MyReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.SCREEN_ON"/>
<action android:name="android.intent.action.SCREEN_OFF"/>
</intent-filter>
</receiver>
<activity
android:name="com.example.broadcast_receiver.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
BroadcastReceiver और नहीं किसी भी लॉग बनाने, कृपया मुझे इस समस्या को हल करने के लिए मदद करते हैं।
जांचें http://stackoverflow.com/a/9478013/1777090 –
कृपया Regitser को किसी अन्य सेवा का उपयोग करें। संदेश प्राप्त या आने वाली कॉल। कृपया लॉग जांचें। –
यह जांचें कि यह आपके लिए पूरी तरह से मदद कर सकता है http://stackoverflow.com/questions/9477922/android-broadcast-receiver-for-screen-on-and-screen-off – nilkash