This question is pretty much a duplicate but the linked issue was never really resolved and the thread is a few months old so I didn't want to resurrect it.
The default behavior of apps running on an ICS device with Android Beam turned on is to push a message with the application Uri that will be processed by Google Play on the receiving end.
I am trying to develop an activity that will push NdefMessage if condition A is true and will otherwise disable pushing messages. The API documentation for setNdefPushMessage(...) seems to indicate that this is possible by passing in a null message:
Pass a null NDEF message to disable foreground NDEF push in the specified activities.
However, trying to simply ban all pushes via the following code still results with the "Touch to Beam" UI coming up and an application Uri being sent...
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getNfcAdapter().setNdefPushMessage(null, this);
}
Does anyone know if it is actually possible to disable pushes from an Activity? A few systems apps do it but I have not been able to locate the code that achieves this. Any help is much appreciated.
This seems to be a bug in Android ICS. Although the documentation says you should be able to disable it by setting the NDEF message null, this simply does not work. Good news is that it has been fixed and now does work in Android 4.1 Jellybean.
Related
I have a popular read aloud app, that is also often used by visually impaired and blind people. Some, very few of them complain that when using the app or having it read aloud, it repeatedly says "Service at Voice" (my app's name is #Voice Aloud Reader). I tested this on several phones with different versions of Android and TalkBack enabled, but couldn't reproduce this problem.
The app is showing a notification with reading progress and buttons to pause/resume, FF and reverse etc. Of course all the reading aloud is done from a service, not activity, because a user may want to close my activity, or even turn off screen, and still listen. I would gladly post more technical details, but don't know which ones are relevant.
I tried searching for any combination of terms "TalkBack saying 'service' repeatedly", but cannot find anything relevant. My users who contacted me about this could not find either any setting in TalkBack app to make it stop saying this. Could anyone shed some light on this issue?
I found the reason for my problem, part of it was my own app code, and part just confusing behavior of Android system and TalkBack on different devices. Here is what was happening:
The app, #Voice Aloud Reader, reads text loaded into it (web pages, docs, books) and highlights the sentence it reads aloud. On each change of sentence it updates progress, both on its own screen if visible, and in the notification. The notification update code is pretty old, from Android 4 days. I did not know then how to update the content of notification, it seemed to me that the only way to update it, after using NotificationBuilder to update content, was to call in my service again:
startForeground(/* id: */ 1000, myNotifBuilder.build());
It worked well for years, also under TalkBack, no problems. Even today on at least 5 test devices I have with Android 5 to 9 and with emulators, TalkBack activated, it works correctly. But some users reported that upon reading each new sentence (progress update), TalkBack says "Service #Voice". I finally updated the code as follows, and my users report that the problem is solved:
if (newNotification) {
startForeground(/* id: */ 1000, myNotifBuilder.build());
}
else {
NotificationManagerCompat.from(this).notify(1000, myNotifBuilder.build());
}
I doubt that this knowledge will help many people, now notifications are documented better and there is a clear "Update notification" chapter that explains how to do this correctly in Google documents for developers.
I bet it's announcing the app name on orientation changes each time the MainActivity is created.
SO link
I have an app that reads notifications through TTS. With Google's change in policy for apps using Accessibility, I switched to Notification Listener, though that meant I had to remove the option to read toast messages. I released the update last night and already received feedback from someone who wanted the toast feature back.
Is there any way to read toast messages without using Accessibility? My search for a solution came up empty.
Update (2018-01-16)
After a little digging into the Android source, I found this relevant method in the Toast class (API 27):
private void trySendAccessibilityEvent() {
AccessibilityManager accessibilityManager =
AccessibilityManager.getInstance(mView.getContext());
if (!accessibilityManager.isEnabled()) {
return;
}
// treat toasts as notifications since they are used to
// announce a transient piece of information to the user
AccessibilityEvent event = AccessibilityEvent.obtain(
AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED);
event.setClassName(getClass().getName());
event.setPackageName(mView.getContext().getPackageName());
mView.dispatchPopulateAccessibilityEvent(event);
accessibilityManager.sendAccessibilityEvent(event);
}
That makes it clear that if no accessibility services are enabled, toasts aren't dispatched to the handler that AccessibilityService uses, so some kind of hack to access toasts the same way Accessibility gets them would be impossible without any services enabled. Of course, I'm trying to avoid creating an accessibility service again and don't want to rely on users having a different one enabled.
It appears that if there is any way to access toasts without Accessibility, it may have to be some fairly complex reflection to reach Toast$TN.mNextView or .mView through com.android.server.NotificationManagerService.mToastQueue and $ToastRecord.callback. It's a bit over my head right now as I'm not very familiar with reflection, but I'm still digging.
I'm developing an Android app which supports Chromecast and to do that I'm using a combination of MinimalCastMediaRouteProvider + a custom receiver. All is well with the playback but the Chomecast UX guide has a section headed Cast menu functions appropriately for available receiver devices. It seems to state that when the Chromecast device is already connected to a service it should have a label indicating it, like the following with netflix:
The issue is that on my device all I see is this:
where it's missing the "casting xxx" while I have another device casting to it. Is there something I need to set in my receiver app or is it something in the Android code? I don't see any documentation about it.
You don't need to do anything on your side at this point; there is currently a bug in the preview sdk that doesn't let that to work properly.
Once ACTION_NEW_OUTGOING_CALL has been broadcasted, I need to capture the following event of the other party answer. Could you advice on how to achieve that please? I know it is possible as the Android dialer app changes the green Android icon to the person's photo exactly when they pick up.
UPDATED: I've had a look at the source of the app on Android handling the outgoing calls. I noticed the following method in ContactsUtils:
/**
* Kick off an intent to initiate a call.
*/
public static void initiateCall(Context context, CharSequence
phoneNumber) {
Intent intent = new Intent(Intent.ACTION_CALL_PRIVILEGED,
Uri.fromParts("tel", phoneNumber.toString(), null));
context.startActivity(intent); }
I guess my answer is in the activity listening for Intent.ACTION_CALL_PRIVILEGED. So to rephrase my question: Does anyone know which activity handles Intent.ACTION_CALL_PRIVILEGED?
I don't think there's such API and also there's no API for sending DTMFs due to the same reason that you can't tell when the call is being connected.
It does not necessarily needs to be possible to capture this as an outside app. The green android icon is a part of the application that controls the call, so it does not need a broadcast to change the icon.
As far as android's telephony manager is concerned u cannot detect programmatically whether the call has been answered or not. This is to say that u do not have the option to know when the user picked the phone at other end.
Android has got 3 states of telephony manager and none of them are capable of detecting whether the call was actually answerd or not(IN CASE OF OUTGOING CALLS)
The only way you may be able to do this is by parsing the Logcat logs, no PhoneStateListener event is available for that.
Some are asking for it here: https://code.google.com/p/android/issues/detail?id=14266
Anyway, in versions above Android 4.2 as Logcat is "sandboxed" it may be impossible...
I'm working with NFC on Android, specifically with Android Beam. My question is: is it possible to disable Android Beam support for an activity?
This is what some system applications do, such as messaging: if another phone is put close, my phone vibrates but the "Touch to beam" screen doesn't appear and the other phone doesn't receive anything.
EDIT: Calling:
NfcAdapter.setNdefPushMessage(NdefMessage message, Activity activity, Activity... activities)
in onResume() with a null message should do the trick (the doc says: "Pass a null NDEF message to disable foreground NDEF push in the specified activities.") but it doesn't work.
Thanks
When I do it like this, It works like a charm.
NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
adapter.setNdefPushMessage(null, this, this);
There isn't a way to do this currently. Maybe you can provide a menu option to disable NFC in your app? Why do you want to do this, by the way?
EDIT:
Sorry, there is a way to do this. Call setNdefPushMessage() in the activities that you don't want to push anything with a null NDEF message. Let me know if that works.