android programming based on message - android

I am developing an android application, which has to respond to a certain SMS message.
The message must be as follows:
It must come from a particular number, already known to the application.
It must contain a certain code as the text.
If both of these are satisfied, then the code in the SMS should be displayed inside a particular button object in the application.
Can anyone please help me do this? I just need to get the way to do this.

The following article describes sending and receiving SMS with Android: http://mobiforge.com/developing/story/sms-messaging-android

First of all, there's no official API to work with SMS, but still there's some way around that (though you don't have ANY guarantee it will work on all vendor's devices).
See the link presented by #Stefan to understand how you can intercept SMSes.
Than you need to parse the number (getOriginatingAddress()). If that satisfies your criteria, parse the SMS body for your code-word (getMessageBody().toString()).
Latest, if all criteria are met, you have to acquire reference to your button object (findViewById(R.id.) and change the text using setText("your text").
Consider having the button positioned in your layout with visibility attribute set to "invisible" and when you set the text, change the visibility attribute to "visible" (not sure if you need it like this).

Related

Android autofill: dispatchProvideAutofillStructure() not laid out

I have configured my app to support Android Oreo with compileSdkVersion 26. I've also set up android:autofillHints="phone" for my phone number input field. When I tap on the field, I can see "Autofill" popping up. However, when I tap on "Autofill", "Contents can't be autofilled" toast appears and I see the following trace in logcat:
RemoteFillService Not handling { when=-3ms what=3 target=com.android.internal.os.HandlerCaller$MyHandler } as service for ComponentInfo{com.google.android.gms/com.google.android.gms.autofill.service.AutofillService} is already destroyed
View dispatchProvideAutofillStructure(): not laid out, ignoring
How should I fix this? I've confirmed that I have the phone number configured in Settings > System > Languages & input > Advanced > Input assistance > Autofill service.
UPDATE with a sample XML: In API 26 emulator settings, I can select "Autofill with Google". Using the Design tab of Android Studio, I added a "Phone" type EditText, and then manually inserted android:autofillHints="phone" in the XML element:
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="phone"
android:autofillHints="phone" />
Logcat peculiarities described above can be observed using this XML.
I'm the Android Frameworks engineer leading the Autofill Framework project, so I'll answer some questions:
The "Contents can't be autofilled" message typically means the Autofill Service does not know how to autofill the screen. When you're adding autofill support to your app, it's often easier to use an Autofill Service you can control first, rather than a "real" service like a password manager. As mentioned in a previous reply, we provide a sample service that can be used for this purpose.
When you long-press a text field and select AUTOFILL, you are in fact "forcing" an autofill request as mentioned in another reply (i.e., behind the scenes the text field is calling AutofillManager.requestAutofill()). If the Autofill Service knows how to autofill your screen, you shouldn't need to do that, as the autofill suggestions would show up right away once you focus the input field.
You shouldn't need to set importantForAutofill or call AutofillManager.cancel() in your case.
So, my recommendation is to try to use the sample Autofill Service implementation to test your app first. Most likely, the first time you access your app the autofill popup won't be shown because the service does not have data for it. But once your app triggers the save UI (for example, after you manually enter the phone number and the activity finishes) and you tap save, that data should be available the next time you launch the activity.
Hope that helps,
-- Felipe
This may well be the issue - as
as service for ComponentInfo{com.google.android.gms/com.google.android.gms.autofill.service.AutofillService} is already destroyed
Ensuring data is available
In some special cases, you need to take
additional steps to make sure that the data is available to the
Autofill Framework to save. For example, an activity can present a
layout with standard text views, but then destroy the layout and
replace it with one without child views, such as GLSurfaceView.
In this case, the data in the original layout is not available to the
framework. To make the data available to the framework, you should
call commit() on the AutofillManager object before replacing the
original layout.
You'll need to fix some of these issues within your java code.
Add IMPORTANT_FOR_AUTOFILL_AUTO and check that autofill isenabled().
You may need to manage some of the settings within the java force the Autofill request:
Sometimes, you may need to force an autofill request to occur in response to a user action. .../...
public void eventHandler(View view) {
AutofillManager afm = context.getSystemService(AutofillManager.class);
if (afm != null) {
afm.requestAutofill();
}
}
Do you have an app on you phone that implements an Autofill service? I tried it with "Autofill with Google" service, and could got my phone number autofilled without problems (with emulator running SDK 26). You will need a service part for get the autofill working. See this example.
Get the latest OS image. After downloading and installing the update that became available on 2017-09-21 for my Google Pixel XL device, autofill works perfectly. So, it suffices to have android:autofillHints="phone" in XML, no other changes are required to enable the autofill feature.
The "Contents can't be autofilled" - this was caused for me because i did not agree to the auto fill service. So go into your android settings in Oreo and above and search for "autofill" . find your service (mine was default googles) and there should be a prompt to agree to its service. toggle it off and one if it does not appear. Afterwards i was able to use autofill.

Is it possible to get latest missed call or received sms notification from a class which we created on android?

I am able to see getting new sms or calllog from apks which I built but my question is that;
for example I create a .class which in
<com.example.xx
Can I use it on my any other apk's layout xml file using <com.example.xx ... /> using with layout width and height.
Is that possible? If so can you create this class file ?
( I know manifest needs receiver and permissions for latest missed calls & messages)
I hope I can explain clearly what I mean
I'm also not sure what you're asking, but...
Yes, you can access the latest sms or the call log from any Activity you want, from any apk you want, and/or from pretty much from anywhere you want on the phone.
You'd use a Content Provider to access that information. If you wanted to, you could even use a Broadcast Receiver to trigger your application whenever you received a message or phone call.
And yes, you could even do this in a library if you wanted (so that others could use it from their own layouts). If that's what you're asking.
And yes, you could even do this from one apk to another apk through intents if you wanted (not that I would see any advantage to doing that). May be, that last one is not what you were asking.
Have I answered your question?

How to change the default android call screen(both outgoing and incoming)

I would like to know how I can add extra fields to the current android calling and recieving screen ? Like the area code of a region or so? I am looking for pointers at to where to start only. Could someone please help me?Just to convince people that this indeed is possible , the link to the app that does just this is https://play.google.com/store/apps/details?id=ardent.androidapps.callerinfo.views&hl=en

Access the android notifications of other applications

Is it possible to programatically access the text posted on the android notification area (displayed by an application which is not my own)?
The logic I am after would be something like...
for each (NotificationMessage m in NotificationArea.Notifications)
{
String msg = m.GetMessage()
}
Unfortunately, no. This would create security concerns, possibly hijacking personal information. See This Thread
In Android 4.3 and above, use the NotificationListenerService. Otherwise use Accessibility.
http://developer.android.com/reference/android/service/notification/NotificationListenerService.html
This is possible with the accessibility service, but you have to pick up on notifications as they arrive (ie there isn't a list you can iterate around at any point). You'd need to build that up yourself.

android Outbound caller id - on/off

I wan to hide/show my caller id from my activity programmatically. I tried to find it in the android documentation but without the luck. Maybe you have any ideas?
I posted a question asking this on the Android Google group and got absolutely no answers at all. I've also seen a couple of other question on SO which also had no answers (or none that work).
I came to the conclusion that it simply isn't possible. My reasoning is this...
If I go to Settings -> Call -> Additional settings, I see an AlertDialog which has a HeaderTitle of 'Call settings' and I see a circular progress indicator and a message saying 'Reading settings...'.
It occurs to me that my phone is, at that point, accessing my phone/network provider. The resulting 'chooser' dialog gives me options for 'Network default', 'Hide number' and 'Show number' and when I make a selection (or even if I just 'Cancel' the dialog), I get another AlertDialog with circular progress indicator with the message 'Updating settings...'.
In short, it seems the Caller ID setting is not entirely 'local' to the phone settings and relies on interaction with the provider and, for whatever reason, as a result of this the Android APIs don't allow this to be manipulated programatically.
I'm not sure if this is something on the 'To Do' list for future versions of Android or if there are legal/security implications in allowing it to be done or some other reason. Whatever the case may be, I haven't found anybody so far who is able to explain why there isn't a method for TelephonyManager (for example) to simply switch this.
EDIT: No luck on getting the Additional Settings AlertDialog with the standard APIs either.
The reason I say that is that it is possible to pull up various parts of the device's 'Settings', e.g., in one of my apps I use android.provider.Settings.ACTION_WIRELESS_SETTINGS in the constructor of an Intent passed to startActivity(). This brings up the Settings page for enabling/disabling wi-fi, mobile internet and bluetooth.
android.provider.Settings has other similar ACTIONs for other Settings pages but there isn't even one for 'Call' never mind Call -> Additional Settings and nothing for the AlertDialog to allow you to choose to Hide/Show the outgoing Caller ID.
If this can be done then it would have to be an undocumented API unless I completely missed it (I spent a long time looking). I suspect examining the Android source-code may be the only way to find an answer and I haven't attempted that yet.
I have managed to get Additional call settings dialog. Explanation below:
Although it looks like it is part of the Settings, in fact it is part of the Native PhoneApp. If you take a look at the AndroidManifest.xml of the PhoneApp you will see that Activity GsmUmtsAdditionalCallOptions has defined IntentFilter for the android.intent.action.MAIN.
So, the code that I checked to work correctly on several phones:
Intent additionalCallSettingsIntent = new Intent("android.intent.action.MAIN");
ComponentName distantActivity = new ComponentName("com.android.phone", "com.android.phone.GsmUmtsAdditionalCallOptions");
additionalCallSettingsIntent.setComponent(distantActivity);
startActivity(additionalCallSettingsIntent);
If the #31# trick works for your needs for a single call then you could add a broadcast receiver that listens for the outgoing call notification and modifies the number to include #31# at the start before it gets dialled. Android allows the number to be changed on the way through like that.
Only works if your default is to enable caller ID and your network support #31# and you want to toggle it off using a widget, say.
The Caller ID is network specific not something that the phone controls. In fact in certain mobile network configurations the phone doesn't even 'know' its own phone number.
Some networks support sending an activate/deactivate caller ID network command. In GSM this is normally #31#. It can be permanent or on a per call basis.
Permanent requests the network to hide the caller ID for all calls.
Per call requests the network to hide the caller ID only for that call. The latter is achieved by prefixing the number being called by #31#, so for example calling #31#85432786426 would call 85432786426 hiding the caller.
Some networks support both, some only support one of them, and some do not enable it. Try your luck and try prefixing the dialed number with #31# and see if it works.
http://www.gsm-security.net/faq/gsm-caller-id-clip-clir.shtml
If you want a shortcut to the additional call settings, you can use App Cut and select GSM settings. It will place a shortcut on your home screen.

Categories

Resources