Use your Android Wear device with an iPhone...

Get your Android Wear device to work cross-platform without hacking...



One of the major problems in the ongoing battle between Apple and Android is the lack of cross-platform integration. Once you’ve committed to one operating system, it becomes very diffi cult to move over as so much of your data, such as your music and photos, refuses to transfer across to the rival platform. Wearables have added another dimension to this issue as an iPhone user may want an Android smartwatch, but then they would not be able to use it with their phone. However, iPhone users can now use some basic functions on their Android Wear device thanks to two new apps. This tutorial will require you to use both an Android and Apple handset in the setup, but after that your smartwatch should be able to sync up with either of your phones. This tutorial will show you how to use both the BLE Utility app and the ‘Aerlink: Wear Connect for iOS’ app in order to turn your Android-only smartwatch into a device that can work with both Android and Apple handsets, giving you many more interesting options for your smartwatch.

1. Download relevant apps.


Download ‘Aerlink: Wear Connect for iOS’ onto your Android phone. It will appear as ‘Aerlink’ on your handset and smartwatch. Download BLE Utility on an iPhone.

2. Locate the Aerlink app


You should already have the Android Wear
app downloaded and your watch synced with your Android phone. Next, tap on the watch’s homescreen where you will see the Aerlink app.

3. Activate iOS Service



Click the app. On the next screen, you will
see a toggle for iOS Service. The slider will be grey; tap it to turn it blue. Your phone will now be able to see and pair with Apple handsets via Bluetooth.

4. Open BLE Utility



BLE Utility fi nds devices that use Bluetooth
Low Energy. Without this, the iPhone still couldn’t locate the watch. Once the app has loaded, tap on Peripheral. This is where the watch will appear.

5. Search for iPhone

Once you had moved the slider, the watch should have told you it had disconnected –this is part of the plan. Tap the magnifying glass icon and it will search for compatible devices to pair with.


6. Pair the phone

When the watch and the phone find each other, this box should appear. Look on the watch’s screen for the code then type in the vacant box. Pairing with an Android phone is a bit simpler.

[MT6582] Flyme OS 4.5.4.1R for H870


Flyme Os 4.5.4.1
Android 5.1.1
CyanogenMod 12.1





2 sim
Hotspot
wifi
gps
ussd(Maybe)

Bug: stock front camera

DOWNLOAD : flyme_4.5.4.1R_H870.zip

Credit: Coolpad devs 



Free book: Linux From Scratch (LFS)

Linux From Scratch (LFS) is a project that provides you with step-by-step instructions for building your own customized Linux system entirely from source.

You may download the stable book in various formats from the stable book directory.

Freecharge– Get Rs.60 cashback on Rs.50 recharge or bill payment.....

Even after they are running so many cashback offers already, they have now sent 120% cashback codes to their customer’s email address and phones.So just check your inbox and grab your Rs 60 cashback on Rs 50+ recharge now.......

Verify if you have got any message or email on your registered mobile and email address. Just give it a try and if you are lucky you may succeed.
How to get the cashback on freecharge ?
1.Download freecharge app –Android -Use my promocode  RU3W7JI
 I iOS I Windows
2. Sign in /Register
3. Enter mobile number
4. Enter the amount & Apply coupon code –“M50
5.Complete payment using debit/Credit card
6.That’s it. You will receive Rs 60 cashback within 24 hours.
Terms and Conditions-
Valid on all Successful Recharges/ Bill Payments till 30th November 2015.
Promocode can be redeemed only through specific accounts those who got SMS or E-mail regarding this offer.
Valid on min. transaction of Rs.50 & max cashback of Rs.60.
Promocode has to be applied to avail cashback offer.
Valid only once per user/credit/debit card.
Cashback to be offered in the form of EGV which can be redeemed in the next 6 months.
Not valid on transactions done via FreeCharge Balance and Netbanking.
Offer valid on FreeCharge App, Web & mWeb.
Offer not valid for Airtel transactions.

RecyclerView + CardView example: with Button


