Register the Broadcast Receiver in the AndroidManifest.xml. This receiver broadcast when screen went ON. This execute either your application activity is on screen or not.
AndroidManifest.xml
<receiver android:name=".MyBroadCastReciever">
<intent-filter>
<action android:name="android.intent.action.SCREEN_ON"/>
</intent-filter>
</receiver>
MyBroadCastReciever.java
public class MyBroadCastReciever extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
Log.i("Check","Screen went ON");
Toast.makeText(context, "screen ON",Toast.LENGTH_LONG).show();
// Here you can write the logic of send SMS, Email, Make a call
}
}
}
Update
Logic to make the call
You can do this simply. It make the call directly.
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "Your Phone_number"));
startActivity(callIntent);
and add this permission in AndroidManifest.xml
<uses-permission android:name="android.permission.CALL_PHONE" />
Logic to send the SMS
You can do this simply. This send the SMS
public void sendSMS() {
String phoneNumber = "0123456789";
String message = "Hello World!";
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNumber, null, message, null, null);
}
and add this permission in AndroidManifest.xml
<uses-permission android:name="android.permission.SEND_SMS" />
Logic to send the Email
If you want to send the Email here without any user interaction on id then either design the PHP web service and call the web service in the android application.
If you want to send the mail from the configured email then you can use the Intent
.
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{"youremail@yahoo.com"});
email.putExtra(Intent.EXTRA_SUBJECT, "subject");
email.putExtra(Intent.EXTRA_TEXT, "message");
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Choose an Email client :"));
Note : If you want to perform this action in Activity then register the broadcast receiver in the Activity and unregister when activity destroy.