Android app that opens inbox SMS - android

I am using an SMS manager in my app, so when a button is clicked, an SMS is sent,
btnPaket.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
String phoneNo = "0977";
String message = "stanje";
sendSMS(phoneNo, message);
Toast.makeText(getBaseContext(), "Zahtjev za provjeru stanja paketa je poslan, odgovor ocekuj uskoro!", Toast.LENGTH_SHORT).show();
}
});
So when I click on the button, the SMS is sent, and I get an automated response with the state of my SMS, and Internet packets. Is there any way such that a received SMS is automatically opened and shown to the user, without leaving the application, and going to the inbox, or the notifications bar?

I don't think Android allows you to directly open/read text messages (for extremely obvious reasons...), however, you might be able to just launch the SMS inbox from your application.
Reference here to how to launch activities.
EDIT:
This person apparently found out how to open the sms inbox, check his second post.

Related

How to handle error situations when Broadcast is not triggered due to unfulfilled message criteria in case of SMS User Consent API?

In the following docs:
https://developers.google.com/identity/sms-retriever/user-consent/request
it is stated a message triggers the broadcast only if it meets these criteria:
The message contains a 4-10 character alphanumeric string with at
least one number.
The message was sent by a phone number that's not
in the user's contacts.
If you specified the sender's phone number,
the message was sent by that number.
However it's not mentioned how to deal with the situation when any of the above criteria is not met and broadcast is not triggered. How do we conduct this to the end-user?
I am able to handle success and timeout cases and handling this situation would make the code more user-friendly.
switch (smsRetrieverStatus.getStatusCode()) {
case CommonStatusCodes.SUCCESS:
// Get consent intent
Intent consentIntent = extras.getParcelable(SmsRetriever.EXTRA_CONSENT_INTENT);
try {
// Start activity to show consent dialog to user, activity must be started in
// 5 minutes, otherwise you'll receive another TIMEOUT intent
startActivityForResult(consentIntent, SMS_CONSENT_REQUEST);
} catch (ActivityNotFoundException e) {
Log.d("Exception","ActivityNotFound");// Handle the exception ...
}
break;
case CommonStatusCodes.TIMEOUT:
Log.e("Timeout-Error:","Listened for msg for 5minutes");
break;
}
You could try using CommonStatusCodes.ERROR but I am not sure if this would get triggered when the SMS received is specifically invalid.
One user-friendly solution may be: setting a timer of 30 seconds for example that starts as soon as you request the SMS/OTP. When the countdown is done, you display a "RESEND SMS" button. So in case the SMS was not received/retrieved, you have a more-user friendly way of letting the user retry and request another SMS.

Unable to update Notifications Hub Categories

I'm having a hard time updating the categories a user is subscribed to recibe push notifications. Here is my scenario:
Every time the app starts, I'm registering the app for notifications as suggested here by Microsoft using the user preferences stored in the local DB, if the user is not subscribed to any category, I send an empty string array:
try
{
regid = _gcm.register(_senderId);
_hub.register(regid, categories.toArray(new String[categories.size()]));
}
After that, I can see the response back from the server without any problem:
protected void onPostExecute(Object result)
{
String message = "No alert configured";
if(categories.size() > 0)
{
message = "Configured alerts: " + categories.toString();
}
Toast.makeText(_context, message, Toast.LENGTH_LONG).show();
}
But even after that, the device keeps getting push notifications for categories that have been un-subscribed from.
I'm using the same Notification Hub (.net Backend) with the same app in iOS and Android, but this problem only occurs in Android.
Any ideas/suggestions?

WebDialog.RequestsDialogBuilder does not actually send a request?

