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"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>


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


  </intent-filter>
</receiver>
    </application>

The main Java file

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

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        }
    }

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{

    @Override
    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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.