Category Archives: Android™

bluestacks

Change BlueStacks App Player Resolution

Overview

BlueStacks App Player for Windows is a great Android emulator that supports most of the common apps and games from Google Play.
In this tutorial I will show you how to Change BlueStacks App Player Resolution in Windows.

Download and Install BlueStacks App Player

  1. Go to http://www.bluestacks.com/ and download BlueStacks App Player
  2. Open BlueStacks App Player and register your GMail Account details
  3. Close BlueStacks

Change BlueStacks App Player Resolution

There are several values ‘GuestHeight/GuestWidth’, and ‘WindowHeight/WindowWidth’.
The ‘Guest’ values sets the Androids resolution and the ‘Window’ values sets the window resolution.

  1. Open ‘regedit’: Start->Run->regedit
  2. Navigate to: ‘HKEY_LOCAL_MACHINE/SOFTWARE/BlueStacks/Guests/Android/FrameBuffer/0/’
  3. Double click the value ‘GuestHeight’
  4. Change Base to Decimal
  5. Input your desired Height resolution
  6. Double click the value ‘GuestWidth’
  7. Change Base to Decimal
  8. Input your desired Height resolution

Repeat the process for the ‘WindowHeight’ and ‘WindowWidth’ values.
Change BlueStacks App Player Resolution

Enjoy!

Android_Robot_200

Android Context in non-activity Class – The Secret of ContextWrapper

Android Context in non-activity Class – The Secret of ContextWrapper

Android Context in non-activity Class

One of most frustrating issues I had to figure out when I’ve started to develop for Android was the Context.

Why there are several kind of Context? and more important – How can I call to system API method from a Class when all the important functions are available only from a Context class??

The problem

Let’s take this function inside activity for example (test for AirPlane Mode),
Where isAirPlaneModeOn() is using the getContentResolver() which is Context.method:

public class MyActivity extends Activity {
 
   ...
 
   public boolean isAirplaneModeOn() {
      return Settings.System.getInt(getContentResolver(),
         Settings.System.AIRPLANE_MODE_ON, 0) != 0;
    }
 
}

Or inside a service:

public class MyService extends Service {
 
   ...
 
   public boolean isAirplaneModeOn() {
      return Settings.System.getInt(getContentResolver(),
         Settings.System.AIRPLANE_MODE_ON, 0) != 0;
   }
 
}

P.S: The isAirplaneModeOn() function is using depreceated method (pre API 17) just for the purpose of simple example and backward compatibility.

Now… lets say you want to create some other class, and move the function to that class:

import android.provider.Settings;

public class MyOtherClass {
   ...
   public boolean isAirplaneModeOn() {
      return Settings.System.getInt(<span style="text-decoration: underline;">getContentResolver</span>(),
         Settings.System.AIRPLANE_MODE_ON, 0) != 0;
   }
}

HEY?!!? Why Eclipse telling me: The method getContentResolver() is undefined for the type MyOtherClass

????? ….. Because getContentResolver() is a context method – Soon you realize you must have access to Context.. so What the solution?

 

Some solutions

I’ve read a lot about context(s). Maybe, most of the valuable stuff out there in the internet…

Some are saying to pass the context to the class and save a reference to that context like:

class YourNonContextClass {
   private Context context;

   public YourNonContextClass(Context context){
      this.context=context;
   }

   public boolean isAirplaneModeOn() {
      return Settings.System.getInt(context.getContentResolver(),
         Settings.System.AIRPLANE_MODE_ON, 0) != 0;
   }
}

Some are saying to pass the context to your static function like:

public class MyOtherClass { 
   public static boolean isAirplaneModeOn(Context context) {
      return Settings.System.getInt(context.getContentResolver(),
         Settings.System.AIRPLANE_MODE_ON, 0) != 0;
   }
}

Both solutions works. Both have their Pros and Cons. both require you to alter the code inside the function.

 

Solution – The Secret of ContextWrapper

Finally … After a fashion… With lot of experimentation, I’ve found a great solution that I really like! :

CONTEXTWRAPPER!

