List of usage examples for android.content Intent getParcelableArrayExtra
public Parcelable[] getParcelableArrayExtra(String name)
From source file:com.cerema.cloud2.files.services.FileUploader.java
/** * Entry point to add one or several files to the queue of uploads. * * New uploads are added calling to startService(), resulting in a call to * this method. This ensures the service will keep on working although the * caller activity goes away./*w w w . j a va2s. c om*/ */ @Override public int onStartCommand(Intent intent, int flags, int startId) { Log_OC.d(TAG, "Starting command with id " + startId); if (intent.hasExtra(KEY_CANCEL_ALL) && intent.hasExtra(KEY_ACCOUNT)) { Account account = intent.getParcelableExtra(KEY_ACCOUNT); if (mCurrentUpload != null) { FileUploaderBinder fub = (FileUploaderBinder) mBinder; fub.cancel(account); return Service.START_NOT_STICKY; } } if (!intent.hasExtra(KEY_ACCOUNT) || !intent.hasExtra(KEY_UPLOAD_TYPE) || !(intent.hasExtra(KEY_LOCAL_FILE) || intent.hasExtra(KEY_FILE))) { Log_OC.e(TAG, "Not enough information provided in intent"); return Service.START_NOT_STICKY; } int uploadType = intent.getIntExtra(KEY_UPLOAD_TYPE, -1); if (uploadType == -1) { Log_OC.e(TAG, "Incorrect upload type provided"); return Service.START_NOT_STICKY; } Account account = intent.getParcelableExtra(KEY_ACCOUNT); if (!AccountUtils.exists(account, getApplicationContext())) { return Service.START_NOT_STICKY; } String[] localPaths = null, remotePaths = null, mimeTypes = null; OCFile[] files = null; if (uploadType == UPLOAD_SINGLE_FILE) { if (intent.hasExtra(KEY_FILE)) { files = new OCFile[] { intent.getParcelableExtra(KEY_FILE) }; } else { localPaths = new String[] { intent.getStringExtra(KEY_LOCAL_FILE) }; remotePaths = new String[] { intent.getStringExtra(KEY_REMOTE_FILE) }; mimeTypes = new String[] { intent.getStringExtra(KEY_MIME_TYPE) }; } } else { // mUploadType == UPLOAD_MULTIPLE_FILES if (intent.hasExtra(KEY_FILE)) { files = (OCFile[]) intent.getParcelableArrayExtra(KEY_FILE); // TODO // will // this // casting // work // fine? } else { localPaths = intent.getStringArrayExtra(KEY_LOCAL_FILE); remotePaths = intent.getStringArrayExtra(KEY_REMOTE_FILE); mimeTypes = intent.getStringArrayExtra(KEY_MIME_TYPE); } } FileDataStorageManager storageManager = new FileDataStorageManager(account, getContentResolver()); boolean forceOverwrite = intent.getBooleanExtra(KEY_FORCE_OVERWRITE, false); boolean isInstant = intent.getBooleanExtra(KEY_INSTANT_UPLOAD, false); int localAction = intent.getIntExtra(KEY_LOCAL_BEHAVIOUR, LOCAL_BEHAVIOUR_FORGET); if (intent.hasExtra(KEY_FILE) && files == null) { Log_OC.e(TAG, "Incorrect array for OCFiles provided in upload intent"); return Service.START_NOT_STICKY; } else if (!intent.hasExtra(KEY_FILE)) { if (localPaths == null) { Log_OC.e(TAG, "Incorrect array for local paths provided in upload intent"); return Service.START_NOT_STICKY; } if (remotePaths == null) { Log_OC.e(TAG, "Incorrect array for remote paths provided in upload intent"); return Service.START_NOT_STICKY; } if (localPaths.length != remotePaths.length) { Log_OC.e(TAG, "Different number of remote paths and local paths!"); return Service.START_NOT_STICKY; } files = new OCFile[localPaths.length]; for (int i = 0; i < localPaths.length; i++) { files[i] = obtainNewOCFileToUpload(remotePaths[i], localPaths[i], ((mimeTypes != null) ? mimeTypes[i] : null)); if (files[i] == null) { // TODO @andomaex add failure Notification return Service.START_NOT_STICKY; } } } OwnCloudVersion ocv = AccountUtils.getServerVersion(account); boolean chunked = FileUploader.chunkedUploadIsSupported(ocv); AbstractList<String> requestedUploads = new Vector<String>(); String uploadKey = null; UploadFileOperation newUpload = null; try { for (int i = 0; i < files.length; i++) { newUpload = new UploadFileOperation(account, files[i], chunked, isInstant, forceOverwrite, localAction, getApplicationContext()); if (isInstant) { newUpload.setRemoteFolderToBeCreated(); } newUpload.addDatatransferProgressListener(this); newUpload.addDatatransferProgressListener((FileUploaderBinder) mBinder); Pair<String, String> putResult = mPendingUploads.putIfAbsent(account, files[i].getRemotePath(), newUpload); if (putResult != null) { uploadKey = putResult.first; requestedUploads.add(uploadKey); } // else, file already in the queue of uploads; don't repeat the request } } catch (IllegalArgumentException e) { Log_OC.e(TAG, "Not enough information provided in intent: " + e.getMessage()); return START_NOT_STICKY; } catch (IllegalStateException e) { Log_OC.e(TAG, "Bad information provided in intent: " + e.getMessage()); return START_NOT_STICKY; } catch (Exception e) { Log_OC.e(TAG, "Unexpected exception while processing upload intent", e); return START_NOT_STICKY; } if (requestedUploads.size() > 0) { Message msg = mServiceHandler.obtainMessage(); msg.arg1 = startId; msg.obj = requestedUploads; mServiceHandler.sendMessage(msg); } return Service.START_NOT_STICKY; }
From source file:reportsas.com.formulapp.Formulario.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 1) { if (data != null) { if (data.hasExtra("data")) { Bitmap photobmp = (Bitmap) data.getParcelableExtra("data"); // iv.setImageBitmap(photobmp); ByteArrayOutputStream baos = new ByteArrayOutputStream(); photobmp.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] imageBytes = baos.toByteArray(); String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT); if (parametroCam == null) { parametroCam = new ParametrosRespuesta(2); }//w w w .j a v a 2 s.c o m parametroCam.setValor(encodedImage); // prueba.setText(encodedImage); // new MyAsyncTask(Formulario.this) // .execute("POST",encodedImage, HTTP_EVENT); } } } if (requestCode == MY_REQUEST_CODE && resultCode == Pdf417ScanActivity.RESULT_OK) { // First, obtain scan results array. If scan was successful, array will contain at least one element. // Multiple element may be in array if multiple scan results from single image were allowed in settings. Parcelable[] resultArray = data .getParcelableArrayExtra(Pdf417ScanActivity.EXTRAS_RECOGNITION_RESULT_LIST); StringBuilder sb = new StringBuilder(); for (Parcelable p : resultArray) { if (p instanceof Pdf417ScanResult) { // check if scan result is result of Pdf417 recognizer Pdf417ScanResult result = (Pdf417ScanResult) p; // getStringData getter will return the string version of barcode contents String barcodeData = result.getStringData(); // isUncertain getter will tell you if scanned barcode contains some uncertainties boolean uncertainData = result.isUncertain(); // getRawData getter will return the raw data information object of barcode contents BarcodeDetailedData rawData = result.getRawData(); // BarcodeDetailedData contains information about barcode's binary layout, if you // are only interested in raw bytes, you can obtain them with getAllData getter byte[] rawDataBuffer = rawData.getAllData(); DataR = rawData.toString(); String[] arrayElements = DataR.split("Element #"); String Nombre = "", Apellido = "", cedula = "", fecha = "", dia, mes, ano; if (arrayElements.length >= 7) { String[] auxliarArray = arrayElements[7].split("decoded\\):"); String strDatos = auxliarArray[1]; char[] ca = strDatos.toCharArray(); for (int i = 0; i < strDatos.length(); i++) { if (Character.isLetter(ca[i])) //Si es letra Apellido += ca[i]; //Salto de lnea e imprimimos el carcter else //Si no es letra cedula += ca[i]; //Imprimimos el carcter } Apellido = Apellido.trim(); cedula = (cedula.replaceAll("\n", "")).trim(); if (cedula.length() == 0) { auxliarArray = arrayElements[5].split("decoded\\):"); strDatos = auxliarArray[1]; ca = strDatos.toCharArray(); Apellido = ""; for (int i = 0; i < strDatos.length(); i++) { if (Character.isLetter(ca[i])) //Si es letra Apellido += ca[i]; //Salto de lnea e imprimimos el carcter else //Si no es letra cedula += ca[i]; //Imprimimos el carcter } Apellido = Apellido.trim(); cedula = (cedula.replaceAll("\n", "")).trim(); cedula = cedula.substring(cedula.length() - 10, cedula.length()); cedula = eliminarceros(cedula); auxliarArray = arrayElements[9].split("decoded\\):"); Nombre = (auxliarArray[1].replaceAll("\n", "")).trim(); } else { cedula = eliminarceros(cedula); auxliarArray = arrayElements[11].split("decoded\\):"); Nombre = (auxliarArray[1].replaceAll("\n", "")).trim(); } auxliarArray = result.getStringData().toString().split(Nombre); strDatos = auxliarArray[1]; ca = strDatos.toCharArray(); Boolean result_ciclo = true; int i = 0; while (result_ciclo) { if (Character.isDigit(ca[i])) { fecha += ca[i]; } if (fecha.length() >= 9) { result_ciclo = false; } i++; } fecha = fecha.substring(1, fecha.length()); } else { int puntoI = 0; if (barcodeData.indexOf("1F") > 0) { puntoI = barcodeData.indexOf("1F"); } else if (barcodeData.indexOf("0M") > 0) { puntoI = barcodeData.indexOf("0M"); } else if (barcodeData.indexOf("0F") > 0) { puntoI = barcodeData.indexOf("0F"); } else if (barcodeData.indexOf("1M") > 0) { puntoI = barcodeData.indexOf("1M"); } else { } if (puntoI > 0) { String seb = barcodeData.substring(1, puntoI); fecha = barcodeData.substring(puntoI + 2, puntoI + 10); int posL = 0, posE; char[] ca = seb.toCharArray(); for (int w = seb.length() - 1; w > 0; w--) { if (Character.isLetter(ca[w])) { posL = w; break; } } seb = seb.substring(1, posL + 1); ca = seb.toCharArray(); for (int w = seb.length() - 1; w > 0; w--) { if (Character.isLetter(ca[w])) { Nombre = ca[w] + Nombre; posL = w; } else { break; } } seb = seb.substring(1, posL); ca = seb.toCharArray(); for (int w = seb.length() - 1; w > 0; w--) { if (Character.isDigit(ca[w])) { posL = w; break; } } for (int w = posL + 1; w <= seb.length(); w++) { if (Character.isLetter(ca[w])) { Apellido += ca[w]; } else { break; } } cedula = seb.substring(posL - 9, posL + 1); cedula = eliminarceros(cedula); } else { fecha = ""; } } if (fecha.length() == 0) { parametroScan = null; Toast toast1 = Toast.makeText(this, "Los datos de codigo no pudieron ser interpretados!", Toast.LENGTH_SHORT); toast1.show(); } else { dia = fecha.substring(6, 8); mes = fecha.substring(4, 6); ano = fecha.substring(0, 4); fecha = dia + "/" + mes + "/" + ano; Infocadena = "Nombre: \n" + Nombre + ".\nApellido: \n" + Apellido + ". \nCedula: \n" + cedula + ". \nFecha de Nacimiento: \n" + fecha + "."; if (parametroScan == null) { parametroScan = new ParametrosRespuesta(3); } parametroScan.setValor(Infocadena); } // new MyAsyncTask(Formulario.this) // .execute("POST",Infocadena, HTTP_EVENT); } else if (p instanceof BarDecoderScanResult) { // check if scan result is result of BarDecoder recognizer /* BarDecoderScanResult result = (BarDecoderScanResult) p; // with getBarcodeType you can obtain barcode type enum that tells you the type of decoded barcode BarcodeType type = result.getBarcodeType(); // as with PDF417, getStringData will return the string contents of barcode String barcodeData = result.getStringData(); if(checkIfDataIsUrlAndCreateIntent(barcodeData)) { return; } else { sb.append(type.name()); sb.append(" string data:\n"); sb.append(barcodeData); sb.append("\n\n\n");= }*/ } else if (p instanceof ZXingScanResult) { // check if scan result is result of ZXing recognizer /* ZXingScanResult result= (ZXingScanResult) p; // with getBarcodeType you can obtain barcode type enum that tells you the type of decoded barcode BarcodeType type = result.getBarcodeType(); // as with PDF417, getStringData will return the string contents of barcode String barcodeData = result.getStringData(); if(checkIfDataIsUrlAndCreateIntent(barcodeData)) { return; } else { sb.append(type.name()); sb.append(" string data:\n"); sb.append(barcodeData); sb.append("\n\n\n"); }*/ } else if (p instanceof USDLScanResult) { // check if scan result is result of US Driver's Licence recognizer USDLScanResult result = (USDLScanResult) p; // USDLScanResult can contain lots of information extracted from driver's licence // you can obtain information using the getField method with keys defined in // USDLScanResult class String name = result.getField(USDLScanResult.kCustomerFullName); sb.append(result.getTitle()); sb.append("\n\n"); sb.append(result.toString()); } } } }
From source file:com.mobilyzer.MeasurementScheduler.java
@Override public void onCreate() { Logger.d("MeasurementScheduler -> onCreate called"); PhoneUtils.setGlobalContext(this.getApplicationContext()); phoneUtils = PhoneUtils.getPhoneUtils(); phoneUtils.registerSignalStrengthListener(); this.measurementExecutor = Executors.newSingleThreadExecutor(); this.mainQueue = new PriorityBlockingQueue<MeasurementTask>(Config.MAX_TASK_QUEUE_SIZE, new TaskComparator()); this.waitingTasksQueue = new PriorityBlockingQueue<MeasurementTask>(Config.MAX_TASK_QUEUE_SIZE, new WaitingTasksComparator()); this.pendingTasks = new ConcurrentHashMap<MeasurementTask, Future<MeasurementResult[]>>(); this.tasksStatus = new ConcurrentHashMap<String, MeasurementScheduler.TaskStatus>(); this.alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); this.resourceCapManager = new ResourceCapManager(Config.DEFAULT_BATTERY_THRESH_PRECENT, this); this.serverTasks = new HashMap<String, Date>(); // this.currentSchedule = new HashMap<String, MeasurementTask>(); this.idToClientKey = new ConcurrentHashMap<String, String>(); messenger = new Messenger(new APIRequestHandler(this)); gcmManager = new GCMManager(this.getApplicationContext()); this.setCurrentTask(null); this.setCurrentTaskStartTime(null); this.checkin = new Checkin(this); this.checkinRetryIntervalSec = Config.MIN_CHECKIN_RETRY_INTERVAL_SEC; this.checkinRetryCnt = 0; this.checkinTask = new CheckinTask(); this.batteryThreshold = -1; this.checkinIntervalSec = -1; this.dataUsageProfile = DataUsageProfile.NOTASSIGNED; // loadSchedulerState();//TODO(ASHKAN) // Register activity specific BroadcastReceiver here IntentFilter filter = new IntentFilter(); filter.addAction(UpdateIntent.CHECKIN_ACTION); filter.addAction(UpdateIntent.CHECKIN_RETRY_ACTION); filter.addAction(UpdateIntent.MEASUREMENT_ACTION); filter.addAction(UpdateIntent.MEASUREMENT_PROGRESS_UPDATE_ACTION); filter.addAction(UpdateIntent.GCM_MEASUREMENT_ACTION); filter.addAction(UpdateIntent.PLT_MEASUREMENT_ACTION); broadcastReceiver = new BroadcastReceiver() { @Override/*from w ww .j a v a 2s.com*/ public void onReceive(Context context, Intent intent) { Logger.d(intent.getAction() + " RECEIVED"); if (intent.getAction().equals(UpdateIntent.MEASUREMENT_ACTION)) { handleMeasurement(); } else if (intent.getAction().equals(UpdateIntent.GCM_MEASUREMENT_ACTION)) { try { JSONObject json = new JSONObject( intent.getExtras().getString(UpdateIntent.MEASUREMENT_TASK_PAYLOAD)); Logger.d("MeasurementScheduler -> GCMManager: json task Value is " + json); if (json != null && MeasurementTask.getMeasurementTypes().contains(json.get("type"))) { try { MeasurementTask task = MeasurementJsonConvertor.makeMeasurementTaskFromJson(json); task.getDescription().priority = MeasurementTask.GCM_PRIORITY; task.getDescription().startTime = new Date(System.currentTimeMillis() - 1000); task.getDescription().endTime = new Date(System.currentTimeMillis() + (600 * 1000)); task.generateTaskID(); task.getDescription().key = Config.SERVER_TASK_CLIENT_KEY; submitTask(task); } catch (IllegalArgumentException e) { Logger.w("MeasurementScheduler -> GCM : Could not create task from JSON: " + e); } } } catch (JSONException e) { Logger.e( "MeasurementSchedule -> GCMManager : Got exception during converting GCM json to MeasurementTask", e); } } else if (intent.getAction().equals(UpdateIntent.MEASUREMENT_PROGRESS_UPDATE_ACTION)) { String taskid = intent.getStringExtra(UpdateIntent.TASKID_PAYLOAD); String taskKey = intent.getStringExtra(UpdateIntent.CLIENTKEY_PAYLOAD); int priority = intent.getIntExtra(UpdateIntent.TASK_PRIORITY_PAYLOAD, MeasurementTask.INVALID_PRIORITY); Logger.e( intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD) + " " + taskid + " " + taskKey); if (intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD).equals(Config.TASK_FINISHED)) { tasksStatus.put(taskid, TaskStatus.FINISHED); Parcelable[] results = intent.getParcelableArrayExtra(UpdateIntent.RESULT_PAYLOAD); if (results != null) { sendResultToClient(results, priority, taskKey, taskid); for (Object obj : results) { try { MeasurementResult result = (MeasurementResult) obj; /** * Nullify the additional parameters in MeasurmentDesc, or the results won't be * accepted by GAE server */ result.getMeasurementDesc().parameters = null; String jsonResult = MeasurementJsonConvertor.encodeToJson(result).toString(); saveResultToFile(jsonResult); } catch (JSONException e) { Logger.e("Error converting results to json format", e); } } } handleMeasurement(); } else if (intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD).equals(Config.TASK_PAUSED)) { tasksStatus.put(taskid, TaskStatus.PAUSED); } else if (intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD) .equals(Config.TASK_STOPPED)) { tasksStatus.put(taskid, TaskStatus.SCHEDULED); } else if (intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD) .equals(Config.TASK_CANCELED)) { tasksStatus.put(taskid, TaskStatus.CANCELLED); Parcelable[] results = intent.getParcelableArrayExtra(UpdateIntent.RESULT_PAYLOAD); if (results != null) { sendResultToClient(results, priority, taskKey, taskid); } } else if (intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD) .equals(Config.TASK_STARTED)) { tasksStatus.put(taskid, TaskStatus.RUNNING); } else if (intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD) .equals(Config.TASK_RESUMED)) { tasksStatus.put(taskid, TaskStatus.RUNNING); } } else if (intent.getAction().equals(UpdateIntent.CHECKIN_ACTION) || intent.getAction().equals(UpdateIntent.CHECKIN_RETRY_ACTION)) { Logger.d("Checkin intent received"); handleCheckin(); } } }; this.registerReceiver(broadcastReceiver, filter); }
From source file:com.android.mms.ui.ComposeMessageActivity.java
private void processPickResult(final Intent data) { // The EXTRA_PHONE_URIS stores the phone's urls that were selected by user in the // multiple phone picker. final Parcelable[] uris = data.getParcelableArrayExtra(Intents.EXTRA_PHONE_URIS); final int recipientCount = uris != null ? uris.length : 0; final int recipientLimit = MmsConfig.getRecipientLimit(); if (recipientLimit != Integer.MAX_VALUE && recipientCount > recipientLimit) { new AlertDialog.Builder(this) .setMessage(getString(R.string.too_many_recipients, recipientCount, recipientLimit)) .setPositiveButton(android.R.string.ok, null).create().show(); return;//w ww. j a v a 2 s. c o m } final Handler handler = new Handler(); final ProgressDialog progressDialog = new ProgressDialog(this); progressDialog.setTitle(getText(R.string.pick_too_many_recipients)); progressDialog.setMessage(getText(R.string.adding_recipients)); progressDialog.setIndeterminate(true); progressDialog.setCancelable(false); final Runnable showProgress = new Runnable() { @Override public void run() { progressDialog.show(); } }; // Only show the progress dialog if we can not finish off parsing the return data in 1s, // otherwise the dialog could flicker. handler.postDelayed(showProgress, 1000); new Thread(new Runnable() { @Override public void run() { final ContactList list; try { list = ContactList.blockingGetByUris(uris); } finally { handler.removeCallbacks(showProgress); progressDialog.dismiss(); } // TODO: there is already code to update the contact header widget and recipients // editor if the contacts change. we can re-use that code. final Runnable populateWorker = new Runnable() { @Override public void run() { mRecipientsEditor.populate(list); updateTitle(list); } }; handler.post(populateWorker); } }, "ComoseMessageActivity.processPickResult").start(); }