codegerm 0 Newbie Poster

Im trying to do a simple broadcast in Android to detect the screen is on. For me this is a learning excersize to understand the Android broadcast capabilities. Please help. I have the Android XML

<application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".UsbddActivity"
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />


    <receiver android:name=".BootReceiver">
            <action android:name="android.intent.action.SCREEN_ON"></action> 


The main Java file

package usb.usbd;
import android.os.Bundle;
public class UsbddActivity extends Activity {

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

The Broadcast class That supposed to display the toast.

package usb.usbd;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class BootReceiver extends BroadcastReceiver{

    public void onReceive(Context arg0, Intent arg1) {

        Toast.makeText( arg0, "worked", Toast.LENGTH_LONG).show();
        run(arg0 );

    public void run(Context arg0 ) { 
          Toast.makeText(arg0, "sss", Toast.LENGTH_SHORT).show(); 


It doesnt dislay any errors nor does it display the toast. How can i get the toast to display when the screen is turned on.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.