vendredi 29 mai 2015

Send data and wait for the answers with the Wearable Data Layer API

I have a wearable device from which data is sent to a handheld device wrapped in a DataMap object. On the handheld device I implemented a listener service that extends WearableListenerService implemented in this way:

public class ListenerService extends WearableListenerService {
    private static final String TAG = ListenerService.class.toString();

    private static final String WEARABLE_DATA_PATH = "/wearable_data";

    @Override
    public void onDataChanged(DataEventBuffer dataEvents) {
        DataMap dataMap;

        for (DataEvent event : dataEvents) {
            if (event.getType() == DataEvent.TYPE_CHANGED) {
                String path = event.getDataItem().getUri().getPath();

                if (path.equals(WEARABLE_DATA_PATH)) {
                    dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();

                    messageReceived(dataMap);
                }
            }
        }
    }

    private void messageReceived(DataMap dataMap) {
        Log.v(TAG, "DataMap received on handheld device: " + dataMap);
    }
}

The transmission from wearable to handheld works flawlessly. However, I would need to send back from handheld to wearable an answer, like "ok done" or "error xxx". How can I do that?

Android: Magnetometer data deviates

I am trying to estimate heading from the accelerometer, gyro and magnetometer data. I have implemented A Complementary Filter from here.

What I am trying is that I am holding the phone in my hand and I walked 15 steps in a straight line and I am trying to estimate Euler angles as given in the link above. But when I plot the raw data, I observe that the magnetometer data deviates. Here are the images of raw sensor data.

enter image description here

enter image description here

enter image description here

My question is: how do I estimate Euler angles so that they indicate I am walking in straight line.

OnClick / OnTouch user changing their mind

I am currently experimenting with onclick listeners and on on touch listeners.

I found out that using a onclick the app will always execute the action even if the user drags his/her finger off of the element. but i wanted the user to be able to change his mind and drag his/her finger off of the element so that it won't execute the action. i managed to do this with on touch.

on touch code :

action_bar_group_info.setOnTouchListener(new View.OnTouchListener() {
        int [] location = new int[4];
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            location[0] = action_bar_group_info.getLeft();
            location[1] = action_bar_group_info.getTop();
            location[2] = action_bar_group_info.getBottom();
            location[3] = action_bar_group_info.getRight();

            Log.v("Location: ", "top: "+String.valueOf(location[1]) + " left: "+String.valueOf(location[0]) + " right: "+String.valueOf(location[3]) + " bottom: "+String.valueOf(location[2]));
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                action_bar_group_info.setBackgroundColor(Color.parseColor("#ec9169"));
                return true;
            }
            if (event.getAction() == MotionEvent.ACTION_UP) {
                if ((int) event.getX() > location[0] && (int) event.getX() < location[3] && (int) event.getY() > location[1] && (int) event.getY() < location[2]) {
                    action_bar_group_info.setBackgroundColor(Color.parseColor("#ec9169"));
                    Intent intent = new Intent(mContext, GroupInformation.class);
                    intent.putExtra("gid", gid);
                    intent.putExtra("gname", gname);
                    intent.putExtra("image", img);
                    intent.putExtra("uid", uid);
                    startActivity(intent);
                    finish();
                }else {
                    action_bar_group_info.setBackgroundColor(Color.parseColor("#f54c00"));
                }
            }
            if(event.getAction() == MotionEvent.ACTION_MOVE){
                Log.v("Location pointer: x:"+ String.valueOf((int) event.getX())," Y: "+ String.valueOf((int) event.getY()));
                if ((int) event.getX() < location[0] || (int) event.getX() > location[3] || (int) event.getY() < location[1] || (int) event.getY() > location[2]) {
                    action_bar_group_info.setBackgroundColor(Color.parseColor("#f54c00"));
                }
            }

            return false;
        }
    });

But is this really the way to do it isn't there a easier way to achieve what i want?

action_bar_group_info is a linear layout.

System application in Android

How exactly Android determines if an application is a system application with root privilege?

I know that for such applications, ApplicationInfo.FLAG_SYSTEM will be enabled, and those applications must declare shared user id as "android.uid.system" in their Manifest file. Along with that there is another criteria, where an application located in /system/app should also be treated as System application.

I searched the source code for PackageMangerService.java in AOSP where I observed that if shared user id is android.uid.system then the application is assigned the flag as FLAG_SYSTEM.

But I guess, the applications which are available in /system/app do not contain the shared user id as android.uid.system then how do they get this flag FLAG_SYSTEM enabled for them?

Status of multicast on Android devices as on 2015

Multicast support on Android is Version specific ? Most of new age devices will come with 4.3 & above. So MulticastSocket API work on 4.3 & above ? Is multicast support is device/OEM specific ?

Wanted to know exact status whether Multicast on Android is supported as on May15 ?

Referred number of posts but it is not clear

http://ift.tt/1JbK4l6

Multicast RTP on Android 4.0+

Problem with MulticastSocket on Java-Android

http://ift.tt/1FHCf4p

http://ift.tt/1y1QFaX

http://ift.tt/1FHCdcz

How to receive Multicast packets on Android

Problem with Android Multicast Sockets

Android, how to use the Accelerometer Sensors?

can someone help me understand the Accelerometer Sensor. I've read this and this overviews about the sensors and the motion sensor but i can't understand which movement triggers which sensor, (for an example the Sensor TYPE_ACCELEROMETER and Sensor event data SensorEvent.values[0] means Acceleration force along the x axis (including gravity).) what does that mean? which motion is it? So if anyone can help me, please all I want to know is to check if the phone is on a landscape orientation and standing vertically, and when the phone gets tilted to the front or backward. these are the 3 movements that I want to know, thanks

Hi I am woring for a Quiz App, so I need to call post rest services(json),below one is my sample code which is not working

I need to pass 3 thing as parameter 1-userid, 2-List questionids and 3- List answerIds. My Question is how to pass List Object not String or Json String here-

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("userid", "121213"));
    nameValuePairs.add(new BasicNameValuePair("questionsids", listobj);
    nameValuePairs.add(new BasicNameValuePair("answerIds", listObj));

    HttpClient httpclient=new DefaultHttpClient();
    HttpPost httppost = new HttpPost(url);
    httppost.setHeader(HTTP.CONTENT_TYPE,"application/x-www-form-urlencoded;charset=UTF-8");

    try {
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

Is There any other way to call the post rest service.How to resolve above one?

Thanks Ranjan.