Example usage for android.os Message Message

List of usage examples for android.os Message Message

Introduction

In this page you can find the example usage for android.os Message Message.

Prototype

public Message() 

Source Link

Document

Constructor (but the preferred way to get a Message is to call #obtain() Message.obtain() ).

Usage

From source file:net.evecom.androidecssp.activity.taskresponse.TaskAddActivity.java

/**
 * //from   w ww .jav  a  2 s.  com
 * 
 * 
 * @author Mars zhang
 * @created 2015-11-25 2:06:28
 * @param entity
 */
private void postdata(final HashMap<String, String> entity) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            Message message = new Message();
            try {
                saveResult = connServerForResultPost("jfs/ecssp/mobile/taskresponseCtr/taskadd", entity);
            } catch (ClientProtocolException e) {
                message.what = MESSAGETYPE_02;
                Log.e("mars", e.getMessage());
            } catch (IOException e) {
                message.what = MESSAGETYPE_02;
                Log.e("mars", e.getMessage());
            }
            if (saveResult.length() > 0) {
                message.what = MESSAGETYPE_01;
            } else {
                message.what = MESSAGETYPE_02;
            }
            Log.v("mars", saveResult);
            saveHandler.sendMessage(message);
        }
    }).start();

}

From source file:com.baofeng.game.sdk.net.AsyncHttpPost.java

@Override
public void run() {
    String ret = "";
    try {//from   w  ww  .ja  va 2s. c  o m
        for (int i = 0; i < BFGameConfig.CONNECTION_COUNT; i++) {
            try {
                request = new HttpPost(url);

                request.addHeader("Accept-Encoding", "default");

                if (parameter != null && parameter.size() > 0) {
                    List<BasicNameValuePair> list = new ArrayList<BasicNameValuePair>();

                    for (RequestParameter p : parameter) {

                        list.add(new BasicNameValuePair(Util.encode(p.getName()), Util.encode(p.getValue())));
                        LogUtil.d("AsyncHttpPost Param ", p.getName() + " , " + p.getValue());

                    }
                    StringBuffer sb = new StringBuffer();
                    for (int j = 0; j < list.size(); j++) {
                        sb.append(list.get(j));
                        if (!(j == list.size() - 1)) {
                            sb.append("&");
                        }
                    }

                    BasicNameValuePair bn = new BasicNameValuePair("sign",
                            MD5Util.MD5(sb + "1234" + BFGameConfig.SERVERKEY));
                    //                  System.out.println("@@@" +  sb + "1234"
                    //                        + BFGameConfig.SERVERKEY);
                    list.add(bn);
                    ((HttpPost) request).setEntity(new UrlEncodedFormEntity(list, HTTP.UTF_8));

                }
                LogUtil.d("AsyncHttpPost : ", url);

                httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectTimeout);
                httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, readTimeout);
                HttpResponse response = httpClient.execute(request);
                int statusCode = response.getStatusLine().getStatusCode();
                if (statusCode == HttpStatus.SC_OK) {
                    // HttpManager.saveCookies(response);
                    InputStream is = response.getEntity().getContent();
                    BufferedInputStream bis = new BufferedInputStream(is);
                    bis.mark(2);
                    // ??
                    byte[] header = new byte[2];
                    int result = bis.read(header);
                    // reset??
                    bis.reset();
                    // ?GZIP?
                    int headerData = getShort(header);
                    // Gzip ? ? 0x1f8b
                    if (result != -1 && headerData == 0x1f8b) {
                        is = new GZIPInputStream(bis);
                    } else {
                        is = bis;
                    }
                    InputStreamReader reader = new InputStreamReader(is, "utf-8");
                    char[] data = new char[100];
                    int readSize;
                    StringBuffer sb = new StringBuffer();
                    while ((readSize = reader.read(data)) > 0) {
                        sb.append(data, 0, readSize);
                    }
                    ret = sb.toString();
                    bis.close();
                    reader.close();

                } else {
                    RequestException exception = new RequestException(RequestException.IO_EXCEPTION,
                            "??,??" + statusCode);
                    ret = ErrorUtil.errorJson("-1", exception.getMessage());
                }

                break;
            } catch (Exception e) {
                if (i == BFGameConfig.CONNECTION_COUNT - 1) {
                    RequestException exception = new RequestException(RequestException.IO_EXCEPTION,
                            "");
                    ret = ErrorUtil.errorJson("-1", exception.getMessage());
                } else {
                    LogUtil.d("connection url", "" + i);
                    continue;
                }
            }
        }
    } catch (java.lang.IllegalArgumentException e) {
        RequestException exception = new RequestException(RequestException.IO_EXCEPTION,
                BFGameConfig.ERROR_MESSAGE);
        ret = ErrorUtil.errorJson("-2", exception.getMessage());
    } finally {
        if (!BFGameConfig.IS_STOP_REQUEST) {
            Message msg = new Message();
            msg.obj = ret;
            msg.getData().putSerializable("callback", callBack);
            resultHandler.sendMessage(msg);
        }
        if (customLoadingDialog != null && customLoadingDialog.isShowing()) {
            customLoadingDialog.dismiss();
            customLoadingDialog = null;
        }
    }
    super.run();
}

