Skip to content

Instantly share code, notes, and snippets.

/**
* Returns a list of packages that support Custom Tabs.
*/
public static ArrayList getCustomTabsPackages(Context context) {
PackageManager pm = context.getPackageManager();
// Get default VIEW intent handler.
Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
// Get all apps that can handle VIEW intents.
List resolvedActivityList = pm.queryIntentActivities(activityIntent, 0);
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<script async src="https://cdn.ampproject.org/shadow-v0.js"></script>
<style>
#amp-container {
width: 100vw;
height: 80vh;
public boolean hasOficialPackage() {
Intent intent = new Intent("...");
PackageManager pm = getPackageManager();
// Queries for Packages that can handle a given Intent
List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(intent, 0);
for (ResolveInfo ri: resolvedActivityList) {
// Is this the package we'e looking for?
if (ri.activityInfo.packageName.equals("my.package.name")) {
try {
@andreban
andreban / UpdateCache.java
Last active September 4, 2017 10:41
Signing an AMP update-cache URL in Java
/**
* Copyright 2015-2016, Google, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@andreban
andreban / golang_on_rpi.md
Last active August 5, 2017 20:57 — forked from konradko/golang_on_rpi.md
Install Golang 1.8 on Raspberry Pi

Check latest version on https://golang.org/dl/

wget https://storage.googleapis.com/golang/go1.7.linux-armv6l.tar.gz
sudo tar -C /usr/local -xzf go1.8.3.linux-armv6l.tar.gz 

Add the following to ˜/.profile

export PATH=$PATH:/usr/local/go/bin
// The PM5 API returns a Promise when the connection is established.
// The WakeLock is acquired once a connection is established.
pm5.connect()
.then(() => {
screen.keepAwake = true;
//...
});
// The API also provides a disconnect event. The WakeLock is released
// once the application is disconnected from the rowing machine.
pm5.addEventListener('disconnect', () => {
gulp.task('generate-service-worker', callback => {
const rootDir = 'dist';
swPrecache.write(path.join(rootDir, 'service-worker.js'), {
staticFileGlobs: [rootDir + '/**/*.{js,html,css,png,jpg,gif,svg,eot,ttf,woff}'],
stripPrefix: rootDir
}, callback);
});
generalStatusCharacteristic.addEventListener('characteristicvaluechanged', e => {
const dataView = e.target.value;
const avgStrokeRate = dataView.getUint8(10);
const endingHeartRate = dataView.getUint8(11);
const averageHeartRat = dataView.getUint8(12);
// ...
});
serialNumberCharacteristic.addEventListener('characteristicvaluechanged', e => {
const decoder = new TextDecoder('utf-8');
const value = decoder.decode(e.target.value);
// ...
});
rowingService.getCharacteristic('ce060031-43e5-11e4-916c-0800200c9a66') // General Info.
.then(generalInfoCharacteristic => generalInfoCharacteristic.startNotifications())
.then(generalInfoCharacteristic => {
generalInfoCharacteristic.addEventListener('characteristicvaluechanged', e => {
// Parse characteristic value.
});
});