This example work on last example of "Gallery-like RecyclerView + CardView example" to show how to add a button and OnClickListener in RecyclerView + CardView. A ImageButton is add over the photo on each cell. Once user click on the ImageButton, the corresponding OnClickListener, to show the info of the corresponding photo.


Modify layout/layout_cardview.xml to add a ImageButton.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
card_view:cardCornerRadius="5sp"
card_view:cardElevation="5sp">

<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
android:id="@+id/item_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageButton
android:id="@+id/buttonInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/ic_menu_info_details"
android:background="#00ffffff"/>


</FrameLayout>
</android.support.v7.widget.CardView>


Modify MyRecyclerViewAdapter.java:
- get the reference to the Button in the constructor of RecyclerView.ViewHolder.
- implement the OnClickListener in onBindViewHolder() of MyRecyclerViewAdapter.
package com.blogspot.android_er.androidgallery;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

public class MyRecyclerViewAdapter extends RecyclerView.Adapter<MyRecyclerViewAdapter.ItemHolder>{

private List<Uri> itemsUri;
private LayoutInflater layoutInflater;
private Context context;
private OnItemClickListener onItemClickListener;
MainActivity mainActivity;

public MyRecyclerViewAdapter(Context context, MainActivity mainActivity){
this.context = context;
layoutInflater = LayoutInflater.from(context);
itemsUri = new ArrayList<Uri>();

this.mainActivity = mainActivity;
}

@Override
public MyRecyclerViewAdapter.ItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
CardView itemCardView = (CardView)layoutInflater.inflate(R.layout.layout_cardview, parent, false);
return new ItemHolder(itemCardView, this);
}

@Override
public void onBindViewHolder(MyRecyclerViewAdapter.ItemHolder holder, final int position) {
final Uri targetUri = itemsUri.get(position);
holder.setItemUri(targetUri.getPath());

if (targetUri != null){

try {
//! CAUTION !
//I'm not sure is it properly to load bitmap here!
holder.setImageView(loadScaledBitmap(targetUri));

holder.btnInfo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context,
"btnInfo clicked:\n"
+ "position:" + position + "\n"
+ targetUri.getLastPathSegment(),
Toast.LENGTH_LONG).show();
}
});


} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}

/*
reference:
Load scaled bitmap
http://android-er.blogspot.com/2013/08/load-scaled-bitmap.html
*/
private Bitmap loadScaledBitmap(Uri src) throws FileNotFoundException {

//display the file to be loadScaledBitmap(),
//such that you can know how much work on it.
mainActivity.textInfo.append(src.getLastPathSegment() + "\n");

// required max width/height
final int REQ_WIDTH = 150;
final int REQ_HEIGHT = 150;

Bitmap bm = null;

// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(context.getContentResolver().openInputStream(src),
null, options);

// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, REQ_WIDTH,
REQ_HEIGHT);

// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
bm = BitmapFactory.decodeStream(
context.getContentResolver().openInputStream(src), null, options);

return bm;
}

public int calculateInSampleSize(BitmapFactory.Options options,
int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;

if (height > reqHeight || width > reqWidth) {

// Calculate ratios of height and width to requested height and
// width
final int heightRatio = Math.round((float) height
/ (float) reqHeight);
final int widthRatio = Math.round((float) width / (float) reqWidth);

// Choose the smallest ratio as inSampleSize value, this will
// guarantee
// a final image with both dimensions larger than or equal to the
// requested height and width.
inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
}

return inSampleSize;
}

@Override
public int getItemCount() {
return itemsUri.size();
}

public void setOnItemClickListener(OnItemClickListener listener){
onItemClickListener = listener;
}

public OnItemClickListener getOnItemClickListener(){
return onItemClickListener;
}

public interface OnItemClickListener{
public void onItemClick(ItemHolder item, int position);
}

public void add(int location, Uri iUri){
itemsUri.add(location, iUri);
notifyItemInserted(location);
}

public void clearAll(){
int itemCount = itemsUri.size();

if(itemCount>0){
itemsUri.clear();
notifyItemRangeRemoved(0, itemCount);
}
}


public static class ItemHolder extends RecyclerView.ViewHolder implements View.OnClickListener{

private MyRecyclerViewAdapter parent;
private CardView cardView;
ImageView imageView;
String itemUri;

ImageButton btnInfo;

public ItemHolder(CardView cardView, MyRecyclerViewAdapter parent) {
super(cardView);
itemView.setOnClickListener(this);
this.cardView = cardView;
this.parent = parent;
imageView = (ImageView) cardView.findViewById(R.id.item_image);
btnInfo = (ImageButton) cardView.findViewById(R.id.buttonInfo);
}

public void setItemUri(String itemUri){
this.itemUri = itemUri;
}

public String getItemUri(){
return itemUri;
}

public void setImageView(Bitmap bitmap){
imageView.setImageBitmap(bitmap);
}

@Override
public void onClick(View v) {
final OnItemClickListener listener = parent.getOnItemClickListener();
if(listener != null){
listener.onItemClick(this, getLayoutPosition());
//or use
//listener.onItemClick(this, getAdapterPosition());
}
}
}
}




~ More example of RecyclerView + CardView.


Add and Remove view dynamically, another approach

Last post show a example of "Add and Remove view dynamically", each Remove Button have its own OnClickListener object, each OnClickListener object refer to a specified view.


It's another approach: all Remove Buttons share a common OnClickListener object. Inside the OnClickListener, retrieve the associate addView from the trigger view by calling its getParent() method.


MainActivity.java
package com.blogspot.android_er.androiddynamicview;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.method.ScrollingMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

EditText textIn;
Button buttonAdd;
LinearLayout container;
TextView reList, info;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

textIn = (EditText)findViewById(R.id.textin);
buttonAdd = (Button)findViewById(R.id.add);
container = (LinearLayout)findViewById(R.id.container);
reList = (TextView)findViewById(R.id.relist);
info = (TextView)findViewById(R.id.info);
info.setMovementMethod(new ScrollingMovementMethod());

buttonAdd.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
LayoutInflater layoutInflater =
(LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View addView = layoutInflater.inflate(R.layout.row, null);
TextView textOut = (TextView)addView.findViewById(R.id.textout);
textOut.setText(textIn.getText().toString());
Button buttonRemove = (Button)addView.findViewById(R.id.remove);
/*
final View.OnClickListener thisListener = new View.OnClickListener(){
@Override
public void onClick(View v) {
info.append("thisListener called:\t" + this + "\n");
info.append("Remove addView: " + addView + "\n\n");
((LinearLayout)addView.getParent()).removeView(addView);

listAllAddView();
}
};

buttonRemove.setOnClickListener(thisListener);
container.addView(addView);

info.append(
"thisListener:\t" + thisListener + "\n"
+ "addView:\t" + addView + "\n\n"
);
*/


buttonRemove.setOnClickListener(commonRemoveOnClickListener);
container.addView(addView);
info.append(
"CommonRemoveOnClickListener:\t" + commonRemoveOnClickListener + "\n"
+ "addView:\t" + addView + "\n"
+ "buttonRemove:\t" + buttonRemove + "\n\n");

listAllAddView();

}
});
}

private void listAllAddView(){
reList.setText("");

int childCount = container.getChildCount();
for(int i=0; i<childCount; i++){
View thisChild = container.getChildAt(i);
reList.append(thisChild + "\n");
}
}

View.OnClickListener commonRemoveOnClickListener = new View.OnClickListener(){
@Override
public void onClick(View v) {
info.append("this View clicked:\t" + v + "\n");
info.append("this Listener called:\t" + this + "\n");
View thisParentView = (View) v.getParent();
info.append("Remove thisParentView: " + thisParentView + "\n\n");
((LinearLayout)thisParentView.getParent()).removeView(thisParentView);

listAllAddView();
}
};

}


activity_main.xml and row.xml, refer to last post "Add and Remove view dynamically, keep track of child views".

Add and Remove view dynamically, keep track of child views