From source file:com.carpool.dj.carpool.model.GcmIntentService.java

protected void onMessage(Context context, Intent intent) {

    HashMap<String, String> NotificationMap = new HashMap<String, String>();
    try {/*w  w w .  j  a  v a 2s.  com*/
        this.context = context;
        String Message = URLDecoder.decode(intent.getStringExtra("message"), "UTF-8");
        Log.i("NotificationMap", "message->" + Message);
        Log.i("NotificationMap",
                "messageType->" + URLDecoder.decode(intent.getStringExtra("messageType"), "UTF-8"));
        // if (!message.equals(Message)) {
        // message = Message;
        NotificationMap.put("message", Message);
        NotificationMap.put("timestamp", URLDecoder.decode(intent.getStringExtra("timestamp"), "UTF-8"));
        NotificationMap.put("accountId", URLDecoder.decode(intent.getStringExtra("accountId"), "UTF-8"));
        NotificationMap.put("messageType", URLDecoder.decode(intent.getStringExtra("messageType"), "UTF-8"));
        showGCMMassage(NotificationMap);

        NotificationHandler.sendMessage(new Message());

        if ("CarEvent".equals(intent.getStringExtra("messageType"))) {
            CarPoolNotificationHandler.sendMessage(new Message());
        }

        // }
        // }
    } catch (Exception e) {
        Utils.ExceptionHandler(e, ContentActivity.tracker, Utils.nowActivity);
        Log.e(TAG, e.getMessage());
    }
}

From source file:com.changxiang.game.sdk.net.AsyncHttpPost.java

@Override
public void run() {
    String ret = "";
    try {//from w w  w  .  j av  a  2s.co m
        for (int i = 0; i < CXGameConfig.CONNECTION_COUNT; i++) {
            try {
                request = new HttpPost(url);

                request.addHeader("Accept-Encoding", "default");

                if (parameter != null && parameter.size() > 0) {
                    List<BasicNameValuePair> list = new ArrayList<BasicNameValuePair>();
                    for (RequestParameter p : parameter) {
                        list.add(new BasicNameValuePair(Util.encode(p.getName()), Util.encode(p.getValue())));
                        LogUtil.d("AsyncHttpPost Param ", p.getName() + " , " + p.getValue());

                    }
                    StringBuffer sb = new StringBuffer();
                    for (int j = 0; j < list.size(); j++) {
                        sb.append(list.get(j));
                        if (!(j == list.size() - 1)) {
                            sb.append("&");
                        }
                    }

                    BasicNameValuePair bn = new BasicNameValuePair("sign",
                            MD5Util.MD5(sb + "1234" + CXGameConfig.SERVERKEY));

                    System.out.println(
                            "POST_SIGN:" + sb + "&sign=" + MD5Util.MD5(sb + "1234" + CXGameConfig.SERVERKEY));
                    list.add(bn);
                    ((HttpPost) request).setEntity(new UrlEncodedFormEntity(list, HTTP.UTF_8));
                }

                System.out.println("====" + url);
                httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectTimeout);
                httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, readTimeout);
                HttpResponse response = httpClient.execute(request);
                int statusCode = response.getStatusLine().getStatusCode();
                if (statusCode == HttpStatus.SC_OK) {
                    // HttpManager.saveCookies(response);
                    InputStream is = response.getEntity().getContent();
                    BufferedInputStream bis = new BufferedInputStream(is);
                    bis.mark(2);
                    // ??
                    byte[] header = new byte[2];
                    int result = bis.read(header);
                    // reset??
                    bis.reset();
                    // ?GZIP?
                    int headerData = getShort(header);
                    // Gzip ? ? 0x1f8b
                    if (result != -1 && headerData == 0x1f8b) {
                        is = new GZIPInputStream(bis);
                    } else {
                        is = bis;
                    }
                    InputStreamReader reader = new InputStreamReader(is, "utf-8");
                    char[] data = new char[100];
                    int readSize;
                    StringBuffer sb = new StringBuffer();
                    while ((readSize = reader.read(data)) > 0) {
                        sb.append(data, 0, readSize);
                    }
                    ret = sb.toString();
                    bis.close();
                    reader.close();

                } else {
                    RequestException exception = new RequestException(RequestException.IO_EXCEPTION,
                            "??,??" + statusCode);
                    ret = ErrorUtil.errorJson("-1", exception.getMessage());
                }

                break;
            } catch (Exception e) {
                if (i == CXGameConfig.CONNECTION_COUNT - 1) {
                    RequestException exception = new RequestException(RequestException.IO_EXCEPTION,
                            "");
                    ret = ErrorUtil.errorJson("-1", exception.getMessage());
                } else {
                    LogUtil.d("connection url", "" + i);
                    continue;
                }
            }
        }
    } catch (java.lang.IllegalArgumentException e) {
        RequestException exception = new RequestException(RequestException.IO_EXCEPTION,
                CXGameConfig.ERROR_MESSAGE);
        ret = ErrorUtil.errorJson("-2", exception.getMessage());
    } finally {
        if (!CXGameConfig.IS_STOP_REQUEST) {
            Message msg = new Message();
            msg.obj = ret;
            msg.getData().putSerializable("callback", callBack);
            resultHandler.sendMessage(msg);
        }
        if (customLoadingDialog != null && customLoadingDialog.isShowing()) {
            customLoadingDialog.dismiss();
            customLoadingDialog = null;
        }
    }
    super.run();
}

