954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Display toast on Android broadcast when screen is on.

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.

codegerm
Newbie Poster
2 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: