Posts Tagged ‘Code Snippet’

Posts that have small parts from a bigger code.

How to get Android local files URI

Click here to read How to get Android local files URI

When programming applications for Android that requires the playback of audio or video files, sometimes, there’s the need to obtain the URI of those media files instead of using a String for the absolute path. But what is a URI? A URI (Uniform Resource Identifier) is an address to an local or internet resource. It’s more like a standardized path syntax that allows pointing to a specific resource that’s available over the internet, however we are going to use it to point it to a local resource.

A URI is specially useful, when using the VideoView class to load a video located on the res folder or in the SD card. Passing the video file to the VideoView as a String won’t even work on an emulated Android device. This way, we need to get the URI of the file.


WordPress: get posts within the loop

Click here to read WordPress: get posts within the loop

This post will explain how to get posts at the WordPress loop, so you can place code (probably advertisement code) after a specific post (first, second, third) or at intervals (e.g.: every 3 posts).

Before starting, it is a good idea to create a backup copy of your theme’s index.php file, just in case anything goes wrong.

This is a five page post, so here is the page index:

  1. Get the first post
  2. Get the 2nd, 3rd or any other post
  3. Get odd/even posts
  4. Get post intervals
  5. Final considerations

Let’s begin by finding where to place the code. That’s why we need to find the WordPress Loop in the index.php file.


Access Activity class from View

Click here to read Access Activity class from View

So, it begins! This is the first on this blog!

Let’s start with a Android Programming tip: how to access the Activity from an instantiated View object.

The first thing to do is consider if you really need to call an Activity from a View. Take some time to analyze your classes and their relationships. Probably, the variable/method you need to access doesn’t have to be a member of the Activity class. In that case, think about placing that variable/method inside the View or create a new class that has variables/methods which can be accessed by both Activity and View. Unless an Activity variable or method (e.g. Activity.finish() ) needs to be called from the View, there is no need to try to access the Activity from the current View.

But if you need to access a method/variable of the calling Activity from the View, here is how it’s done: