Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 服务。但在上传时,我无法处理另一个web api请求。请将代码与AsyncTask@ItzikSamara我已经实现了使用异步任务及其在后台服务中上载图像。但在上传时,我无法处理另一个web api请求。我已使用异步任务及其在后台服务中上传图像来实现。但在_Android_Service_Android Service - Fatal编程技术网

Android 服务。但在上传时,我无法处理另一个web api请求。请将代码与AsyncTask@ItzikSamara我已经实现了使用异步任务及其在后台服务中上载图像。但在上传时,我无法处理另一个web api请求。我已使用异步任务及其在后台服务中上传图像来实现。但在

Android 服务。但在上传时,我无法处理另一个web api请求。请将代码与AsyncTask@ItzikSamara我已经实现了使用异步任务及其在后台服务中上载图像。但在上传时,我无法处理另一个web api请求。我已使用异步任务及其在后台服务中上传图像来实现。但在,android,service,android-service,Android,Service,Android Service,服务。但在上传时,我无法处理另一个web api请求。请将代码与AsyncTask@ItzikSamara我已经实现了使用异步任务及其在后台服务中上载图像。但在上传时,我无法处理另一个web api请求。我已使用异步任务及其在后台服务中上传图像来实现。但在上传时,我无法处理另一个web api请求。如果您希望多ul asynctask并行运行,则应使用而不是执行*。我已使用Async task及其在后台服务中上传图像来实现。但在上传时,我无法处理另一个web api请求。如果您希望多线程异步任务


服务。但在上传时,我无法处理另一个web api请求。请将代码与AsyncTask@ItzikSamara我已经实现了使用异步任务及其在后台服务中上载图像。但在上传时,我无法处理另一个web api请求。我已使用异步任务及其在后台服务中上传图像来实现。但在上传时,我无法处理另一个web api请求。如果您希望多ul asynctask并行运行,则应使用而不是执行*。我已使用Async task及其在后台服务中上传图像来实现。但在上传时,我无法处理另一个web api请求。如果您希望多线程异步任务并行运行,则应使用而不是执行*。
public class CartActivity extends Activity {



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.cart_screen);

        Intent serviceIntent = new Intent(CartActivity.this, UploadImgService.class);
        startService(serviceIntent);
        }
}
public class UploadImgService  extends Service {

//local database
private DataSourceUserRecords dataResource ; 
private SQLiteDatabase _database = null;
private Cursor _cursor = null;
private MySqliteHelper DBHelper; 


private String _userID = "";
private  String _uniqueID = "";
private String _imageName = "";
private String _imgPath = "";
private int _idDB =0; 
private Bitmap _imgBitmap;
private String _base64Str = "";



JSONObject outerJsonObject ;
JSONArray _mainArray ;


HttpClient client;
String _responseMain = "";
HttpResponse responseMain;
@Override
public void onCreate() {
    super.onCreate();
    // This method is invoked when the service is called.
    // Need to fetch all the data from Local database

    // do subroutines here
    System.out.println("onCreate of Service  " );
    try{

        outerJsonObject = new JSONObject();
        _mainArray = new JSONArray();

        DBHelper = new MySqliteHelper(UploadImgService.this);
        _database = DBHelper.getWritableDatabase();
        dataResource  = new DataSourceUserRecords(UploadImgService.this);
        dataResource.open();

        //  _database = context.openOrCreateDatabase(MySqliteHelper, arg1, arg2)

        //dataResource  = new DataSourceUserRecords(context);
        //_database= context.openOrCreateDatabase(MySqliteHelper.DATABASE_NAME, MODE_PRIVATE, null);
        _cursor = _database.rawQuery("select * from "+MySqliteHelper.TABLE_NAME, null);

        _cursor.moveToFirst(); 
        while(_cursor.isAfterLast() == false){

            _idDB =  _cursor.getInt(_cursor.getColumnIndex(MySqliteHelper.READING_DETAILS_COLUMN_ID));
            _userID =  _cursor.getString(_cursor.getColumnIndex(MySqliteHelper.READING_DETAILS_COLUMN_USER_ID));
            _uniqueID =  _cursor.getString(_cursor.getColumnIndex(MySqliteHelper.READING_DETAILS_COLUMN_UNIQUE_ID));
            _imageName =  _cursor.getString(_cursor.getColumnIndex(MySqliteHelper.READING_DETAILS_COLUMN_IMG_NAME));
            _imgPath =  _cursor.getString(_cursor.getColumnIndex(MySqliteHelper.READING_DETAILS_COLUMN_IMAGE_PATH));

            System.out.println("DATA base column id :" + _idDB);
            System.out.println("USer id from db : "  + _userID);
            System.out.println("Unique Name from db : " + _uniqueID);
            System.out.println("Image Name from db : " + _imageName);
            System.out.println("Image path from db : " +_imgPath);




            JSONObject _jSubObj = new JSONObject();
            _imgBitmap = BitmapFactory.decodeFile(_imgPath);
            _base64Str =  Constant.convertBitmapToBase64(_imgBitmap);
            _jSubObj.put("user_id", _userID);
            _jSubObj.put("unique_id", _uniqueID);
            _jSubObj.put("img_name", "image_" + _cursor.getPosition()/*+_temp_orderid*/);
            _jSubObj.put("img_base", _base64Str);


            _mainArray.put(_jSubObj);


            _cursor.moveToNext();
        }
        _cursor.close();

        try {
            outerJsonObject.put("image_details",_mainArray);
            if (NetworkAvailablity.checkNetworkStatus(UploadImgService.this)) {





                try {
                    // Creating HTTP client
                    client = new DefaultHttpClient();

                    // Creating HTTP Post
                    HttpPost httpPost= new HttpPost(WebServiceConstants
                            .getMethodUrl(WebServiceConstants.METHOD_UPLOAD_IMAGES));



                    // Building post parameters, key and value pair
                    List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>();

                    nameValuePair.add(new BasicNameValuePair("image_details", outerJsonObject.toString()));
                    //                  nameValuePair.add(new BasicNameValuePair("order_details", _mainArray.toString()));

                    // Url Encoding the POST parameters
                    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
                    responseMain = client.execute(httpPost);
                    HttpEntity entitity = responseMain.getEntity();

                    _responseMain = EntityUtils.toString(entitity); // content will be consume only once
                    System.out.println("Response of Upload image : "+_responseMain);
                    //                      System.out.println("_catID : "  +_catID);
                } catch (UnsupportedEncodingException e) {
                    // writing error to Log
                    e.printStackTrace();
                    /*Constant.alertDialogShow(UploadImgService.this, getResources().getString(R.string.messageText),
                            "Internal server error.", "");*/

                }
                catch (Exception e) {
                    // TODO: handle exception
                    e.printStackTrace();


                }




            System.out.println("OuterJSON request upload image "+outerJsonObject);


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

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

}




@Override
public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return null;
    // A client or activity is binded to service
}

}