From source file:net.networksaremadeofstring.cyllell.ViewCookbooks_Fragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    settings = this.getActivity().getSharedPreferences("Cyllell", 0);
    try {// w w w  .j a v  a 2s.  c om
        Cut = new Cuts(getActivity());
    } catch (Exception e) {
        e.printStackTrace();
    }

    dialog = new ProgressDialog(getActivity());
    dialog.setTitle("Contacting Chef");

    dialog.setMessage("Please wait: Prepping Authentication protocols");
    dialog.setIndeterminate(true);
    if (listOfCookbooks.size() < 1) {
        dialog.show();
    }

    updateListNotify = new Handler() {
        public void handleMessage(Message msg) {
            int tag = msg.getData().getInt("tag", 999999);

            if (msg.what == 0) {
                if (tag != 999999) {
                    listOfCookbooks.get(tag).SetSpinnerVisible();
                }
            } else if (msg.what == 1) {
                //Get rid of the lock
                CutInProgress = false;

                //the notifyDataSetChanged() will handle the rest
            } else if (msg.what == 99) {
                if (tag != 999999) {
                    Toast.makeText(ViewCookbooks_Fragment.this.getActivity(),
                            "An error occured during that operation.", Toast.LENGTH_LONG).show();
                    listOfCookbooks.get(tag).SetErrorState();
                }
            }
            CookbookAdapter.notifyDataSetChanged();
        }
    };

    handler = new Handler() {
        public void handleMessage(Message msg) {
            //Once we've checked the data is good to use start processing it
            if (msg.what == 0) {
                OnClickListener listener = new OnClickListener() {
                    public void onClick(View v) {
                        GetMoreDetails((Integer) v.getTag());
                    }
                };

                OnLongClickListener listenerLong = new OnLongClickListener() {
                    public boolean onLongClick(View v) {
                        //selectForCAB((Integer)v.getTag());
                        Toast.makeText(getActivity(), "This version doesn't support Cookbook editing yet",
                                Toast.LENGTH_SHORT).show();
                        return true;
                    }
                };

                CookbookAdapter = new CookbookListAdaptor(getActivity(), listOfCookbooks, listener,
                        listenerLong);
                try {
                    list = (ListView) getView().findViewById(R.id.cookbooksListView);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                if (list != null) {
                    if (CookbookAdapter != null) {
                        list.setAdapter(CookbookAdapter);
                    } else {
                        //Log.e("CookbookAdapter","CookbookAdapter is null");
                    }
                } else {
                    //Log.e("List","List is null");
                }

                dialog.dismiss();
            } else if (msg.what == 200) {
                dialog.setMessage("Sending request to Chef...");
            } else if (msg.what == 201) {
                dialog.setMessage("Parsing JSON.....");
            } else if (msg.what == 202) {
                dialog.setMessage("Populating UI!");
            } else {
                //Close the Progress dialog
                dialog.dismiss();

                //Alert the user that something went terribly wrong
                AlertDialog alertDialog = new AlertDialog.Builder(context).create();
                alertDialog.setTitle("API Error");
                alertDialog.setMessage("There was an error communicating with the API:\n"
                        + msg.getData().getString("exception"));
                alertDialog.setButton2("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        //getActivity().finish();
                    }
                });
                alertDialog.setIcon(R.drawable.icon);
                alertDialog.show();
            }
        }
    };

    Thread dataPreload = new Thread() {
        public void run() {
            if (listOfCookbooks.size() > 0) {
                handler.sendEmptyMessage(0);
            } else {
                try {
                    handler.sendEmptyMessage(200);
                    Cookbooks = Cut.GetCookbooks();
                    handler.sendEmptyMessage(201);
                    JSONArray Keys = Cookbooks.names();
                    String URI = "";
                    String Version = "0.0.0";
                    JSONObject cookbook;
                    for (int i = 0; i < Cookbooks.length(); i++) {
                        cookbook = new JSONObject(Cookbooks.getString(Keys.get(i).toString()));
                        //URI = Cookbooks.getString(Keys.get(i).toString()).replaceFirst("^(https://|http://).*/cookbooks/", "");
                        //Version = Cookbooks.getString(Keys.get(i).toString())
                        //Log.i("Cookbook Name", Keys.get(i).toString());
                        URI = cookbook.getString("url").replaceFirst("^(https://|http://).*/cookbooks/", "");
                        //Log.i("Cookbook URL", URI);

                        JSONArray versions = cookbook.getJSONArray("versions");

                        Version = versions.getJSONObject(versions.length() - 1).getString("version");
                        //Log.i("Cookbook version", Version);

                        listOfCookbooks.add(new Cookbook(Keys.get(i).toString(), URI, Version));
                    }

                    handler.sendEmptyMessage(202);
                    handler.sendEmptyMessage(0);
                } catch (Exception e) {
                    BugSenseHandler.log("ViewCookbooksFragment", e);
                    e.printStackTrace();
                    Message msg = new Message();
                    Bundle data = new Bundle();
                    data.putString("exception", e.getMessage());
                    msg.setData(data);
                    msg.what = 1;
                    handler.sendMessage(msg);
                }
            }
            return;
        }
    };

    dataPreload.start();
    return inflater.inflate(R.layout.cookbooks_landing, container, false);
}

From source file:cn.xiaocool.android_etong.net.constant.request.MainRequest.java

public void updatauseravatar(final String avatar) {
    new Thread() {
        Message msg = new Message();

        public void run() {
            String data = "&userid=" + user.getUserId() + "&avatar=" + avatar;
            Log.e("data is ", data);
            String result_data = NetUtil.getResponse(WebAddress.UPLOADUSERAVATAR, data);
            Log.e("successful", result_data);
            try {
                JSONObject obj = new JSONObject(result_data);
                msg.what = CommunalInterfaces.UPUSERAVATAR;
                msg.obj = obj;//w  w w .ja  v a  2s. c o m
            } catch (JSONException e) {
                e.printStackTrace();
            } finally {
                handler.sendMessage(msg);
            }
        }
    }.start();
}

From source file:com.watch.customer.ui.ShopSearchActivity.java

