How do I hide Google Ad Manager ads on mobile devices? - google-ad-manager

I have a <div class="ad-container"> that contains my Google Ad Manager snippet for displaying ad banners, and my CSS has media queries to hide it on smaller devices:
.ad-container {
display: none;
}
Will that prevent the ad from triggering impressions in Google Ad Manager? Or will the impression be counted (but obviously never get clicked since the user can't see it)?
Otherwise how do I do this correctly to not trigger an impression?

Hidding a placement container won't prevent adserver calls. Most of the time, Google Ad Manager will try to force the display of the ad to prevent unviewable ads.
In your case, I would use the sizeMapping (see here) to define sizes attached to the banner placement.
Here is a sample :
var adSlot = googletag
.defineSlot('/6355419/Travel/Europe', [728, 90], 'banner')
.addService(googletag.pubads());
var mapping = googletag.sizeMapping()
.addSize([640, 480], [728, 90]) //allow 728x90 ad banner for screens bigger than 639x479px
.addSize([0, 0], []) //below 639x479px window size, no ad size attached / allowed
.build();
adSlot.defineSizeMapping(mapping);
Using responsive sizeMapping is the correct way to dispatch size per window size.

Related

How do I fetch HomeKit values for usage in iOS 14 Widgets?

I am writing a HomeKit app that successfully shows live data from my supported accessories in-app. I can read single values (HMCharacteristic.readValue) or use notifications to stay updated (HMCharacteristic.enableNotification).
Now I want to implement Widgets that show this data on the user's Home Screen. This consists of four steps:
A dynamic Intent fetches all the registered (and supported) Accessories from the HMHomeManager and enables the user to select one of them to be shown on the Widget.
Inside the IntentTimelineProvider's getTimeline function I can then again use the HMHomeManager to retrieve the Accessory I want to display on the Widget (based on the Accessory's UUID which is stored inside the getTimeline's configuration parameter - the Intent).
Still inside the getTimeline function I can choose the Services and Characteristics I need for displaying the Accessory's Widget from the HMHomeManager.
Up until here everything works fine.
However, when I try to read the values from the Characteristics I chose before using HMCharacteristic.readValue, the callback contains an error stating
Error Domain=HMErrorDomain Code=80 "Missing entitlement for API."
The Widget's Info.plist contains the 'Privacy - HomeKit Usage Description' field and the Target has the HomeKit capability.
After some research I came up with the following theory: Obviously the whole WidgetKit API runs my code in background. And it seems like HomeKit does not allow access from a background context. Well, it does allow access to Homes/Services/Characteristics, but it does not allow reading or writing on Characteristics (I guess to make sure App developers use HomeKit Automations and don't try to implement custom automations that are controlled by some background process of their app running on the iPhone).
My (simplified) getTimeline code:
func getTimeline(for configuration: SelectAccessoryIntent, in context: Context, completion: #escaping (Timeline<Entry>) -> ()) {
// id stores the uuid of the accessory that was chosen by the user using the dynamic Intent
if let id = configuration.accessory?.identifier {
// Step 2.: fetch the accessory
// hm is a HMHomeManager
let hm = HomeStore.shared.homeManager
// take a short nap until the connection to the local HomeKit instance is established (otherwise hm.homes will create an empty array on first call)
sleep(1)
let accessories = hm.homes.flatMap({ h in h.accessories })
if let a = accessories.filter({ a in a.uniqueIdentifier.uuidString == id }).first {
// a holds our HMAccessory
// Step 3.: select the characteristic I want
// obviously the real code chooses a specific characteristic
let s: HMService = a.services.first!
let c: HMCharacteristic = s.characteristics.first!
// Step 4.: read the characteristic's value
c.readValue(completionHandler: {err in
if let error = err {
print(error)
} else {
print(c.value ?? "nil")
}
// complete with timeline
completion(Timeline(entries: [RenderAccessoryEntry(date: Date(), configuration: configuration, value: c.value)], policy: .atEnd))
})
}
}
}
}
My questions:
First: Is my theory correct?
If so: What can I do? Are there any entitlements that allow me to access HomeKit in background or similar? Do I need to perform the readValue call elsewhere? Or is it just impossible to use the HomeKit API with WidgetKit with the current versions of HomeKit/WidgetKit/iOS and best I can do is hope they introduce this capability at some point in the future?
If not: What am I missing?

Pywinauto 0.6.0 access browser URL in edit control for Firefox

I am currently trying to access URL of the active window for Firebox browser using Pywinauto 0.6.0, as part of a python app that can track website usage. I am a newbie python programmer, so if I have made some obvious mistakes then this is why.
I have read all the material I can find on Google and the Pywinauto docs, but there are no clear indications of how to do this, atleast not without using "Typekeys" after connecting to a window.
In fact, I have been able to access to the URL the "hack" way by connecting to the browser window with pywinauto, then using "TypeKeys()" to grab the URL and copy it to clipboard. But this approach will not work for me, as it interrupts the user and my app must run in the background whilst the user is accessing their system as usual. Using the typekeys method introduces some odd mouse and window behaviour when changing or refreshing windows and then trying to grab the URL - so the approach has proven unworkable for me.
Currently the code I have is as follows (I have used the window text title='' of a specific window I am using for testing, in practice it is whichever the active tab on the browser is):
from pywinauto import *
app = application.Application()
app.connect(title=u'Facebook - Log In or Sign Up - Mozilla Firefox', found_index=0)
window = app.top_window_()
window.PrintControlIdentifiers()
titlebar = window.child_window(title=u'Facebook - Log In or Sign Up - Mozilla Firefox')
toolbar = titlebar.child_window(title=u'Navigation Toolbar')
combobox = toolbar.child_window(title=u'Search or enter address')
edit = combobox.child_window(title=u'Search or enter address')
I use PrintControlIdentifiers() in order to see which elements I can interact with, but this returns only
MozillaWindowClass - 'Facebook - Log In or Sign Up - Mozilla Firefox' (L-32000, T-32000, R-31840, B-31944)
[u'Facebook - Log In or Sign Up - Mozilla Firefox', u'MozillaWindowClass', u'Facebook - Log In or Sign Up - Mozilla FirefoxMozillaWindowClass']
I can access the Firefox Window fine with the current active tab, but next when trying to access the ChildWindow and subsequent ChildWindow there is no error, until I try and do something with the childwindow e.g., Click() function on what I think in the URL bar UI element. However, I am not sure even if the code is even accessing the child window element correctly in the first place. Or if this the right way to try and filter through the child elements to get to the URL edit control element.
As can be seen in the below image of the tree view of the UI elements (using UISPY.exe), the following tree to access the firefox browser edit control element that contains the URL is:
Tree view of Firefox UI elements via UISPY
"window" -> "title bar" -> "tool bar" "Navigation Toolbar" -> "combo box" -> "Search or enter address" -> "edit" "Search or enter address
where the "edit" control contains the attribute Value, Value:"url", which I need to extract to a variable.
Any help with this would greatly appreciated.
This is probably too late to post but incase any future developers has similiar question. Here is working solution.
Just pass backend='uia' as argument like application.Application(backend='uia'). Now, accessing and performing actions on child_window is possible.
Here is complete code snippet for any url.
url='https://google.com'
app = application.Application(backend='uia').connect(title_re=".*Mozilla Firefox")
main_firefox_winspec = app.window(title_re=".*Mozilla Firefox")
address_bar = main_firefox_winspec.child_window(title_re=".*or enter address", control_type="Edit")
address_bar.set_edit_text(url)
time.sleep(3)
main_firefox_winspec.child_window(title="Go to the address in the Location Bar").wrapper_object().click_input()

Use Google Glass Mirror API to scan QR code

I have the Google Mirror API's Quick Start for PHP up and running on a Microsoft Azure Website and can communicate with Google Glass.
I had a closer look to the options like the "request/response" example:
case 'insertItemWithAction':
$new_timeline_item = new Google_TimelineItem();
$new_timeline_item->setText("What did you have for lunch?");
$notification = new Google_NotificationConfig();
$notification->setLevel("DEFAULT");
$new_timeline_item->setNotification($notification);
$menu_items = array();
// A couple of built in menu items
$menu_item = new Google_MenuItem();
$menu_item->setAction("REPLY");
array_push($menu_items, $menu_item);
$menu_item = new Google_MenuItem();
$menu_item->setAction("READ_ALOUD");
array_push($menu_items, $menu_item);
$new_timeline_item->setSpeakableText("What did you eat? Bacon?");
$menu_item = new Google_MenuItem();
$menu_item->setAction("SHARE");
array_push($menu_items, $menu_item);
(from https://github.com/googleglass/mirror-quickstart-php/blob/master/index.php)
I am now wondering if it is possible to use the Google Glass Mirror API to scan a QR code.
The idea is to replace the user having to speak a control digit, convert the control digit to a QR code and have the user scan the QR code without having to speak.
Is this possible?
You cannot present a QR Code scanning screen to your user by only using the Mirror API. Nor can you add a MenuItem allowing the user to send back a picture.
But, you can register as a contact, and have your users share with you pictures containing QR Codes.
More info about registering as a contact
More info about receiving shares
This is not a very fluid user experience, but it's the only way you could "scan" QR Codes while only using the Mirror API.

Google Glass: Displaying a published LiveCard

I'm having trouble displaying a LiveCard.
public class RollTheDiceActivity extends Activity {
private LiveCard mLiveCard;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_roll_the_dice);
// ^^^^^^^^^^^^^^^^^^^^^^
publishCard(this);
}
private void publishCard(Context context) {
// Already published
if (mLiveCard != null)
return;
String cardId = "my_card";
TimelineManager tm = TimelineManager.from(context);
mLiveCard = tm.getLiveCard(cardId);
RemoteViews mRemoteViews = new RemoteViews(context.getPackageName(),
R.layout.livecard_roll_the_dice);
// ^^^^^^^^^^^^^^^^^^^^^^
mLiveCard.setViews(mRemoteViews);
Intent intent = new Intent(context, RollTheDiceActivity.class);
mLiveCard.setAction(PendingIntent.getActivity(context, 0, intent, 0));
mLiveCard.publish();
}
}
I expected to see the contents livecard_roll_the_dice instead of activity_roll_the_dice, since publishing will be instant and take over the screen.
Instead, activity_roll_the_dice content is showing. I think this means that the mLiveCard is either never published or published but not pushed to the screen.
How do I show the contents of a published card on the screen?
In case it helps, I'm launching the app through a voice trigger from home screen: "Ok Google, roll the dice"
Thank you!
Live cards are published in the background unless you pass PublishMode.REVEAL to the publish method to force it to be displayed. However, a larger problem is that live cards should be published by a background service rather than an activity. Live cards need to be owned by a long-running context in order to stay alive in the timeline while the user is navigating elsewhere in the timeline or in immersions.
So, if you want an activity to also publish a live card, you should put the live card code in a service and have the activity make a call to that service (e.g., using a binder) to publish the card.
Is there a reason you're using an activity at all and setting its content view when you expect the live card to be displayed immediately? If that's the behavior you want, you might consider removing the activity entirely and using a service instead, with the voice trigger attached to the service. The compass sample provides an example of this.
Calvin, the live card's "life" should be tied to something more "persistent", as the previous poster points out. If you look at my example code, it always uses a background service to control the life of the live card. Your activity will come and go (paused/resumed) whereas the live card is "pinned" and it's always there until you explicitly "unpublish" it.
One other thing i found that might save someone a bit of time with this problem!
When using RemoteViews for "low frequency updates" from a service to manage a LiveCard (rather than a DirectRenderingCallback for "high frequency" updates), ensure you DONT call setDirectRenderingEnabled(true) on the LiveCard.
This will cause the RemoteView to not work at all! Removing the setDirectRenderingEnabled from the liveCard when using a RemoteView to manage its view resource fixed the livecard not appearing issue for me.

Does the /me/friends Facebook open graph API call ever get paginated?

I'm testing my app based on a friend list of about 350 people, and not seeing any pagination on /me/friends/.
What's unclear to me (by testing & documentation) is the following:
At how many friends do the graph.facebook.com/me/friends or graph.facebook.com/ID/friends open graph calls starts to paginate, if at all?
look at Graph API Explorer: https://developers.facebook.com/tools/explorer?method=GET&path=me%2Ffriends and scroll to the very bottom - you will there something like:
"paging": {
"next": "https://graph.facebook.com/me/friends?format=json&limit=5000&offset=5000&__after_id=XXX"
}
which leads me to believe that default page size is 5000
you can set that limit explicitly if you want to: https://developers.facebook.com/tools/explorer?method=GET&path=me%2Ffriends%26limit%3D1
Set the limit yourself using limit=5000 for max limit. I.e so /me/friends?limit=5000
With the JavaScript SDK, two fields are returned, data and paging. Just hit the nextPage URL, and on the next result, there will be no more paging variable/next variable, indicating that you've hit the end.