I have a old example of "Add and Remove view dynamically". Somebody ask how the Remove button keep track of the views. So I modify the example to explain in more details.


In this example, when user click on the Add button, it will create a child View, addView. The addView have a Button, buttonRemove. The buttonRemove have its own OnClickListener object. The OnClickListener object refer to the specified addView when it is created.

That means the OnClickListener object of the buttonRemove in the first child view("abc") not the same object in the second child view("abcdef"), not the same object in the third child view("abcdefghi")...All have its own individual OnClickListener object. And each OnClickListener object refer to a specified addView object. Such that it can keep track of the child Views, addView.


MainActivity.java
package com.blogspot.android_er.androiddynamicview;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.method.ScrollingMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

EditText textIn;
Button buttonAdd;
LinearLayout container;
TextView reList, info;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

textIn = (EditText)findViewById(R.id.textin);
buttonAdd = (Button)findViewById(R.id.add);
container = (LinearLayout)findViewById(R.id.container);
reList = (TextView)findViewById(R.id.relist);
info = (TextView)findViewById(R.id.info);
info.setMovementMethod(new ScrollingMovementMethod());

buttonAdd.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
LayoutInflater layoutInflater =
(LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View addView = layoutInflater.inflate(R.layout.row, null);
TextView textOut = (TextView)addView.findViewById(R.id.textout);
textOut.setText(textIn.getText().toString());
Button buttonRemove = (Button)addView.findViewById(R.id.remove);

final View.OnClickListener thisListener = new View.OnClickListener(){
@Override
public void onClick(View v) {
info.append("thisListener called:\t" + this + "\n");
info.append("Remove addView: " + addView + "\n\n");
((LinearLayout)addView.getParent()).removeView(addView);

listAllAddView();
}
};

buttonRemove.setOnClickListener(thisListener);
container.addView(addView);

info.append(
"thisListener:\t" + thisListener + "\n"
+ "addView:\t" + addView + "\n\n"
);

listAllAddView();
}
});
}

private void listAllAddView(){
reList.setText("");

int childCount = container.getChildCount();
for(int i=0; i<childCount; i++){
View thisChild = container.getChildAt(i);
reList.append(thisChild + "\n");
}
}
}


layout/activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="16dp"
tools:context="com.blogspot.android_er.androiddynamicview.MainActivity">


<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<Button
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Add" />

<EditText
android:id="@+id/textin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@id/add" />
</RelativeLayout>

<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"></LinearLayout>

</LinearLayout>

<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:autoLink="web"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold" />

<TextView
android:id="@+id/relist"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:textStyle="bold"
android:background="#E0E0E0"/>
<TextView
android:id="@+id/info"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:textStyle="italic"
android:background="#D0D0D0"
android:gravity="bottom"/>

</LinearLayout>
</LinearLayout>


layout/row.xml, the layout of the child views.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/remove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Remove"/>
<TextView
android:id="@+id/textout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@id/remove"/>
</RelativeLayout>


download filesDownload the files (Android Studio Format) .

It's another approach to share a common OnClickListener between all buttonRemove.

more:
Add and Remove view dynamically, with EditText/AutoCompleteTextView inside

100 Times Fastest Technology In Networking is "LiFi":- Tests Prove

With speeds of 1GBps, the technology could enable a high-definition film to be downloaded in seconds



What is LiFi Then:-

LiFi is a disruptive technology which will shift business models and create opportunities ripe for
exploitation. The dominance and lifetime of LED lighting has created a need for new business models in the lighting industry. The need to offer services, including new payment and financing models, creates an unprecedented opportunity for LiFi.



Test Results: Li-Fi is 100 times Faster than Wi-Fi

An Estonian startup company called Velmenni took the technology out of the laboratories and into the real-world offices, and industrial environments in Tallinn for the first time and, believe me, it's really, really fast.