I am working on an app, which sends a request to the selected user. Am selecting the user through FriendPickerFragment(Android.Support.V4.App). I am successfully getting the list of friends I have selected on the "Done" button of the Picker fragment. Post that, I am trying to build a request dialog, which should not show up in my app, but should send the FB request to the selected friends. Here is my code:
Bundle bundle = new Bundle ();
bundle.PutString ("app_id", AppID);
var dialog = new WebDialog.RequestsDialogBuilder (this.Activity, Session.ActiveSession, bundle).SetMessage(user + " has invited you to join my application");
dialog.Build ();
The problem I am facing is that, the request is not actually sent. There is no exception either. I even implemented the call back:
public void OnComplete(Bundle bundle, FacebookException e)
but the execution does NOT go in the callback. What am I missing here ? Any help would be greatly appreciated.
Tried dialog.SetTo(userId) before build also....still not working...
Any suggestions ?
Well, according to the documentation for RequestDialogBuilder the method public WebDialog build(), the behavior you describe is by design. Quote:
"The dialog is not shown, but is ready to be shown by calling Dialog.show()"
It sounds like you do not want to show a dialog, but just want to send a request without any UI. You are using the wrong tool to do that. To send a request using a dialog, you have to show the dialog, and the user action is what causes a request to be sent. This doesn't require any special permission to be granted ahead of time, because it only sends a request if the user chooses to after your app opens the dialog.
There may or may not be a way to do what you want (send an app request without any user interaction) ... if there is a way, it will be along these lines:
use the Graph API, get a token with some permission that the user grants to your app. Here's a place to start looking:
https://developers.facebook.com/docs/graph-api/reference/v2.1/user/apprequests/

Google Hangouts breaks SMS order

I've got an app that sends a text message as a response after receiving a text message. (Auto Respond) When SMS is enabled in hangouts, my app wasn't sending its messages. I fixed that by doing this:
<intent-filter android:priority="500">
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
After sending the message, my app also writes that sent message to the user's SMS log (inbox/outbox displayed by messaging apps.)
But now that my SMS receiver is higher priority than Hangouts, the sent message is written to the user's SMS log AFTER the received message when it should be the other way around.
So it shows like this:
Response Message
Received Message - this is what triggered the response
But it should be:
Received Message - triggers response
Response Message
Is there a way for me to wait for the received message to be written before writing the response message? It works fine when SMS is disabled in Hangouts. But since Hangouts is now writing that message instead of the default SMS receiver, it messes things up like crazy.
EDIT: Thanks to Keith's response, this is the code that worked for me:
context.getContentResolver().registerContentObserver(
Uri.parse("content://sms"),
true,
smsObserver);
And this class:
private class SMSObserver extends ContentObserver
{
public SMSObserver()
{
super(null);
}
#Override
public boolean deliverSelfNotifications() {
return true;
}
#Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
if(!selfChange)
//sendResponse
context.getContentResolver().unregisterContentObserver(this);
}
#Override
public void onChange(boolean selfChange, Uri uri) {
super.onChange(selfChange, uri);
if(!selfChange)
//sendResponse
context.getContentResolver().unregisterContentObserver(this);
}
}
I'm not sure if the self change part is necessary, but it works so I'm not changing it.
Try a ContentObserver on the SMS database to listen for when Hangouts writes to the SMS content provider. This approach should be compatible with 4.4/Hangouts as well as earlier versions; you'd just wait until something is written to write your sent message.
Tested two different versions on Android 4.3, Galaxy Nexus:
context.getContentResolver().registerContentObserver(Uri.parse("content://sms"), true, myContentObserver);
or
cursor = context.getContentResolver().query(Uri.parse("content://sms/inbox"),
new String[] { SMS_ID, SMS_ADDRESS, SMS_READ },
"read = 0",
null,
null);
cursor.registerContentObserver(myContentObserver);
But I couldn't use the non-Cursor version with sms/inbox for some reason. The downside of the Cursor-based version is that it seems to need to stay open so then you have to be sure to close it later.
Also, neither version is being called when the read status changes.

Outbox message not being sent

In my app I want to keep track on sms sending. In case of sms does not sent due to network failure(No signal).
I managed to put sms in outbox :
private void putoutbox(String addr,String msg) {
// TODO Auto-generated method stub
ContentValues values = new ContentValues();
values.put("address", addr);
values.put("body", msg);
getContentResolver().insert(Uri.parse("content://sms/Outbox"), values);
}
sms is being shown in default message folder with status sending
but sms never sent
I also tried
content://sms/failed
and it also does not send sms.
Please tell me what I am missing.
Thank you all for helping me
as st0le gives a very useful link here one must have to provide all seven attribute
unfortunately i can not show the code for that,but it will work if you restart your phone

Categories

Resources