private void onSearch() {
    editstr = searchEdit.getText().toString().trim();
    if (editstr.equals("") || editstr.length() == 0) {
        return;/*  w  ww.  j a  v  a2 s .co  m*/
    }
    SimpleDateFormat formatter = new SimpleDateFormat("MM-dd-HH");
    Date curDate = new Date(System.currentTimeMillis());
    String timestr = formatter.format(curDate);
    sdao.insert(new Search(0, editstr, timestr));
    ThreadPoolManager.getInstance().addTask(new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            String result = null;
            try {
                result = HttpUtil.post(HttpUtil.URL_FINDSTOREBYNAME,
                        new BasicNameValuePair(JsonUtil.NAME, editstr));
            } catch (IOException e) {
                e.printStackTrace();
                result = e.getMessage();
            }
            Log.e("hjq", HttpUtil.getURlStr(HttpUtil.URL_FINDSTOREBYNAME,
                    new BasicNameValuePair(JsonUtil.NAME, editstr)));
            Log.e("hjq", "result=" + result);
            Message msg = new Message();
            msg.what = 1;
            msg.obj = result;
            mHandler.sendMessage(msg);
        }
    });

}

From source file:com.iloomo.net.AsyncHttpPost.java

@Override
public void run() {
    String ret = "";
    try {//from w ww .j a v a 2s.  c  o m
        for (int i = 0; i < HttpConstant.CONNECTION_COUNT; i++) {
            try {
                request = new HttpPost(url);
                request.addHeader("Accept-Encoding", "default");

                if (parameter != null && parameter.size() > 0) {
                    List<BasicNameValuePair> list = new ArrayList<BasicNameValuePair>();
                    Set<String> keys = parameter.keySet();

                    for (String key : keys) {
                        list.add(new BasicNameValuePair(key, String.valueOf(parameter.get(key))));
                    }
                    ((HttpPost) request).setEntity(new UrlEncodedFormEntity(list, HTTP.UTF_8));
                }
                httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectTimeout);
                httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, readTimeout);
                HttpResponse response = httpClient.execute(request);
                int statusCode = response.getStatusLine().getStatusCode();
                if (statusCode == HttpStatus.SC_OK) {
                    InputStream is = response.getEntity().getContent();
                    BufferedInputStream bis = new BufferedInputStream(is);
                    bis.mark(2);
                    // ??
                    byte[] header = new byte[2];
                    int result = bis.read(header);
                    // reset??
                    bis.reset();
                    // ?GZIP?
                    int headerData = getShort(header);
                    // Gzip ? ? 0x1f8b
                    if (result != -1 && headerData == 0x1f8b) {
                        // LogUtil.d("HttpTask", " use GZIPInputStream  ");
                        is = new GZIPInputStream(bis);
                    } else {
                        // LogUtil.d("HttpTask",
                        // " not use GZIPInputStream");
                        is = bis;
                    }
                    InputStreamReader reader = new InputStreamReader(is, "utf-8");
                    char[] data = new char[100];
                    int readSize;
                    StringBuffer sb = new StringBuffer();
                    while ((readSize = reader.read(data)) > 0) {
                        sb.append(data, 0, readSize);
                    }
                    ret = sb.toString();
                    bis.close();
                    reader.close();

                } else {
                    RequestException exception = new RequestException(RequestException.IO_EXCEPTION,
                            "??,??" + statusCode);
                    ret = ErrorUtil.errorJson("999", exception.getMessage());
                }

                break;
            } catch (Exception e) {
                if (i == HttpConstant.CONNECTION_COUNT - 1) {
                    RequestException exception = new RequestException(RequestException.IO_EXCEPTION,
                            "");
                    ret = ErrorUtil.errorJson("999", exception.getMessage());
                } else {
                    Log.d("connection url", "" + i);
                    continue;
                }
            }
        }
    } catch (IllegalArgumentException e) {
        RequestException exception = new RequestException(RequestException.IO_EXCEPTION,
                HttpConstant.ERROR_MESSAGE);
        ret = ErrorUtil.errorJson("999", exception.getMessage());
    } finally {
        if (!HttpConstant.IS_STOP_REQUEST) {
            Message msg = new Message();
            msg.obj = ret;
            msg.getData().putSerializable("callback", callBack);
            resultHandler.sendMessage(msg);
        }
    }
    super.run();
}

From source file:com.spoiledmilk.ibikecph.util.HttpUtils.java