"We are doing a few pilot projects in different industries where we can utilize the VLC technology,"Velmenni's CEO Deepak Solanki told IBTimes UK.
"Currently we have designed a smart lighting solution for an industrial environment where the data communication is done through the light. We're also doing a pilot project with a private client where we're setting up a Li-Fi network to access the Internet in [our] office space."
 Who Invented Li-Fi ?

Li-Fi technology was originated in 2011 by Professor Harald Haas of the University of Edinburgh, who demonstrated that, with a flickering light from a single LED, he could transmit more data than a cellular tower. Professor Haas, delivered a TED talk about his technology in 2011, which has attracted more than 1.7 million views.




[MT6582] Miui 7.0.2.0 - Stable for TRUE SMART 5.0 SLIM


ROM OS Version: 4.4.x KitKat
ROM Kernel: Linux 3.4.x


Features

1.SIM 2 3G WORKING. NOW ITS DUAL 3G - FIRST FOR MT6582

[Credits to Mr.deliopoulos-for making it & Mr.Ondipuli-for informing us about that patch]
2. Beautiful MIUI 7 - Muitilang
3. Online themes,wallpapers,ringtones,etc..
4. More Battery Efficient,Smooth
5. Extra Reboot Menu Mod
6. Modded dialer , settings , In Call UI and new File manager
7. Good Camera Quality
8. All Unwanted/chinese MIUI apps Removed
9. Play Store working





HOW TO FLASH:
1. boot to custom recovery(CWM,Philz,TWRP)
2. Factory reset
3. Install from zip > select ROM file > OK
4. reboot
5. Enjoy







Credit:  
Tran Tien XDA Dev
Team TMTT Porting


YU Testing YU6000, expected to be Yuphoria successor

YU YU6000 appears in GFXBench database, specifications revealed

YU YU6000 appears in GFXBench database, specifications revealed

YU YU6000 specs in GFXBench database

YU a Micromax subsidiary which is yet to complete one year of it's launch is planning ahead very seriously. Their upcoming device YU Yutopia (YU5050) is yet to launch but YU is already testing a new device YU6000 expected to be  YU Yuphoria's successor.

The device's specifications were revealed on GFXBench a graphics benchmark. The device listed was running on SoC: MediaTek MT6753 octa core CPU @1.5GHz a deviation from all Qualcomm Snapdragon based devices from YU. It houses 3GB RAM with 16 GB ROM. The camera listed is 12 MP rear with 7 MP front snapper which could easily be 13MP/8MP combo. It will have 4.6" FHD screen. The device comes with usual set of sensors. 

It looks pretty good on paper as Yuphoria successor if they price it similar to Yuphoria which was launched with initial price tag of ₹6,999. MediaTek MT6753 which is equivalent to Snapdragon 615.
However we do advise you to take this with a pinch of salt as the tests can easily be fooled.

socket.getInetAddress() return null on Android 5

Refer to last example of "Simple HTTP server running on Android", it work on Xiaomi Redmi 2 running Android 4.4.4. But somebody report program stopped on Android 5 devices. So I re-test on Nexus 7 running Android 5.1.1. Yes, the app crash! caused by NullPointerException, because socket.getInetAddress() return null.


Modify MainActivity.java to capture socket.getInetAddress() before and after close():
package com.blogspot.android_er.androidhttpserver;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.EditText;
import android.widget.TextView;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.util.Enumeration;

public class MainActivity extends AppCompatActivity {

EditText welcomeMsg;
TextView infoIp;
TextView infoMsg;
String msgLog = "";

ServerSocket httpServerSocket;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

welcomeMsg = (EditText) findViewById(R.id.welcomemsg);
infoIp = (TextView) findViewById(R.id.infoip);
infoMsg = (TextView) findViewById(R.id.msg);

infoIp.setText(getIpAddress() + ":"
+ HttpServerThread.HttpServerPORT + "\n");

HttpServerThread httpServerThread = new HttpServerThread();
httpServerThread.start();
}

