New logo!

Hi everybody,

As you can see in the header of the website. We are proud to present you our new logo, made by Loes Habraken. She is a good friend of PullesSon – Android and a wonderful freelance designer.

We are really happy with this contribution of Loes Habraken and in the future you might see more designs from her hand. If you are searching for design, logo of style you can always contact her. You can get more info about her at www.loeshabraken.com.

Thanks again Loes.

Kind regards,
PullesSon – Android

Tips & Tricks: WiFi Direct

Hi Android dev’s,

We are back in business at least on the website. We still are having some technical problems with our hardware.

Today we would like to share some information on WiFi Direct with Android.

What is WiFi Direct?
WiFi Direct is a direct connection between two WiFi devices, which at least one is WiFi Direct certified, without any access point in between. It can do peer to peer connections over WiFi, because it will start up an soft AP (Software Access Point). When the connection is established it can do similar things as bluetooth: share files, print files and play together. It has a larger range then bluetooth.

How to implement it in Android?
From Android 4.0 (API Level 14) it is possible to use WiFi Direct in applications.
Everything we need to do from within the application is coming from: WifiP2pManager. With WifiP2pManager you can do initialization, discover, connect and more.

To start you first need to add the following permissions to your Android manifest.

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

After the right permissions are added you need to add a simple broadcast receiver, so your application will receive the events from the Android system.

/**
 * A BroadcastReceiver that notifies of important Wi-Fi p2p events.
 */
public class WiFiDirectBroadcastReceiver extends BroadcastReceiver {
 
    private WifiP2pManager manager;
    private Channel channel;
    private MyWiFiActivity activity;
 
    public WiFiDirectBroadcastReceiver(WifiP2pManager manager, Channel channel,
            MyWifiActivity activity) {
        super();
        this.manager = manager;
        this.channel = channel;
        this.activity = activity;
    }
 
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
 
        if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {
            int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);
            if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
                // Wifi Direct is enabled
            } else {
                // Wi-Fi Direct is not enabled
            }
        } else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {
            // request available peers from the wifi p2p manager. This is an
            // asynchronous call and the calling activity is notified with a
            // callback on PeerListListener.onPeersAvailable()
            if (manager != null) {
                manager.requestPeers(channel, myPeerListListener);
            }
        } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
            // Respond to new connection or disconnections
        } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
            // Respond to this device's wifi state changing
        }
    }
}

Then in your activity add the following:

WifiP2pManager mManager;
Channel mChannel;
BroadcastReceiver mReceiver;
...
@Override
protected void onCreate(Bundle savedInstanceState){
    ...
    mManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
    mChannel = mManager.initialize(this, getMainLooper(), null);
    Receiver = new WiFiDirectBroadcastReceiver(manager, channel, this);
 
    mIntentFilter = new IntentFilter();
    mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
    mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
    mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
    mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
    ...
}

Don’t forget to register and unregister the receiver in onResume() and onPause().

This is the first part you have to do, after this you can use the WifiP2pManager to discover peers and to connect to them.
This is done with the following code to discover peers:

manager.discoverPeers(channel, new WifiP2pManager.ActionListener() {
    @Override
    public void onSuccess() {
        ...
    }
 
    @Override
    public void onFailure(int reasonCode) {
        ...
    }
});

And for connecting to peers with the following code:

//obtain a peer from the WifiP2pDeviceList
WifiP2pDevice device;
WifiP2pConfig config = new WifiP2pConfig();
config.deviceAddress = device.deviceAddress;
manager.connect(channel, config, new ActionListener() {
 
    @Override
    public void onSuccess() {
        //success logic
    }
 
    @Override
    public void onFailure(int reason) {
        //failure logic
    }
});

We hope these tips and tricks will help you to start with WiFi Direct on Android.

Kind regards,
PullesSon – Android

Updated: Let Me Android That For You

Hi App-users,

We are proud to announce an update on Let Me Android That For You.

Now you can change the LMGTFY options from the menu. You can chance the the language of the result page of LMGTFY and also select some Google Apps, like Maps, Finance and Images.

Have fun with it.

Kind regards,
PullesSon – Android.

Tips & Tricks: Screen sizes

Hi Android developers,

Last week was hectic, we needed to reinstall and reconfigure the backend server of Perka’s File stash.

This week we will take a little twist and we will talk about a topic that is more focused on design: Screen sizes.

When designing Android apps the best practice is to use Density-independent pixel (dp) as measure. A dp is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a “medium” density screen. At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160).

Another best practice is to use wrap_content and fill_parent in XML so the layout will scale automagically. Also a RelativeLayout is a good practice, it will keep the distances the same even if the screen is bigger or smaller.

Also keep in mind of using layout and orientation qualifiers, which can be added to the /res/ directory. This will make it easy to make to make a different layout for another screen size and/or orientation.

For images used in for the different screens, you might want to use draw9patch to make image.9.png files. These files are processed by the tool and you can assign how it will be stretched.

Another good practice is to use Fragments, this will allow you to reuse designs in different layouts. You can combine the fragments in a layout or just use 1 fragment as layout.

Extended information can be found at: Supporting Multiple Screen Sizes and Android Training Multiscreen

Kind regards,
PullesSon – Android