So What is ContextWrapper?

Proxying implementation of Context that simply delegates all of its calls to another Context. Can be subclassed to modify behavior without changing the original Context.

In other simple words: It’s a class that inherits another Context.

 

So, How to use the ContextWrapper?

Let’s talk about the function we discussed above and create a ContextWrapper class for it:

public class MyContextWrapper extends ContextWrapper {

    public MyContextWrapper(Context base) {
      super(base);
   }

   public boolean isAirplaneModeOn() {
      return Settings.System.getInt(getContentResolver(),
         Settings.System.AIRPLANE_MODE_ON, 0) != 0;
   }
}

Note that nothing need to be changed in the isAirplaneModeOn() function as the class itself inherits the wrapper you’ve called from (Activity, Service, IntentService, etc).

To call the function just use:

boolean isAir = (new MyContextWrapper(this)).isAirplaneModeOn();

Where ‘this’ could be any context you’d like to. applicationContext, Service or Activity.

 

That’s it.  Easy haa!

And choose what fits you best…

 

Development Specialist, Artist and Activist
Personal Website
android

Android Get Mobile IP Address code example

Android Get Mobile IP Address

Android Get Mobile IP Address Code Example

Android Get Mobile IP Address :

Getting the android IP address for Wi-Fi connection using the API is very simple:

/**
 * Get the IP of current Wi-Fi connection
 * @return IP as string
 */
private String getIP() {
 try {
   WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
   WifiInfo wifiInfo = wifiManager.getConnectionInfo();
   int ipAddress = wifiInfo.getIpAddress();
   return String.format(Locale.getDefault(), "%d.%d.%d.%d",
   (ipAddress & 0xff), (ipAddress >> 8 & 0xff),
   (ipAddress >> 16 & 0xff), (ipAddress >> 24 & 0xff));
 } catch (Exception ex) {
   Log.e(TAG, ex.getMessage());
   return null;
 }
}

But what if you need to get the Mobile connection IP?

The answer is to check the NetWorkInterface like this:

/** Get IP For mobile */
public static String getMobileIP() {
  try {
    for (Enumeration<NetworkInterface> en = NetworkInterface
    .getNetworkInterfaces(); en.hasMoreElements();) {
       NetworkInterface intf = (NetworkInterface) en.nextElement();
       for (Enumeration<InetAddress> enumIpAddr = intf
          .getInetAddresses(); enumIpAddr.hasMoreElements();) {
          InetAddress inetAddress = enumIpAddr.nextElement();
          if (!inetAddress.isLoopbackAddress()) {
             String ipaddress = inetAddress .getHostAddress().toString();
             return ipaddress;
          }
       }
    }
  } catch (SocketException ex) {
     Log.e(TAG, "Exception in Get IP Address: " + ex.toString());
  }
  return null;
}

