Reputation: 4332
I am not sure if this question appropriate as I new to Android. I am thinking to solve a problem such that when I am driving I want my Android to Auto send or Auto reply any incoming SMS. Would appreciate if you can guide me or provide me some tutorial or code on this. Can this task be accomplished in Android? Thanks.
Upvotes: 0
Views: 2819
Reputation: 230
sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
int hasSMSPermission = checkSelfPermission(SEND_SMS);
if (hasSMSPermission != PackageManager.PERMISSION_GRANTED) {
if (!shouldShowRequestPermissionRationale(SEND_SMS)) {
showMessageOKCancel("You need to allow access to Send SMS",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[] {SEND_SMS},
REQUEST_SMS);
}
}
});
return;
}
requestPermissions(new String[] {SEND_SMS},
REQUEST_SMS);
return;
}
sendMySMS();
}
}
});
sendButton.performClick();
just add "sendButton.performClick()" after the listener. I tried it.
Upvotes: 0
Reputation: 230
sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
int hasSMSPermission = checkSelfPermission(SEND_SMS);
if (hasSMSPermission != PackageManager.PERMISSION_GRANTED) {
if (!shouldShowRequestPermissionRationale(SEND_SMS)) {
showMessageOKCancel("You need to allow access to Send SMS",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[] {SEND_SMS},
REQUEST_SMS);
}
}
});
return;
}
requestPermissions(new String[] {SEND_SMS},
REQUEST_SMS);
return;
}
sendMySMS();
}
}
});
sendButton.performClick();
Upvotes: 0
Reputation: 69
https://developer.android.com/guide/topics/ui/accessibility/index.html
With the accessibility service in android you can get the current screen and can make the system to click buttons or send SMS automatically for you.
It can get the current screen and click into SMS, get the text box and set text, and click the send button at the end.
https://github.com/PrivacyStreams/PrivacyStreams
You can add this build.gradle into your project and get the text box with just a few lines.
Upvotes: 0
Reputation: 699
You can use this for sending message, but for this first you need to set permission in android menifest file
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNumber, null,, smsText, null, null);
See this tutorial for incoming messages or calls: Android BroadcastReceiver Tutorial
Upvotes: 0
Reputation: 216
You could use the Google Cloud Messaging (GCM) service, and each time you get an incoming message get a reply from the server. Each time you get a reply from the GCM server with the broadcastevevent you could send a auto reply.
Upvotes: 1