I am trying to learn android on my own, and currently working on a simple project.
I want to receive whenever the phone is plugged to a power source, so I put a receiver to the manifest and create a subclass under my main activity. The problem is the program crashes when I plug the phone.
There are many questions about it here and everywhere else, and believe me I looked all of them but none of them solved this problem.
MainActivity.java
public class MySystemBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "ACTION_POWER_CONNECTED event received", Toast.LENGTH_LONG).show();
}
}
Manifest:
<receiver
android:name="deneme.sarjolcer.MainActivity$MySystemBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
</intent-filter>
</receiver>
Please forgive me if there is a too silly error, I am just new at this thing. I have been working over the same error for a week now and actually do not see straight now. Thank you very much.