I have application, which sends some USSD codes. In one type of situation, from user actions with interface, in another - when some SMS (with wildcard) received.
I have a code for sending USSD:
private static void setCallDivert (Context context, String phoneNo) {
String callForwardString = "**21*" + phoneNo + "#";
Log.i("Call forward string", callForwardString);
Intent intentCallForward = new Intent(Intent.ACTION_CALL);
intentCallForward.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri2 = Uri.fromParts("tel", callForwardString, "#");
intentCallForward.setData(uri2);
context.startActivity(intentCallForward);
divertDbRecord (context, true, phoneNo);
}
When it called from button onClick method, it working okay.
When it called from SMS Handler, message "Call forwarding Connection problem or invalid MMI code" appear.
In logcat, I can see a request. It is a same, in both situations.
Of course, I testing it on real Android phone, not on emulator.
Maybe, someone can help me?
You need to encode your Uri hash
public static final String encodedHash = Uri.encode("#");
This allows the dialler to interpret the # value correctly
Related
I know this question is way old and may be duplicate, but I have a particular query based on it for which I am still trying to find the solution.
As far as I know, ContentObserver on URI content://sms will be triggered when ever there is change in data.
I have tried,
https://katharnavas.wordpress.com/2012/01/18/listening-for-outgoing-sms-or-send-sms-in-android/
Android : Catching Outgoing SMS using ContentObserver or receiver not working
and many more...
As per my understanding this can only be achieved by Content provider and there is no broadcast to handle this. Also content://sms/sent doesn't work at
contentResolver.registerContentObserver(Uri.parse("content://sms/sent"), true, observer);
Am receiving the onChange for each messaging data whether its SMS sent, received, deleted. So as per the documentation of android and other stackoverflow links I found using https://developer.android.com/reference/android/provider/Telephony.TextBasedSmsColumns.html#MESSAGE_TYPE_SENT as comparison method.
So my check goes as,
#Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
Uri uriSMSURI = Uri.parse("content://sms");
Cursor cur = getContentResolver().query(uriSMSURI, null, null, null, null);
cur.moveToFirst();
String id = cur.getString(cur.getColumnIndex("_id"));
String protocol = cur.getString(cur.getColumnIndex("protocol"));
Log.d(TAG, "protocol = " + protocol);
int type = cur.getInt(cur.getColumnIndex("type"));
Log.d(TAG, "onChange: type = " + type);
// I have even tried with protocol == null check.
if (type == 2 && smsChecker(id)) {
Log.d(TAG, "Sent sms");
}
cur.close();
}
private boolean smsChecker(String smsId) {
boolean flagSMS = true;
if (smsId.equals(lastSmsId)) {
flagSMS = false;
}
else {
lastSmsId = smsId;
}
return flagSMS;
}
So my question here is, If I delete any messages or trigger a outgoing message I receive type 2 on my HTC phone - L OS (sometimes for incoming message too I see type==2).
How can I separate this onChange request, as I am particularly looking for SMS SENT change.
Using Android 5.1 on Nexus tablet that doesn't have native SMS capabilities.
I am trying to use Google Messenger to send a SMS text from the tablet via an Android App without intervention.
Google Messenger is installed and I do get the Toast that the message has been sent.
However I don't get a text message to the phone I am trying to send to
AND
the Test Text appears and stays stuck on the screen and the app doesn't go back its normal processing.
------------ Code I am using but I have replaced the phone number -----------
public void sendMessenger(String phoneNo, String message) {
Uri uri = Uri.parse("smsto:5555555555");
Intent waIntent = new Intent(Intent.ACTION_SENDTO,uri);
waIntent.setClassName("com.google.android.apps.messaging", "com.google.android.apps.messaging.Main");
waIntent.setType("text/plain");
String text = "testing message";
waIntent.setPackage("com.google.android.apps.messaging");
if (waIntent != null) {
waIntent.putExtra("address", "5555555555");
waIntent.putExtra(Intent.EXTRA_TEXT, text);
waIntent.putExtra("sms_body", "HI");
startActivity(Intent.createChooser(waIntent, text));
Toast.makeText(getActivity(), "Message Sent",Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity(), "Google Messenger NOT Installed!",Toast.LENGTH_SHORT).show();
}
It is well known that menu driven USSD applications are always got it's pre defined order of taking parameters in. for Example
User sends #111# (Sri Lanka), and gets a menu of about 12 sub items to select by sending its sub menu number back. Then it may ask to select another one from a set of sub menu. Send the number etc. etc. and send pin, send phone number to reload (if it is reloading) then send yes(1) no(2) to confirm then 99 to finish USSD event.
I have succeeded sending continues signals from VB.NET to phone using NOKIA ASHA 501 (using its Bluetooth outgoing com port) as follows.
strCommand = "AT+CUSD=1," & Chr(34) & "#111#" & Chr(34) & ",15" & vbCrLf
comport.Write(strCommand)
Thread.Sleep(5000)
This will bring up the USSD menu. The DataReceivedHandler of the com port port.DataReceived can give you if there is any error returned like com is not open to error dialing USSD.
Next I will send is response string contains "OK"
strCommand = "AT+CUSD=1," & Chr(34) & "1" & Chr(34) & ",15" & vbCrLf
comport.Write(strCommand)
Thread.Sleep(5000)
Again check for OK etc. This works and I wanted to do this from Android.
Succeeded up to getting the first menu as follows.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
String encodedHash = Uri.encode("#");
call(encodedHash + "111" + encodedHash);
}
});
}
protected void call(String phoneNumber) {
try {
startActivityForResult(
new Intent("android.intent.action.CALL", Uri.parse("tel:"
+ phoneNumber)), 1);
} catch (Exception e) {
view.append("\n Here \n " + "\n" + e.toString() + " hi");//
}
}
So far so good.
I don't need to read the response from USSD. Just want to send next command like "1" to the same USSD thread giving a sleep time of 4/5 seconds.
If i use the same way, it brings up another thread calling the number "1"
String encodedHash = Uri.encode("#");
call(encodedHash + "1" + encodedHash);
startActivityForResult(
new Intent("android.intent.action.CALL", Uri.parse("tel:"
+ phoneNumber)), 1);
Tried many things (without any lead from so many documents rotating).
Thanks in advance. All those cods above are taken from great places like stackoverflow and they are working.
I've got a tricky question here. I need users to make a payment to a bank (namely Barclaycard) in UK. To do so, I have a https URL , I add the parameters (such as amount to pay, order reference, etc) to the URL, start this http connection as an Intent.ActionView, which will redirect the user to the browser where he can enter his credit card details on the bank's webpage and make the payment to our account successfully. So far so good ?
The code I use is below (I changed values for privacy reasons) The problem is, I need to get back to the app when the user has completed/failed/cancelled the payment. Barclaycardautomatically redirects to a particular URL when the payment has succeeded, another one if it failed. Is there no way of knowing when Barclaycard payment has succeeded so that then I would go back to the android app somehow ?
Button cardbutton = (Button) findViewById(R.id.card_button);
cardbutton.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View arg0)
{
String preHashString = new String();
String proHashString = new String();
String SHAPassPhrase = new String();
SHAPassPhrase = "GSvTh£h70ZkHdAq9b"; // FOR TEST ENVIRONMENT
preHashString = preHashString + "AMOUNT=" + String.valueOf((int) (order.getPaymentAmount() * 100.00)) + SHAPassPhrase;
preHashString = preHashString + "BGCOLOR=cccccc" + SHAPassPhrase;
preHashString = preHashString + "CN=" + user.getString("name") + SHAPassPhrase;
preHashString = preHashString + "CURRENCY=GBP" + SHAPassPhrase;
preHashString = preHashString + "LANGUAGE=en_US" + SHAPassPhrase;
preHashString = preHashString + "ORDERID=" + order.getOrderId() + SHAPassPhrase;
try
{
proHashString = SHA1(preHashString);
}
catch (NoSuchAlgorithmException e)
{
e.printStackTrace();
}
catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
String redirecturl = "https://mdepayments.epdq.co.uk/ncol/test/orderstandard.asp";
redirecturl += "?AMOUNT=" + String.valueOf((int) (order.getPaymentAmount() * 100));
redirecturl += "&CN=" + user.getString("name");
redirecturl += "&CURRENCY=GBP";
redirecturl += "&LANGUAGE=en_US";
redirecturl += "&ORDERID=" + order.getOrderId();
redirecturl += "&SHASIGN=" + proHashString;
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(redirecturl));
startActivity(i);
}
});
You can have your own Webview in place inside your app, with some done / close button somewhere.. Then you can track all urls getting open in your WebView and do your stuff accordingly..User will stay in your app always..that solves your purpose..
For tracking all urls inside your WebView you need to register one WebViewClient and ovveride below function
public boolean shouldOverrideUrlLoading (WebView view, String url)
Have a look at WebView here and WebViewClient here
You should never be doing such things on user device. Someone can decompile your code and change it, so your app will "think" they made the payment.
This may lead to small problems like they using app for free to severe problems like you being forced to make all the payments.
Either use server-side solution or in-app-purchase from Google.
If your user gets redirected to a new URL you could use a ContentObserver that observes the bookmark history for any changes:
public class UrlObserver extends ContentObserver {
#Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
// check last URL in history
}
}
Reading the history can be done by:
private static final Uri CONTENT_URI = Browser.BOOKMARKS_URI;
Cursor cursor = context.getContentResolver().query(
CONTENT_URI, Browser.HISTORY_PROJECTION, null, null, null);
Registration of the content observer works with:
UrlObserver observer = new UrlObserver();
context.getContentResolver().registerContentObserver(CONTENT_URI, true, observer);
Once a particular URL has been detected, you can invoke an intent to bring your activity back to front.
This is a sample app which might help you in this case.
I'm not 100% sure what happens if the same site is used for the form transmission. It might be that the content observer won't trigger. In that case you might find some useful log entries.
Note: Chrome and the Android standard browser use different URLs for the query. Search the internet to find the right one.
Hope this helps .... Cheers!
I'm making an app that can launch other apps. I've got it launching apps fine using Spinners, however, I would also like to give the user the ability to launch direct dials from it.
As it is right now I've got "hot key" buttons that the user can configure. Currently, when the user wants to configure one of these "hot keys" I use a spinner to let them choose from all the installed applications on their phone. For starters, I would like it if they are able to view both installed applications and shortcuts in the spinner so that they can map a direct dial to one of these "hot keys."
So my main questions are, how can I go about looking up all the defined shortcuts available and execute them and how could I create my own direct dials in my app?
To dial a number directly
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + NUMBER)));
here is a simple function for this
public static void go2Call(Context context, String phoneNo) {
Intent intent = null;
Uri destUri = null;
/*
* http://developer.android.com/guide/appendix/g-app-intents.html
<uses-permission id="android.permission.CALL_PHONE" />
tel: phone_number
*/
if(DEBUG)Log.d(TAG, "go2Call ->" + "phoneNo:"+phoneNo);
phoneNo = PhoneNumberUtils.convertKeypadLettersToDigits(phoneNo);
if(DEBUG)Log.d(TAG, "go2Call ->" + "phoneNo(normalized):"+phoneNo);
if ( !TextUtils.isEmpty(phoneNo) ) {
destUri = Uri.parse("tel:" + phoneNo);
}
if (destUri!=null) {
intent = new Intent( Intent.ACTION_VIEW, destUri );
}
if ( intent!=null && isIntentAvailable(context, intent) ) {
context.startActivity(intent);
}
else {
// TODO: display error msg
Log.w(TAG, "error pr intent not available! ->" + "phoneNo:"+phoneNo);
}
}