And if you want to get the IP as IPV4 just replace the line:

          if (!inetAddress.isLoopbackAddress()) {

With:

 if (!inetAddress.isLoopbackAddress() && InetAddressUtils.isIPv4Address(inetAddress.getHostAddress())) {
Development Specialist, Artist and Activist
Personal Website
bluestacks

Optimize BlueStacks App Player for Windows

Overview

BlueStacks App Player for Windows is a great Android emulator that supports most of the common games on Google Play.
In this tutorial I will give you a few tips how to optimize BlueStacks App Player for Windows.

Download and Install BlueStacks App Player

  1. Go to http://www.bluestacks.com/ and download BlueStacks App Player
  2. Open BlueStacks App Player and register your GMail Account details
  3. Close BlueStacks

Adjust BlueStacks RAM (Memory)

BlueStacks App Player comes with a default of 768MB RAM.

  1. Open ‘regedit’: Start->Run->regedit
  2. Navigate to: ‘HKEY_LOCAL_MACHINE/SOFTWARE/BlueStacks/Guests/Android’
  3. Double click the value ‘Memory’
  4. Change Base to Decimal
  5. Input your desired RAM amount
    DO NOT USE MORE THEN HALF OF YOUR PHYSICAL RAM!!
    For example: If you have 4GB of RAM input 2GB: ‘2048’
  6. optimize BlueStacks RAM

Flickering Issue with NVidia Display Adapter

Sometimes with NVidia GPUs there is an issue that causes the screen to flicker.
CHANGE THIS ONLY IF YOUR BLUESTACKS APP IS FLICKERING!!

  1. Open NVidia Control Panel and navigate to ‘Manage 3D Settings’
  2. Select tab ‘Program Settings’
  3. Click Add and Select ‘BlueStacks Frontend’
  4. Scroll down to ‘Threaded optimization’ and change it to ‘Off’
  5. optimize BlueStacks NVidia GPU

BlueStacks Process priority

Increase BlueStacks Process priorities in Task Manager:

  1. Open Task Manager and go to Details tab
  2. Right-Click ‘HD-Frontend’ and change priority to Above-Normal
  3. optimize BlueStacks NVidia CPU

Enjoy!!

ydpg17 reset

ydpg17 reset – going back to factory defaults

ydpg17 reset

ydpg17 reset – You may know this console as YinLips, Innova or whatever your country importer decides.

 

ydpg17 reset

to reset your YDPG17 android box – Start your YDPG17 games console with ‘POWER‘ + ‘M‘ buttons pressed. after the console start loading leave the power button and continue holding the M button until you’ll get into the menu.

ydpg17 reset

ydpg17 reset

 

to navigate in the menu (it may be different for your console):
use the wheel to move between options and power button to select.

Choose (3) Only format data and cache area.

 

ydpg17 reset

ydpg17 reset

ydpg17 reset

 

that’s it.. you’ve reset your ydpg17 game console back to default.

 

Cheers!,

Development Specialist, Artist and Activist
Personal Website
galaxys3

Install CM10.1 for Galaxy S3 i9300 (Android 4.2.2)

Overview

This tutorial will explain how to install CM10.1 for Galaxy S3 i9300 (Android Jelly Beans 4.2.2).

CM10.1 for Galaxy S3 i9300

Continue reading

CM10

unfortunately android keyboard has stopped FIX

unfortunately android keyboard has stopped

unfortunately android keyboard has stopped error in Google Android CyanogenMod CM10.1 custom rom is a very simple issue to fix.

  • Goto your phone settings -> Apps
  • Change from “Downloaded” tab to “All” tab.
  • Click on “Android keyboard (ASOP) and click on “Clear Data”.
  • Click on “Dictionary Provider” and click on “Clear Data”.

unfortunately android keyboard has stopped FIX

Development Specialist, Artist and Activist
Personal Website
android

Android preference multiple dependency with CheckBoxPreference

Android preference multiple dependency

Android preference multiple dependency is not out-of-the-box feature until api level 14 introduced us with SwitchPreference (extends TwoStatePreference) to implement such feature. the old CheckBoxPreference can’t do that.

 

If your app is designed for newer systems only, (min-api equal or higher than 14) that won’t be a problem for you – because you can use the new SwitchPreference element to get at least 2 states, but if your app designed to work with older api support, or more than 2 dependencies on one element – you need another method.

Note: you can always implement both ways! use the ‘/xml-v14‘ directory to create multiple version of your XML, better with include, one for API 14 with SwitchPreference, and one for the old API’s with the following solution.

Continue reading

Development Specialist, Artist and Activist
Personal Website
CM10

Change CyanogenMod back to Stock – Galaxy S1/S2/S3

Overview

In this tutorial we will explain how to change your Android Samsung Galaxy S1/S2/S3 Device Firmware back to Samsung Stock Firmware from CyanogenMod.

CyanogenMod back to Stock

Continue reading

sgs1

Install CM10.1 for Galaxy S i9000 (Android 4.2.2)

Overview

This tutorial will explain how to Install CM10.1 for Galaxy S i9000 (Android Jelly Beans 4.2.2).
Only for Android 2.3.3 and above, Android 2.3.2 and below Should upgrade to 2.3.3-2.3.6 before changing to CM10

CM10.1 for Galaxy S i9000

Continue reading