List of usage examples for android.content Intent getSerializableExtra
public Serializable getSerializableExtra(String name)
From source file:com.upstack.materialcamerasample.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // Received recording or error from SampleCamera if (requestCode == CAMERA_RQ) { if (resultCode == RESULT_OK) { final File file = new File(data.getData().getPath()); mHandler.post(new Runnable() { @Override//from w w w . ja v a2 s . c o m public void run() { showDialog(MainActivity.this, "Select Resolution", new String[] { "Cancel", "Select" }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { dialog.dismiss(); if (GeneralUtils.checkIfFileExistAndNotEmpty(file.getAbsolutePath())) { new TranscdingBackground(MainActivity.this, file.getAbsolutePath(), file.getName(), "160x120", file).execute(); } else { Toast.makeText(getApplicationContext(), file.getAbsolutePath() + " not found", Toast.LENGTH_LONG) .show(); } } else if (which == 1) { dialog.dismiss(); if (GeneralUtils.checkIfFileExistAndNotEmpty(file.getAbsolutePath())) { new TranscdingBackground(MainActivity.this, file.getAbsolutePath(), file.getName(), "320x240", file).execute(); } else { Toast.makeText(getApplicationContext(), file.getAbsolutePath() + " not found", Toast.LENGTH_LONG) .show(); } } } }); } }); } else if (data != null) { Exception e = (Exception) data.getSerializableExtra(MaterialCamera.ERROR_EXTRA); if (e != null) { e.printStackTrace(); Toast.makeText(this, "Error: " + e.getMessage(), Toast.LENGTH_LONG).show(); } } } }
From source file:net.jongrakko.zipsuri.activity.PostReviseActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK && requestCode == UCrop.REQUEST_CROP) { File cropFile = new File(UCrop.getOutput(data).getPath()); int index = 0; for (int id : postImageViewIds) { ImageView mImageView = (ImageView) rootView.findViewById(id); if (mImageView.getTag() == null) { rootView.findViewById(postImageViewPlusIds[index]).setVisibility(View.VISIBLE); rootView.findViewById(postImageViewRemoveIds[index]).setVisibility(View.VISIBLE); mImageView.setImageBitmap(BitmapFactory.decodeFile(cropFile.getPath())); mImageView.setScaleType(ImageView.ScaleType.FIT_XY); mImageView.setPadding(10, 10, 10, 10); mImageView.setTag(cropFile.getPath()); mImageViewTitle.setImageDrawable(((ImageView) rootView.findViewById(id)).getDrawable()); mImageViewTitle.setTag(id); break; }/* w w w.j a v a2 s .c om*/ index++; } } else if (resultCode == Activity.RESULT_OK && requestCode == PICK_PHOTO_FOR_AVATAR) { UCrop.of(data.getData(), Uri.fromFile( new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg"))) .withMaxResultSize(1920, 1920).start(getContext(), this); } else if (resultCode == Activity.RESULT_OK && requestCode == TAKE_PHOTO_FOR_AVATAR) { UCrop.of(Uri.fromFile(takeFile), Uri.fromFile( new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg"))) .withMaxResultSize(1920, 1920).start(getContext(), this); } else if (resultCode == UCrop.RESULT_ERROR) { final Throwable cropError = UCrop.getError(data); Log.d("mox", "croperror" + cropError.toString()); } else if (resultCode == Activity.RESULT_OK && requestCode == SEARCH_ADDRESS) { AddressModel mAddressModel = (AddressModel) data.getSerializableExtra("data"); setAddressModel(mAddressModel); } else if (resultCode == Activity.RESULT_OK && requestCode == PICK_VIDEO_FOR_AVATAR) { String path = getPath(data.getData()); showVideoAlertDialog(path); } else if (resultCode == Activity.RESULT_OK && requestCode == TAKE_VIDEO_FOR_AVATAR) { String path = takeFile.getPath(); showVideoAlertDialog(path); } }
From source file:eu.faircode.netguard.ServiceSinkhole.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.i(TAG, "Received " + intent); Util.logExtras(intent);/* ww w .j a v a 2 s . c o m*/ // Check for set command if (intent != null && intent.hasExtra(EXTRA_COMMAND) && intent.getSerializableExtra(EXTRA_COMMAND) == Command.set) { set(intent); return START_STICKY; } // Keep awake getLock(this).acquire(); // Get state SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); boolean enabled = prefs.getBoolean("enabled", false); // Handle service restart if (intent == null) { Log.i(TAG, "Restart"); // Recreate intent intent = new Intent(this, ServiceSinkhole.class); intent.putExtra(EXTRA_COMMAND, enabled ? Command.start : Command.stop); } if (ACTION_HOUSE_HOLDING.equals(intent.getAction())) intent.putExtra(EXTRA_COMMAND, Command.householding); if (ACTION_WATCHDOG.equals(intent.getAction())) intent.putExtra(EXTRA_COMMAND, Command.watchdog); Command cmd = (Command) intent.getSerializableExtra(EXTRA_COMMAND); if (cmd == null) intent.putExtra(EXTRA_COMMAND, enabled ? Command.start : Command.stop); String reason = intent.getStringExtra(EXTRA_REASON); Log.i(TAG, "Start intent=" + intent + " command=" + cmd + " reason=" + reason + " vpn=" + (vpn != null) + " user=" + (Process.myUid() / 100000)); commandHandler.queue(intent); return START_STICKY; }
From source file:com.example.cuisoap.agrimac.homePage.homeFragment.java
public void onActivityResult(int requestCode, int resultCode, Intent i) { if (requestCode == 0) { try {/* www . j a v a 2s . co m*/ if (resultCode == Activity.RESULT_CANCELED) ; else { System.out.println(i.getStringExtra("data")); JSONObject m = new JSONObject(i.getStringExtra("data")); HashMap<String, String> s = new HashMap<>(); s.put("machine_name", m.getString("machine_name")); s.put("machine_powertype", m.getString("machine_powertype")); s.put("machine_power", m.getString("machine_power")); s.put("passenger_num", m.getString("passenger_num")); s.put("machine_paytype", m.getString("machine_paytype")); s.put("machine_type", m.getString("machine_type")); s.put("machine_wheeldistance", m.getString("machine_wheeldistance")); s.put("machine_checktime", m.getString("machine_checktime")); s.put("machine_license1", m.getString("machine_license1")); s.put("machine_license2", m.getString("machine_license2")); s.put("drive_type", m.getString("drive_type")); if (m.getString("drive_type").equals("1")) { s.put("driver_name", m.getString("driver_name")); s.put("driver_age", m.getString("driver_age")); s.put("driver_gender", m.getString("driver_gender")); s.put("driver_license_type", m.getString("driver_license_type")); s.put("driver_license", m.getString("driver_license")); } s.put("lease_month", m.getString("lease_month")); s.put("lease_time", m.getString("lease_time")); s.put("need_type", m.getString("need_type")); if (m.getString("need_type").equals("2")) { s.put("need_item", m.getString("need_item")); } s.put("work_condition", m.getString("work_condition")); s.put("machine_house", m.getString("house_type")); data.add(s); adapter.setData(data); adapter.notifyDataSetChanged(); } } catch (JSONException e) { e.printStackTrace(); } } else if (requestCode == 1) { if (resultCode == Activity.RESULT_CANCELED) { System.out.println("canceled"); } else if (resultCode == -1) { removeDataItem((HashMap<String, String>) i.getSerializableExtra("data")); } else { replaceDataItem((HashMap<String, String>) i.getSerializableExtra("data")); System.out.println(data.size()); } adapter.setData(data); adapter.notifyDataSetChanged(); } }
From source file:com.TagFu.facebook.Session.java
/** * Provides an implementation for {@link Activity#onActivityResult onActivityResult} that updates the Session based * on information returned during the authorization flow. The Activity that calls open or requestNewPermissions * should forward the resulting onActivityResult call here to update the Session state based on the contents of the * resultCode and data.//from w w w .ja va 2 s.c o m * * @param currentActivity The Activity that is forwarding the onActivityResult call. * @param requestCode The requestCode parameter from the forwarded call. When this onActivityResult occurs as part * of Facebook authorization flow, this value is the activityCode passed to open or authorize. * @param resultCode An int containing the resultCode parameter from the forwarded call. * @param data The Intent passed as the data parameter from the forwarded call. * @return A boolean indicating whether the requestCode matched a pending authorization request for this Session. */ public final boolean onActivityResult(final Activity currentActivity, final int requestCode, final int resultCode, final Intent data) { Validate.notNull(currentActivity, "currentActivity"); initializeStaticContext(currentActivity); synchronized (this.lock) { if ((this.pendingAuthorizationRequest == null) || (requestCode != this.pendingAuthorizationRequest.getRequestCode())) { return false; } } Exception exception = null; AuthorizationClient.Result.Code code = AuthorizationClient.Result.Code.ERROR; if (data != null) { final AuthorizationClient.Result result = (AuthorizationClient.Result) data .getSerializableExtra(LoginActivity.RESULT_KEY); if (result != null) { // This came from LoginActivity. this.handleAuthorizationResult(resultCode, result); return true; } else if (this.authorizationClient != null) { // Delegate to the auth client. this.authorizationClient.onActivityResult(requestCode, resultCode, data); return true; } } else if (resultCode == Activity.RESULT_CANCELED) { exception = new FacebookOperationCanceledException("User canceled operation."); code = AuthorizationClient.Result.Code.CANCEL; } if (exception == null) { exception = new FacebookException("Unexpected call to Session.onActivityResult"); } this.logAuthorizationComplete(code, null, exception); this.finishAuthOrReauth(null, exception); return true; }
From source file:com.fenlisproject.elf.core.framework.ElfBinder.java
public static void bindIntentExtra(Object receiver) { Field[] fields = receiver.getClass().getDeclaredFields(); for (Field field : fields) { field.setAccessible(true);/*www . ja v a2 s.c om*/ IntentExtra intentExtra = field.getAnnotation(IntentExtra.class); if (intentExtra != null) { try { Intent intent = null; if (receiver instanceof Activity) { intent = ((Activity) receiver).getIntent(); } else if (receiver instanceof Fragment) { intent = ((Fragment) receiver).getActivity().getIntent(); } if (intent != null) { Class<?> type = field.getType(); if (type == Boolean.class || type == boolean.class) { field.set(receiver, intent.getBooleanExtra(intentExtra.value(), false)); } else if (type == Byte.class || type == byte.class) { field.set(receiver, intent.getByteExtra(intentExtra.value(), (byte) 0)); } else if (type == Character.class || type == char.class) { field.set(receiver, intent.getCharExtra(intentExtra.value(), '\u0000')); } else if (type == Double.class || type == double.class) { field.set(receiver, intent.getDoubleExtra(intentExtra.value(), 0.0d)); } else if (type == Float.class || type == float.class) { field.set(receiver, intent.getFloatExtra(intentExtra.value(), 0.0f)); } else if (type == Integer.class || type == int.class) { field.set(receiver, intent.getIntExtra(intentExtra.value(), 0)); } else if (type == Long.class || type == long.class) { field.set(receiver, intent.getLongExtra(intentExtra.value(), 0L)); } else if (type == Short.class || type == short.class) { field.set(receiver, intent.getShortExtra(intentExtra.value(), (short) 0)); } else if (type == String.class) { field.set(receiver, intent.getStringExtra(intentExtra.value())); } else if (type == Boolean[].class || type == boolean[].class) { field.set(receiver, intent.getBooleanArrayExtra(intentExtra.value())); } else if (type == Byte[].class || type == byte[].class) { field.set(receiver, intent.getByteArrayExtra(intentExtra.value())); } else if (type == Character[].class || type == char[].class) { field.set(receiver, intent.getCharArrayExtra(intentExtra.value())); } else if (type == Double[].class || type == double[].class) { field.set(receiver, intent.getDoubleArrayExtra(intentExtra.value())); } else if (type == Float[].class || type == float[].class) { field.set(receiver, intent.getFloatArrayExtra(intentExtra.value())); } else if (type == Integer[].class || type == int[].class) { field.set(receiver, intent.getIntArrayExtra(intentExtra.value())); } else if (type == Long[].class || type == long[].class) { field.set(receiver, intent.getLongArrayExtra(intentExtra.value())); } else if (type == Short[].class || type == short[].class) { field.set(receiver, intent.getShortArrayExtra(intentExtra.value())); } else if (type == String[].class) { field.set(receiver, intent.getStringArrayExtra(intentExtra.value())); } else if (Serializable.class.isAssignableFrom(type)) { field.set(receiver, intent.getSerializableExtra(intentExtra.value())); } else if (type == Bundle.class) { field.set(receiver, intent.getBundleExtra(intentExtra.value())); } } } catch (IllegalAccessException e) { e.printStackTrace(); } } } }
From source file:com.telestax.restcomm_olympus.CallActivity.java
private void handleCall(Intent intent) { isVideo = intent.getBooleanExtra(RCDevice.EXTRA_VIDEO_ENABLED, false); if (intent.getAction().equals(RCDevice.OUTGOING_CALL)) { String text;//w ww. ja va 2s. com if (isVideo) { text = "Video Calling "; } else { text = "Audio Calling "; } lblCall.setText(text + intent.getStringExtra(RCDevice.EXTRA_DID).replaceAll(".*?sip:", "").replaceAll("@.*$", "")); lblStatus.setText("Initiating Call..."); connectParams = new HashMap<String, Object>(); connectParams.put(RCConnection.ParameterKeys.CONNECTION_PEER, intent.getStringExtra(RCDevice.EXTRA_DID)); connectParams.put(RCConnection.ParameterKeys.CONNECTION_VIDEO_ENABLED, intent.getBooleanExtra(RCDevice.EXTRA_VIDEO_ENABLED, false)); connectParams.put(RCConnection.ParameterKeys.CONNECTION_LOCAL_VIDEO, findViewById(R.id.local_video_layout)); connectParams.put(RCConnection.ParameterKeys.CONNECTION_REMOTE_VIDEO, findViewById(R.id.remote_video_layout)); // by default we use VP8 for video as it tends to be more adopted, but you can override that and specify VP9 as follows: //connectParams.put(RCConnection.ParameterKeys.CONNECTION_PREFERRED_VIDEO_CODEC, "VP9"); // *** if you want to add custom SIP headers, please uncomment this //HashMap<String, String> sipHeaders = new HashMap<>(); //sipHeaders.put("X-SIP-Header1", "Value1"); //connectParams.put(RCConnection.ParameterKeys.CONNECTION_CUSTOM_SIP_HEADERS, sipHeaders); handlePermissions(isVideo); } if (intent.getAction().equals(RCDevice.INCOMING_CALL)) { String text; if (isVideo) { text = "Video Call from "; } else { text = "Audio Call from "; } lblCall.setText(text + intent.getStringExtra(RCDevice.EXTRA_DID).replaceAll(".*?sip:", "").replaceAll("@.*$", "")); lblStatus.setText("Call Received..."); //callOutgoing = false; pendingConnection = device.getPendingConnection(); pendingConnection.setConnectionListener(this); // the number from which we got the call String incomingCallDid = intent.getStringExtra(RCDevice.EXTRA_DID); HashMap<String, String> customHeaders = (HashMap<String, String>) intent .getSerializableExtra(RCDevice.EXTRA_CUSTOM_HEADERS); if (customHeaders != null) { Log.i(TAG, "Got custom headers in incoming call: " + customHeaders.toString()); } } }
From source file:com.quwu.xinwo.release.Release_Activity.java
@SuppressWarnings("unchecked") protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case 20://w w w . j av a2s . c o m if (data != null) { if (requestCode == 20) { String sheng = data.getExtras().getString("sheng"); String shi = data.getExtras().getString("shi"); twolevel_id = data.getExtras().getString("id1"); three_id = data.getExtras().getString("id2"); classifyText.setText(sheng + " " + shi + " "); } } break; case CLASSIFY:// ? if (data != null) { String selection_sort = data.getExtras().getString("selection_sort");// Activity ?? classifyText.setText(selection_sort); } break; case KEYBOARD:// ? if (data != null) { list = (List<KeyBoardData>) data.getSerializableExtra("keyboard_data"); for (int i = 0; i < list.size(); i++) { selling_price = list.get(i).getSelling_price(); goods_value = list.get(i).getGoods_value(); original_price = list.get(i).getOriginal_price(); reserve_price = list.get(i).getReserve_price(); freight = list.get(i).getFreight(); check = list.get(i).isCheck(); } if (cordelesBox.isChecked() == true) { if (selling_price != null) { selling_priceEd.setText(selling_price); } } else if (auctionBox.isChecked() == true) { if (reserve_price != null) { auction_retainPriceEd.setText(reserve_price); } } else if (rent_outBox.isChecked() == true) { if (goods_value != null && freight != null) { rent_out_valueEd.setText(goods_value); if (check == true) { rent_out_freightEd.setText("0"); } else { rent_out_freightEd.setText(freight); } } } } break; case 10:// if (data != null) { for (int i = 0; i < MyAdapter.mSelectedImage.size(); i++) { photolist.add((String) data.getExtras().get(String.valueOf(i))); } } break; case 2017:// ? Log.e("onActivityResult", "?"); cropHelper.getDataFromCamera(data); break; case 2108: if (data != null && data.getParcelableExtra("data") != null) { for (int i = 0; i < times.size(); i++) { File f = new File( OSUtils.getSdCardDirectory(getApplicationContext()) + times.get(i) + "head1.png"); if (f.exists()) { camearlist.add( OSUtils.getSdCardDirectory(getApplicationContext()) + times.get(i) + "head1.png"); } } for (int k = 0; k < camearlist.size() - 1; k++) { for (int j = camearlist.size() - 1; j > k; j--) { if (camearlist.get(k).equals(camearlist.get(j))) { camearlist.remove(j); } } } for (int i = 0; i < camearlist.size(); i++) { photolist.add(camearlist.get(i)); } } break; case CameraUtils.RequestCode.FLAG_REQUEST_CAMERA_VIDEO:// if (data != null) { photolist.add(CameraUtils.CAMERA_VIDEO); } break; default: break; } for (int j = 0; j < photolist.size(); j++) { if (photolist.get(j).equals("drawable://" + R.drawable.fb_icn_carema)) { photolist.remove(j); } if (photolist.get(j).equals("drawable://" + R.drawable.fb_icn_video)) { photolist.remove(j); } } photolist.add("drawable://" + R.drawable.fb_icn_carema); photolist.add("drawable://" + R.drawable.fb_icn_video); for (int k = 0; k < photolist.size() - 1; k++) { for (int j = photolist.size() - 1; j > k; j--) { if (photolist.get(k).equals(photolist.get(j))) { photolist.remove(j); } } } adapter = new Release_GridViewAdapter(photolist, this, Release_Activity.this, times); gridView.setAdapter(adapter); gridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (photolist.get(position).equals("drawable://" + R.drawable.fb_icn_carema)) { int j = 0; for (int i = 0; i < photolist.size(); i++) { if (photolist.get(i).equals(CameraUtils.CAMERA_VIDEO)) { j++; } } if (j == 1) { if (photolist.size() < 13) { Date dt = new Date(); time = dt.getTime(); times.add(time); cropHelper = new CropHelper(Release_Activity.this, OSUtils.getSdCardDirectory(getApplicationContext()) + time + "head1.png"); mTempPhotoPath = OSUtils.getSdCardDirectory(getApplicationContext()) + time + "head1.png"; Release_Photo_Pop pop = new Release_Photo_Pop(Release_Activity.this, cropHelper, mTempPhotoPath); pop.showPopupWindow(gridView); } else { Toast.makeText(getApplicationContext(), "??~", 10).show(); } } else { if (photolist.size() < 12) { Date dt = new Date(); time = dt.getTime(); times.add(time); cropHelper = new CropHelper(Release_Activity.this, OSUtils.getSdCardDirectory(getApplicationContext()) + time + "head1.png"); mTempPhotoPath = OSUtils.getSdCardDirectory(getApplicationContext()) + time + "head1.png"; Release_Photo_Pop pop = new Release_Photo_Pop(Release_Activity.this, cropHelper, mTempPhotoPath); pop.showPopupWindow(gridView); } else { Toast.makeText(getApplicationContext(), "??~", 10).show(); } } } else if (photolist.get(position).equals("drawable://" + R.drawable.fb_icn_video)) { int j = 0; for (int i = 0; i < photolist.size(); i++) { if (photolist.get(i).equals(CameraUtils.CAMERA_VIDEO)) { j++; } } if (j != 1) { CameraUtils.openCameraForVideo(Release_Activity.this); } else { Toast.makeText(getApplicationContext(), "?~", 10).show(); } } else if (photolist.get(position).equals(CameraUtils.CAMERA_VIDEO)) {// ? Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); // ? Uri data = Uri.parse("file:///" + CameraUtils.CAMERA_VIDEO); // ??? intent.setDataAndType(data, "video/mp4"); // ? startActivity(intent); } } }); adapter.notifyDataSetChanged(); }
From source file:com.microsoft.aad.adal.AuthenticationActivity.java
private AuthenticationRequest getAuthenticationRequestFromIntent(Intent callingIntent) { AuthenticationRequest authRequest = null; if (isBrokerRequest(callingIntent)) { Logger.v(TAG, "It is a broker request. Get request info from bundle extras."); String authority = callingIntent.getStringExtra(AuthenticationConstants.Broker.ACCOUNT_AUTHORITY); String resource = callingIntent.getStringExtra(AuthenticationConstants.Broker.ACCOUNT_RESOURCE); String redirect = callingIntent.getStringExtra(AuthenticationConstants.Broker.ACCOUNT_REDIRECT); String loginhint = callingIntent.getStringExtra(AuthenticationConstants.Broker.ACCOUNT_LOGIN_HINT); String accountName = callingIntent.getStringExtra(AuthenticationConstants.Broker.ACCOUNT_NAME); String clientidKey = callingIntent.getStringExtra(AuthenticationConstants.Broker.ACCOUNT_CLIENTID_KEY); String correlationId = callingIntent .getStringExtra(AuthenticationConstants.Broker.ACCOUNT_CORRELATIONID); String prompt = callingIntent.getStringExtra(AuthenticationConstants.Broker.ACCOUNT_PROMPT); PromptBehavior promptBehavior = PromptBehavior.Auto; if (!StringExtensions.IsNullOrBlank(prompt)) { promptBehavior = PromptBehavior.valueOf(prompt); }/* w w w . j av a 2s . c o m*/ mWaitingRequestId = callingIntent.getIntExtra(AuthenticationConstants.Browser.REQUEST_ID, 0); UUID correlationIdParsed = null; if (!StringExtensions.IsNullOrBlank(correlationId)) { try { correlationIdParsed = UUID.fromString(correlationId); } catch (IllegalArgumentException ex) { correlationIdParsed = null; Logger.e(TAG, "CorrelationId is malformed: " + correlationId, "", ADALError.CORRELATION_ID_FORMAT); } } authRequest = new AuthenticationRequest(authority, resource, clientidKey, redirect, loginhint, correlationIdParsed); authRequest.setBrokerAccountName(accountName); authRequest.setPrompt(promptBehavior); authRequest.setRequestId(mWaitingRequestId); } else { Serializable request = callingIntent .getSerializableExtra(AuthenticationConstants.Browser.REQUEST_MESSAGE); if (request instanceof AuthenticationRequest) { authRequest = (AuthenticationRequest) request; } } return authRequest; }
From source file:de.tubs.ibr.dtn.dtalkie.service.TalkieService.java
@Override protected void onHandleIntent(Intent intent) { String action = intent.getAction(); if (de.tubs.ibr.dtn.Intent.RECEIVE.equals(action)) { try {/*from w w w. jav a 2 s . c o m*/ while (mClient.getSession().queryNext()) ; } catch (Exception e) { } ; } else if (ACTION_MARK_DELIVERED.equals(action)) { final BundleID received = intent.getParcelableExtra("bundleid"); try { mClient.getSession().delivered(received); } catch (Exception e) { Log.e(TAG, "Can not mark bundle as delivered.", e); } } else if (ACTION_PLAY.equals(action)) { Folder f = Folder.valueOf(intent.getStringExtra("folder")); Long msgid = intent.getLongExtra("message", 0L); // unmark the message mDatabase.mark(f, msgid, false); try { // prepare player Message msg = mDatabase.get(f, msgid); mPlayer.setDataSource(msg.getFile().getAbsolutePath()); mPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL); mPlayer.prepareAsync(); synchronized (mPlayerLock) { // set the player to playing mPlaying = true; // wait until the play-back is done while (mPlaying) { mPlayerLock.wait(); } } } catch (InterruptedException e) { Log.e(TAG, null, e); } catch (IOException e) { Log.e(TAG, null, e); } // mark the message as played mDatabase.mark(f, msgid, true); // remove notification is there are no more pending // messages removeNotification(); } else if (ACTION_PLAY_NEXT.equals(action)) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(TalkieService.this); if (prefs.getBoolean("autoplay", false) || HeadsetService.ENABLED) { Message next = mDatabase.nextMarked(Folder.INBOX, false); if (next != null) { Intent play_i = new Intent(TalkieService.this, TalkieService.class); play_i.setAction(TalkieService.ACTION_PLAY); play_i.putExtra("folder", Folder.INBOX.toString()); play_i.putExtra("message", next.getId()); startService(play_i); } } } else if (ACTION_RECORDED.equals(action)) { File recfile = (File) intent.getSerializableExtra("recfile"); // create a new bundle Bundle b = new Bundle(); // set destination b.setDestination((EID) intent.getSerializableExtra("destination")); // assign lifetime b.setLifetime(1800L); // request signing of the message b.set(ProcFlags.DTNSEC_REQUEST_SIGN, true); try { ParcelFileDescriptor fd = ParcelFileDescriptor.open(recfile, ParcelFileDescriptor.MODE_READ_ONLY); BundleID ret = mClient.getSession().send(b, fd); if (ret == null) { Log.e(TAG, "Recording sent failed"); } else { Log.i(TAG, "Recording sent, BundleID: " + ret.toString()); } recfile.delete(); } catch (FileNotFoundException ex) { Log.e(TAG, "Can not open message file for transmission", ex); } catch (SessionDestroyedException ex) { Log.e(TAG, "DTN session has been destroyed.", ex); } catch (Exception e) { Log.e(TAG, "Unexpected exception while transmit message.", e); } } else if (ACTION_RECEIVED.equals(action)) { String source = intent.getStringExtra("source"); String destination = intent.getStringExtra("destination"); Date created = (Date) intent.getSerializableExtra("created"); Date received = (Date) intent.getSerializableExtra("received"); File file = (File) intent.getSerializableExtra("file"); // add message to database Message msg = new Message(source, destination, file); msg.setCreated(created); msg.setReceived(received); mDatabase.put(Folder.INBOX, msg); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); if (prefs.getBoolean("notification", true)) { // create a notification for this message createNotification(); } Intent play_i = new Intent(TalkieService.this, TalkieService.class); play_i.setAction(ACTION_PLAY_NEXT); startService(play_i); } }