uri

How to make a phone call from your Android app alvin March 12, 2018 - 10:45pm

I came across this Android phone dialer tip yesterday. If you want to make a phone call from an Android application, all you have to do is create a new Intent, either an Intent.ACTION_DIAL (to start the call) or Intent.ACTION_CALL (to place the call).

Here are the three lines of source code you need to get started:

Intent dialIntent = new Intent();
dialIntent.setAction(Intent.ACTION_DIAL);
dialIntent.setData(Uri.parse("tel:8675309"));

How to write if/then/elseif/else in Drupal 8 Twig templates

As a quick note Drupal programming note, here’s an example of how to write if/then/elseif/else in Drupal 8 Twig templates:

{% if node.getType == 'photo' %}
...
{% elseif node.getType in ['book', 'page'] %}
...
{% else %}
...
{% endif %}

While I’m in the neighborhood, here are a few more if conditions I’ve written recently:

How to get the URI of the current node in a Drupal 8 Twig template theme file

As a quick note, I was just able to get the URI of the current page (node) in a Drupal 8 Twig template theme file using this code:

{% set uri = path('entity.node.canonical', {'node': node.id}) %}

As an example, I’m rendering some different content based on the URI of the current node, so I first use that code to set the uri field, then I have a little Twig if/then/else condition like this:

{% if uri starts with '/foo' %}
    <div>Option Foo here ...</div>
{% elseif uri starts with '/bar' %}
    <div>Option Bar here ...</div>
{% else %}
    <div>Option Baz here ...</div>
{% endif %}

In summary, if you wanted to see how to get the URI of the current page/node when using a Drupal 8 Twig theme template file, I hope this example is helpful.

The Android “adb shell list files permission denied” error

As a brief note, today I tried to list the files in my Android application, which was running on a physical Android device — a Nexus 9 — with this adb shell command:

adb shell com.alvinalexander.mybrowser ls /data/data/com.alvinalexander.mybrowser

When I did that, I got an Android/ADB “permission denied” error.

The short story is that a solution to this problem is to run the same command, but with the run-as argument, like this:

Manual PHP and Drupal 6 web access logging

There was a little funky activity on a client's Drupal 6 website that was hosted at GoDaddy, and without having access to an Apache access log file, I wanted to be able to see what was going on. So I wrote the following PHP code snippet to do some manual logging, and placed it in the Drupal theme's page.tpl.php file:

Get a web client's IP address with PHP

I just ran into a situation for a Drupal/PHP client where I wanted to log some access information. There was some unusual access activity on the website, and I want to log IP addresses and URLs for a few days.

As part of that, I wanted to get the web client's IP address, and in PHP you get the client IP address like this:

$ip = $_SERVER['REMOTE_ADDR'];

That returns something like this:

192.168.100.10

If you just need to get a web client's IP address from a PHP script, that's all you need.

Apache RedirectMatch wildcard examples

Apache Redirect 301 FAQ: How can I redirect many old web pages using the Apache Redirect or RedirectMatch syntax and wildcard patterns (regex patterns)?

I'm currently trying to fix a lot of URLs that I more or less intentionally broke when I deleted the old "directory" portion of this website. In short, after removing the directory, no URL at "/Dir" work any more, so I have thousands of broken URLs (technically "URIs") that look like this:

Drupal canonical meta tags for pager URLs alvin May 31, 2011 - 10:06pm

As a quick note, I was just about to write a Drupal 6 module to add "rel=canonical" meta tags to Drupal pager pages (pager URLs), so URLs that look like this:

http://www.devdaily.com/blog?page=47

or this:

What is my Drupal user login URL?

Drupal user login URL FAQ: What the heck is my Drupal user login URL?

A funny story about this Drupal website (alvinalexander.com) is that after I first installed it with my own custom theme where I don’t display the Drupal login link, I couldn’t remember where the Drupal user login page was located. With my Drupal theme changes I didn’t have a link to the Drupal login page anywhere on my Drupal website pages.

After a little bit of poking around, I finally realized the Drupal login page is located at this pretty obvious URI:

Drupal URL/URI - How to get the URL/URI of the current Drupal page

Drupal FAQ: How do I get the URI (or URL) of the current web page from my Drupal theme?

Sometimes when you're working on a Drupal theme, or customizing an existing Drupal theme, you'll want to know the URL (or more likely, the URI) of the page that the user is currently looking at so you can customize that page (or more likely, a series of pages beginning with a certain URI pattern, as with this Custom Drupal PHP block example).