Android Open Source - dCache-Cloud New Media Receiver






From Project

Back to project page dCache-Cloud.

License

The source code is released under:

Copyright ? 2013, Michael Stapelberg and contributors All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following ...

If you think the Android project dCache-Cloud listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package de.desy.dCacheCloud.BCReceiver;
/*from www  . j  a v  a  2s.c  o  m*/
import de.desy.dCacheCloud.DatabaseHelper;
import de.desy.dCacheCloud.UploadService;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.util.Log;

public class NewMediaReceiver extends BroadcastReceiver {

  @Override
  public void onReceive(Context context, Intent intent) {
    Log.d("davsync", "received pic or video intent");

    boolean isNewPic = android.hardware.Camera.ACTION_NEW_PICTURE.equals(intent.getAction());
    boolean isNewVid = android.hardware.Camera.ACTION_NEW_VIDEO.equals(intent.getAction());

    if (!isNewPic && !isNewVid) return;

    SharedPreferences preferences = context.getSharedPreferences("de.desy.dCacheCloud_preferences",
        Context.MODE_PRIVATE);

    if (isNewPic && !preferences.getBoolean("auto_sync_camera_pictures", true)) {
      Log.d("davsync", "automatic camera picture sync is disabled, ignoring");
      return;
    }

    if (isNewVid && !preferences.getBoolean("auto_sync_camera_videos", true)) {
      Log.d("davsync", "automatic camera video sync is disabled, ignoring");
      return;
    }

    boolean syncOnWifiOnly = preferences.getBoolean("auto_sync_on_wifi_only", true);

    Log.d("davsync", "New picture was taken");
    Uri uri = intent.getData();
    Log.d("davsync", "picture uri = " + uri);

    ConnectivityManager cs = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cs.getActiveNetworkInfo();
    if (info == null) {
      return;
    }

    // If we have WIFI connectivity, upload immediately
    boolean isWifi = info.isConnected() && (ConnectivityManager.TYPE_WIFI == info.getType());
    if (!syncOnWifiOnly || isWifi) {
      Log.d("davsync", "Trying to upload " + uri + " immediately (on WIFI)");
      Intent ulIntent = new Intent(context, UploadService.class);
      ulIntent.putExtra(Intent.EXTRA_STREAM, uri);
      context.startService(ulIntent);
    } else {
      Log.d("davsync", "Queueing " + uri + "for later (not on WIFI)");
      // otherwise, queue the image for later
      DatabaseHelper helper = new DatabaseHelper(context);
      helper.queueUri(uri);
    }
  }

}




Java Source Code List

External.Contents.java
External.IntentIntegrator.java
External.IntentResult.java
External.QRCodeEncoder.java
de.desy.dCacheCloud.CountingInputStreamEntity.java
de.desy.dCacheCloud.CryptoHelper.java
de.desy.dCacheCloud.DatabaseHelper.java
de.desy.dCacheCloud.DownloadService.java
de.desy.dCacheCloud.KeyStoreHelper.java
de.desy.dCacheCloud.MySSLSocketFactory.java
de.desy.dCacheCloud.ServerHelper.java
de.desy.dCacheCloud.UploadService.java
de.desy.dCacheCloud.Activities.FriendFoundActivity.java
de.desy.dCacheCloud.Activities.ImportDataActivity.java
de.desy.dCacheCloud.Activities.MainActivity.java
de.desy.dCacheCloud.Activities.ProfileActivity.java
de.desy.dCacheCloud.Activities.ServerViewActivity.java
de.desy.dCacheCloud.Activities.SettingsActivity.java
de.desy.dCacheCloud.Activities.ShareDataActivity.java
de.desy.dCacheCloud.Activities.ShareWithFriendActivity.java
de.desy.dCacheCloud.Activities.UploadActivity.java
de.desy.dCacheCloud.Activities.UserPasswordActivity.java
de.desy.dCacheCloud.BCReceiver.NetworkReceiver.java
de.desy.dCacheCloud.BCReceiver.NewMediaReceiver.java