@Override
protected void onDestroy() {
super.onDestroy();

if (httpServerSocket != null) {
try {
httpServerSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

private String getIpAddress() {
String ip = "";
try {
Enumeration<NetworkInterface> enumNetworkInterfaces = NetworkInterface
.getNetworkInterfaces();
while (enumNetworkInterfaces.hasMoreElements()) {
NetworkInterface networkInterface = enumNetworkInterfaces
.nextElement();
Enumeration<InetAddress> enumInetAddress = networkInterface
.getInetAddresses();
while (enumInetAddress.hasMoreElements()) {
InetAddress inetAddress = enumInetAddress.nextElement();

if (inetAddress.isSiteLocalAddress()) {
ip += "SiteLocalAddress: "
+ inetAddress.getHostAddress() + "\n";
}

}

}

} catch (SocketException e) {
// TODO Auto-generated catch block
e.printStackTrace();
ip += "Something Wrong! " + e.toString() + "\n";
}

return ip;
}

private class HttpServerThread extends Thread {

static final int HttpServerPORT = 8888;

@Override
public void run() {
Socket socket = null;

try {
httpServerSocket = new ServerSocket(HttpServerPORT);

while(true){
socket = httpServerSocket.accept();

HttpResponseThread httpResponseThread =
new HttpResponseThread(
socket,
welcomeMsg.getText().toString());
httpResponseThread.start();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}

private class HttpResponseThread extends Thread {

Socket socket;
String h1;

HttpResponseThread(Socket socket, String msg){
this.socket = socket;
h1 = msg;
}

@Override
public void run() {
BufferedReader is;
PrintWriter os;
String request;

try {
is = new BufferedReader(new InputStreamReader(socket.getInputStream()));
request = is.readLine();

os = new PrintWriter(socket.getOutputStream(), true);

String response =
"<html><head></head>" +
"<body>" +
"<h1>" + h1 + "</h1>" +
"</body></html>";

os.print("HTTP/1.0 200" + "\r\n");
os.print("Content type: text/html" + "\r\n");
os.print("Content length: " + response.length() + "\r\n");
os.print("\r\n");
os.print(response + "\r\n");
os.flush();
InetAddress clientInetAddressBeforeClose = socket.getInetAddress();
socket.close();
InetAddress clientInetAddressAfterClose = socket.getInetAddress();

msgLog += "Request: " + request + "\n";

if(clientInetAddressBeforeClose == null){
msgLog += "clientInetAddressBeforeClose == null\n";
}else{
msgLog += "clientInetAddressBeforeClose = " + clientInetAddressBeforeClose.toString() + "\n";
}

if(clientInetAddressAfterClose == null){
msgLog += "clientInetAddressAfterClose == null\n";
}else{
msgLog += "clientInetAddressAfterClose = " + clientInetAddressAfterClose.toString() + "\n";
}


MainActivity.this.runOnUiThread(new Runnable() {

@Override
public void run() {

infoMsg.setText(msgLog);
}
});

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return;
}
}
}


It's found that on Xiaomi Redmi 2 running Android 4.4.4, socket.getInetAddress() keep no change before and after close().


But on Nexus 7 running Android 5.1.1, change to null after close().


So, we have to read socket.getInetAddress() before close().

Simple HTTP server running on Android

It's my old exercise "Implement simple HTTP server running on Android". Somebody report it's not work, so I re-try it on Android Studio. Actually the code is same as before, and work as expected. Please notice both the server and client have to connect in the same WiFi network.


Updated@2015-11-26:
This code NOT work on Android 5, may be all 5+ version.
Fixed, refer next post "socket.getInetAddress() return null on Android 5".


Work on Xiaomi Redmi 2, running Android 4.4.4


MainActivity.java
package com.blogspot.android_er.androidhttpserver;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.EditText;
import android.widget.TextView;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.util.Enumeration;

public class MainActivity extends AppCompatActivity {

EditText welcomeMsg;
TextView infoIp;
TextView infoMsg;
String msgLog = "";

ServerSocket httpServerSocket;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

welcomeMsg = (EditText) findViewById(R.id.welcomemsg);
infoIp = (TextView) findViewById(R.id.infoip);
infoMsg = (TextView) findViewById(R.id.msg);

infoIp.setText(getIpAddress() + ":"
+ HttpServerThread.HttpServerPORT + "\n");

HttpServerThread httpServerThread = new HttpServerThread();
httpServerThread.start();
}

@Override
protected void onDestroy() {
super.onDestroy();

if (httpServerSocket != null) {
try {
httpServerSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

private String getIpAddress() {
String ip = "";
try {
Enumeration<NetworkInterface> enumNetworkInterfaces = NetworkInterface
.getNetworkInterfaces();
while (enumNetworkInterfaces.hasMoreElements()) {
NetworkInterface networkInterface = enumNetworkInterfaces
.nextElement();
Enumeration<InetAddress> enumInetAddress = networkInterface
.getInetAddresses();
while (enumInetAddress.hasMoreElements()) {
InetAddress inetAddress = enumInetAddress.nextElement();

if (inetAddress.isSiteLocalAddress()) {
ip += "SiteLocalAddress: "
+ inetAddress.getHostAddress() + "\n";
}

}

}

} catch (SocketException e) {
// TODO Auto-generated catch block
e.printStackTrace();
ip += "Something Wrong! " + e.toString() + "\n";
}

return ip;
}

private class HttpServerThread extends Thread {

static final int HttpServerPORT = 8888;

@Override
public void run() {
Socket socket = null;

try {
httpServerSocket = new ServerSocket(HttpServerPORT);

while(true){
socket = httpServerSocket.accept();

HttpResponseThread httpResponseThread =
new HttpResponseThread(
socket,
welcomeMsg.getText().toString());
httpResponseThread.start();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}

private class HttpResponseThread extends Thread {

Socket socket;
String h1;

HttpResponseThread(Socket socket, String msg){
this.socket = socket;
h1 = msg;
}

@Override
public void run() {
BufferedReader is;
PrintWriter os;
String request;

try {
is = new BufferedReader(new InputStreamReader(socket.getInputStream()));
request = is.readLine();

os = new PrintWriter(socket.getOutputStream(), true);

String response =
"<html><head></head>" +
"<body>" +
"<h1>" + h1 + "</h1>" +
"</body></html>";

os.print("HTTP/1.0 200" + "\r\n");
os.print("Content type: text/html" + "\r\n");
os.print("Content length: " + response.length() + "\r\n");
os.print("\r\n");
os.print(response + "\r\n");
os.flush();
socket.close();

msgLog += "Request of " + request
+ " from " + socket.getInetAddress().toString() + "\n";
MainActivity.this.runOnUiThread(new Runnable() {

@Override
public void run() {

infoMsg.setText(msgLog);
}
});

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return;
}
}
}


layout/activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:orientation="vertical"
tools:context="com.blogspot.android_er.androidhttpserver.MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:autoLink="web"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold" />

<EditText
android:id="@+id/welcomemsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Welcome from Android-er" />

<TextView
android:id="@+id/infoip"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >

<TextView
android:id="@+id/msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</ScrollView>
</LinearLayout>


Permission of "android.permission.INTERNET" is needed in AndroidManifest.xml.

download filesDownload the files (Android Studio Format) .

Introducing Visual Studio Dev Essentials

Visual Studio Dev Essentials is a new free developer offering from Microsoft. A free membership to this program gives you access to a range of benefits including developer tools and services, training and support. This video provides an overview of some key benefits, including Visual Studio Community, Visual Studio Team Services, Pluralsight training, and HackHands live programming help. You'll also learn the easiest way to get started and activate your benefits.


Join now at http://aka.ms/devessentials.

Google Search Easter egg for Star Wars - A Long Time Ago in a Galaxy Far Far Away


Search "A Long Time Ago in a Galaxy Far Far Away" in Google.


Download and run Android Studio 2.0 Preview on Windows 10


This video show how to download and run Android Studio 2.0 Preview from Canary Channel‎, in parallel with existing installed Android Studio 1.5.
(The Emulator is seem still the old version, not the New Android Emulator)

reference: Android Developers Blog announcement


Related: Install Android Studio 2.0 Preview on Ubuntu Linux, parallel with existing installed Android Studio


Windows 10: add Administrator account in login screen

To add Administrator account in login screen:

  • Run Command Prompt as Administrator
  • Enter the command:
    net user administrator /active:yes





Generate Power Efficiency Diagnostics Report for Windows 10


To generate Power Efficiency Diagnostics Report for Windows 10:
  • Run Command Prompt as Administrator
  • Enter the command: powercfg -energy -output C:\report.html
  • After report generated, you can see C:\report.html for details.


Windows 10 Power User Menu

Power User Menu of  Windows 10 (and Windows 8) is a pop-up menu with shortcuts tosome usedful "Power User" Windows tools. You can easy access the "Old Control Panel" here.


To Open Power User Menu,

  • Right click the Start button, or 
  • WIN+X: Pressing the WIN (Windows) key and the 'X' key together.


Android SDK Platform Android 6.0 revision 2


Install Android Studio 2.0 Preview on Ubuntu Linux, parallel with existing installed Android Studio


Android Studio 2.0 Preview is available to download in Canary Channel now. This video show how to download and run in Ubuntu (Ubuntu-GNOME 15.10 on VirtualBox/Windows 10), in parallel with existing installed Android Studio 1.5.


(reference: Android Developers Blog)

Related:
Download and run Android Studio 2.0 Preview on Windows 10

Lybrate-Free advice for your Health Problems from Top Doctors

Are you or your any relative are facing any health diseases? Do you want to take some useful advice from India’s top class Doctors without paying anything?  



Lybrate is a online website who provides free consultation advice to their customers by the top doctors of india.


2-Login / Sign Up

3-Enter your Question about Health diseases in “Your Question” section. You can ask question for yourself or anybody else.

4- Enter Your E-Mail id.

5- Click on “Ask Question Now”

6- Answers will be sent to your E-mail id.

Google's interactive StarWars page

Visit google.com/starwars and choose your side.



YU Yunique CyanogenMod Nightlies are Now Available to Install

Install CyanogenMod on YU Yunique now

YU Yunique CyanogenMod Nightlies are Now Available for install
CyanogenMod Nightlies for YU Yunique
YU Yunique launch few months ago in September with a price tag of  ₹4,999 was the first device from YU to come with Pure Android. It was strange given Cyanogen was the selling point of YU Televentures. However Yunique was promised a Cyanogen OS later for those who prefer customization and tinkering with their phone. But despite being more than two months since the launch of Yunique there's no release in sight which matches with the delayed release of Cyanogen OS 12.1 for Yureka, Yureka Plus and Yuphoria.

CyanogenMod community has once again beaten the Cyanogen and released the first build of CyanogenMod 12.1 for Yunique with a codename 'jalebi'. If you've been waiting for Cyanogen experience on your Yunique, you can go ahead and download the nightlies from the CM website here. Be warned though that this is not official and may contain bugs and/or missing features. So do check the build log before installing. 

If you'd like to know more about the CyanogenMod and differences between Cyanogen OS and CyanogenMod read this wiki here.

First YU Yutopia Camera Samples released

Sundeep Gujjar releases first Camera Samples for YU Yutopia



If you're not in the know YU has partnered with  MotoGrapher Sundeep Gajjar, who'll be testing the phone on his Europe Tour with BMW i8. In the five days journey he'll test and showcase Yutopia capability. Today he has dropped first and a major reveal. He posted a photo taken from soon to be launc YU powerhouse Yutopia (or YU5050). Here's the one selfie from Yutopia.

Sundeep Gujjar, Motographer releases first Camera Samples for YU Yutopia (YU5050)
YU Yutopia front camera sample
Sundeep Gujjar, Motographer releases first Camera Samples for YU Yutopia (YU5050)
YU Yutopia rear camera samples
He'll be revealing more about the device in the upcoming five days.We have already revealed the specifications of YU Yutopia which you check here. You can find more about Yutopia here.

Yutopia is an upcoming flagship from YU Televentures.