public static Message JSONtoMessage(JsonNode result) {
    Message ret = new Message();
    Bundle data = new Bundle();
    if (result != null) {
        data.putBoolean("success", result.get("success").asBoolean());
        data.putString("info", result.get("info").asText());
        if (result.has("errors"))
            data.putString("errors", result.get("errors").asText());
        JsonNode dataNode = result.get("data");
        if (dataNode != null) {
            if (dataNode.has("id"))
                data.putInt("id", dataNode.get("id").asInt());
            if (dataNode.has("auth_token"))
                data.putString("auth_token", dataNode.get("auth_token").asText());
        }//from   w ww. j  a v  a2 s . c  o  m
    }
    ret.setData(data);
    return ret;
}

From source file:cm.aptoide.pt.RemoteInSearch.java

@Override
protected void onListItemClick(ListView l, View v, final int position, long id) {

    super.onListItemClick(l, v, position, id);

    Vector<String> tmp_get = db.getApk(apk_lst.get(position).apkid);

    String tmp_path = this.getString(R.string.icons_path) + apk_lst.get(position).apkid;
    File test_icon = new File(tmp_path);

    LayoutInflater li = LayoutInflater.from(this);
    View view = li.inflate(R.layout.alertscroll, null);
    Builder alrt = new AlertDialog.Builder(this).setView(view);
    final AlertDialog p = alrt.create();
    if (test_icon.exists() && test_icon.length() > 0) {
        p.setIcon(new BitmapDrawable(tmp_path));
    } else {/*ww w. j  a va  2  s. c o m*/
        p.setIcon(android.R.drawable.sym_def_app_icon);
    }
    p.setTitle(apk_lst.get(position).name);
    TextView t1 = (TextView) view.findViewById(R.id.n11);
    t1.setText(tmp_get.firstElement());
    TextView t2 = (TextView) view.findViewById(R.id.n22);
    t2.setText(tmp_get.get(1));
    TextView t3 = (TextView) view.findViewById(R.id.n33);
    t3.setText(tmp_get.get(2));
    TextView t4 = (TextView) view.findViewById(R.id.n44);
    t4.setText(tmp_get.get(3));
    TextView t5 = (TextView) view.findViewById(R.id.n55);
    String tmpi = db.getDescript(apk_lst.get(position).apkid);
    if (!(tmpi == null)) {
        t5.setText(tmpi);
    } else {
        t5.setText("No info availale on server. Search market by pressing the button below for more info.");
    }

    p.setButton2("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            return;
        }
    });
    if (tmp_get.get(2).equalsIgnoreCase("\tno\n")) {
        p.setButton(getString(R.string.install), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                p.dismiss();
                new Thread() {
                    public void run() {
                        String apk_pkg = downloadFile(position);
                        if (apk_pkg == null) {
                            Message msg = new Message();
                            msg.arg1 = 1;
                            download_handler.sendMessage(msg);
                            download_error_handler.sendEmptyMessage(0);
                        } else {
                            installApk(apk_pkg, position);
                        }
                    }
                }.start();
            }
        });
        p.setButton3("Search Market", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                p.dismiss();
                Intent intent = new Intent();
                intent.setAction(android.content.Intent.ACTION_VIEW);
                intent.setData(Uri.parse("market://details?id=" + apk_lst.get(position).apkid));
                startActivity(intent);
            }
        });
    } else {
        p.setButton(getString(R.string.rem), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                String apk_pkg = apk_lst.get(position).apkid;
                removeApk(apk_pkg, position);
            }
        });
        if (apk_lst.get(position).status == 2) {
            p.setButton3(getString(R.string.update), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    p.dismiss();
                    new Thread() {
                        public void run() {
                            String apk_pkg = downloadFile(position);
                            if (apk_pkg == null) {
                                //Toast.makeText(RemoteInSearch.this, "Could not connect to server!", Toast.LENGTH_LONG).show();
                                Message msg = new Message();
                                msg.arg1 = 1;
                                download_handler.sendMessage(msg);
                                download_error_handler.sendEmptyMessage(0);
                            } else {
                                installApk(apk_pkg, position);
                            }
                        }
                    }.start();
                }
            });
        } else {
            p.setButton3("Search Market", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    p.dismiss();
                    Intent intent = new Intent();
                    intent.setAction(android.content.Intent.ACTION_VIEW);
                    intent.setData(Uri.parse("market://details?id=" + apk_lst.get(position).apkid));
                    startActivity(intent);
                }
            });
        }
    }
    p.show();
}