if (checkPermission()) {
btn1.setEnabled(true);
} else
{
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.SEND_SMS}, SEND_SMS_PERMISSION_REQ);
}
btn1.setOnLongClickListener(this);
btn2.setOnLongClickListener(this);
btn3.setOnLongClickListener(this);
btn4.setOnLongClickListener(this);
btnState.setOnLongClickListener(this);
btnVanne.setOnLongClickListener(this);
}
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(messageReceiver);
}
public void login(View view) {
}
class MessageReceiver extends BroadcastReceiver {
public static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";
private static final String SMS_SENDER = "0000000000000";
@override
public void onReceive(Context context, Intent intent) {
if (intent != null && intent.getAction() != null &&
ACTION.compareToIgnoreCase(intent.getAction()) == 0) {
Object[] pduArray = (Object[]) intent.getExtras().get("pdus");
SmsMessage[] messages = new SmsMessage[pduArray.length];
for (int i = 0; i < pduArray.length; i++) {
messages = SmsMessage.createFromPdu((byte[]) pduArray);
}
String sms_from = messages[0].getDisplayOriginatingAddress();
if (sms_from.equals(SMS_SENDER)) {
StringBuilder bodyText = new StringBuilder();
for (SmsMessage message : messages) {
bodyText.append(message.getMessageBody());
}
String body = bodyText.toString();
ReceivedSms.setText(body);
abortBroadcast();
}
}
}
}
private boolean checkPermission() {
return false;
}
btn1.setEnabled(true);
} else
{
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.SEND_SMS}, SEND_SMS_PERMISSION_REQ);
}
btn1.setOnLongClickListener(this);
btn2.setOnLongClickListener(this);
btn3.setOnLongClickListener(this);
btn4.setOnLongClickListener(this);
btnState.setOnLongClickListener(this);
btnVanne.setOnLongClickListener(this);
}
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(messageReceiver);
}
public void login(View view) {
}
class MessageReceiver extends BroadcastReceiver {
public static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";
private static final String SMS_SENDER = "0000000000000";
@override
public void onReceive(Context context, Intent intent) {
if (intent != null && intent.getAction() != null &&
ACTION.compareToIgnoreCase(intent.getAction()) == 0) {
Object[] pduArray = (Object[]) intent.getExtras().get("pdus");
SmsMessage[] messages = new SmsMessage[pduArray.length];
for (int i = 0; i < pduArray.length; i++) {
messages = SmsMessage.createFromPdu((byte[]) pduArray);
}
String sms_from = messages[0].getDisplayOriginatingAddress();
if (sms_from.equals(SMS_SENDER)) {
StringBuilder bodyText = new StringBuilder();
for (SmsMessage message : messages) {
bodyText.append(message.getMessageBody());
}
String body = bodyText.toString();
ReceivedSms.setText(body);
abortBroadcast();
}
}
}
}
private boolean checkPermission() {
return false;
}
Last edited: