Hi! I’ll share a few tips with you on how to find out the number of methods that your Android app has. I’m gonna show you a few tools such as APK file methods counter, and an Android plugin that will show you the number of methods each imported class or dependency has. These will […]
programming
CSS / JavaScript: Twitter Bootstrap center modal vertically on mobile web view
I’ve been working with modal boxes using Twitter Bootstrap. And the page I’m working on needs to be viewed in mobile devices. The modal looks nice and centered when viewed on desktop, but when run in mobile web browsers, it’s aligned to the top. Someone on StackOverflow suggested the use of a helper div plus […]
JavaScript: Get current function name
getCallingFunctionName() is the important function here.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
function getCallingFunctionName() { var re = /function (.*?)\(/ var s = getFunctionName.caller.toString(); var m = re.exec( s ) return m[1]; } function myCurrentFunction(){ var func_name = getCallingFunctionName(); alert(func_name); //displays "myCurrentFunction" } myCurrentFunction(); |
Source: Can I get the name of the currently running function in JavaScript?
Android: Switch into another activity
To switch into another activity, the method we use is startActivity(). This is what starts another Android activity:
1 2 |
Intent i = new Intent(this, NameOfActivity.class); startActivity(i); |
Replace NameOfActivity with the name of any activity you’d like to switch into.
Android: Basic WebView Tutorial
A WebView lets you pull a web page and display it in your Android app. It doesn’t take long to implement an Android WebView. Read on. I’ll show you how. AndroidManifest.xml First, open your manifest file to add this permission for INTERNET:
1 |
<uses-permission android:name="android.permission.INTERNET" /> |
The web page won’t be loaded into your app without this permission. […]
PHP dynamic variable names tutorial
I think it’s very convenient for us developers, being able to name our variables dynamically. I’ll show you how to do it in PHP. 🙂 For example, we have variable $foo with “bar” as value like this:
1 2 |
<?php $foo = "bar"; |
If we want to create a variable named based on the “value” of variable $foo, this is […]
PHP: get full URL of current page with GET params or without
The following string variable’s value will get the full URL of the current page, including GET arguments/params, if present.
1 2 3 4 5 6 |
<?php $full_current_url = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; echo $full_current_url; ?> |
To get the full URL of current page but WITHOUT the GET args/params, do this instead:
1 2 3 4 5 6 |
<?php $full_current_url = "http://" . strtok($_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'], "?"); echo $full_current_url; ?> |
The strtok function will return only the part of the URL string up to the character before question […]
Android NetworkOnMainThreadException at StrictMode fix (with deprecated methods used)
A JSON Parser developed by some members of the Android dev team. But a few weeks after completion of the parser, several methods became deprecated. And when we use that parser, we get errors. Part of the stack trace is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[...] E/AndroidRuntime: Caused by: android.os.NetworkOnMainThreadException at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1148) at java.net.InetAddress.lookupHostByName(InetAddress.java:405) at java.net.InetAddress.getAllByNameImpl(InetAddress.java:251) at java.net.InetAddress.getAllByName(InetAddress.java:229) at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137) at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465) [...] |
Not sure if the NetworkOnMainThreadException is being thrown because of the deprecated […]
Android/Java: get variable data type
For some reason you might need to get the data type of your Java variable. Here’s an example of what you can try:
1 2 3 |
String date_created = "2016-02-04"; String data_type = date_created.getClass().getSimpleName(); |
Then do whatever you like with data_type, whose value should be “String”. 🙂
Get device’s IMEI in Android app development
Here’s the content of my MainActivity class where I log the IMEI of my test device.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
package net.catzie.playground; import android.content.Context; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.telephony.TelephonyManager; import android.util.Log; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); String deviceID = telephonyManager.getDeviceId(); Log.d("Device IMEI", deviceID); } } |
You also need to add this permission to your AndroidManifest.xml file:
1 |
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> |
Place it inside the <manifest></manifest> tag, but same level as <application></application>. Source: How to get the device’s IMEI/ESN programmatically in android?