Example usage for android.content Context getExternalFilesDir

List of usage examples for android.content Context getExternalFilesDir

Introduction

In this page you can find the example usage for android.content Context getExternalFilesDir.

Prototype

@Nullable
public abstract File getExternalFilesDir(@Nullable String type);

Source Link

Document

Returns the absolute path to the directory on the primary shared/external storage device where the application can place persistent files it owns.

Usage

From source file:com.android.rahul.myselfieapp.Fragment.CamVideoFragment.java

private String getVideoFilePath(Context context) {
    return context.getExternalFilesDir(null).getAbsolutePath() + "/" + System.currentTimeMillis() + ".mp4";
}

From source file:com.quectel.tsrecordtest.Camera2VideoFragment.java

private String getVideoFilePath(Context context) {
    final File dir = context.getExternalFilesDir(null);
    return (dir == null ? "" : ("/sdcard/DCIM" + "/")) + System.currentTimeMillis() + ".ts";
}

From source file:netlab.fakturk.cam2vidndk.Camera2VideoFragment.java

private String getVideoFilePath(Context context) {
    return context.getExternalFilesDir(null).getAbsolutePath() + "/" + System.currentTimeMillis() + ".avi";
}

From source file:com.mebene.ACHud.Camera2VideoFragment.java

private String getVideoFilePath(Context context) {
    final File dir = context.getExternalFilesDir(null);
    return (dir == null ? "" : (dir.getAbsolutePath() + "/")) + System.currentTimeMillis() + ".mp4";
}

From source file:com.caseystalnaker.android.popinvideodemo.fragments.Camera2VideoFragment.java

private String getVideoFilePath(final Context context) {
    return context.getExternalFilesDir(null).getAbsolutePath() + "/" + System.currentTimeMillis() + ".mp4";
}

From source file:mgumiero9.com.talentcubetest.view.Camera2VideoFragment.java

private String getVideoFilePath(Context context) {
    return context.getExternalFilesDir(null).getAbsolutePath() + "/answerq1.mp4";
}

From source file:com.richwareham.android.logallthethings.Camera2VideoFragment.java

private String getLogFilePathPrefix(Context context) {
    return context.getExternalFilesDir(null).getAbsolutePath() + "/" + System.currentTimeMillis();
}

From source file:com.vonglasow.michael.satstat.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    defaultUEH = Thread.getDefaultUncaughtExceptionHandler();

    Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
        public void uncaughtException(Thread t, Throwable e) {
            Context c = getApplicationContext();
            File dumpDir = c.getExternalFilesDir(null);
            DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.ROOT);
            fmt.setTimeZone(TimeZone.getTimeZone("UTC"));
            String fileName = String.format("satstat-%s.log", fmt.format(new Date(System.currentTimeMillis())));

            File dumpFile = new File(dumpDir, fileName);
            PrintStream s;/*  ww w.j a  va2  s .c  om*/
            try {
                InputStream buildInStream = getResources().openRawResource(R.raw.build);
                s = new PrintStream(dumpFile);
                s.append("SatStat build: ");

                int i;
                try {
                    i = buildInStream.read();
                    while (i != -1) {
                        s.write(i);
                        i = buildInStream.read();
                    }
                    buildInStream.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }

                s.append("\n\n");
                e.printStackTrace(s);
                s.flush();
                s.close();

                Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                Uri contentUri = Uri.fromFile(dumpFile);
                mediaScanIntent.setData(contentUri);
                c.sendBroadcast(mediaScanIntent);
            } catch (FileNotFoundException e2) {
                e2.printStackTrace();
            }
            defaultUEH.uncaughtException(t, e);
        }
    });

    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    mSharedPreferences.registerOnSharedPreferenceChangeListener(this);
    prefUnitType = mSharedPreferences.getBoolean(Const.KEY_PREF_UNIT_TYPE, prefUnitType);
    prefKnots = mSharedPreferences.getBoolean(Const.KEY_PREF_KNOTS, prefKnots);
    prefCoord = Integer
            .valueOf(mSharedPreferences.getString(Const.KEY_PREF_COORD, Integer.toString(prefCoord)));
    prefUtc = mSharedPreferences.getBoolean(Const.KEY_PREF_UTC, prefUtc);
    prefCid = mSharedPreferences.getBoolean(Const.KEY_PREF_CID, prefCid);
    prefCid2 = mSharedPreferences.getBoolean(Const.KEY_PREF_CID2, prefCid2);
    prefWifiSort = Integer
            .valueOf(mSharedPreferences.getString(Const.KEY_PREF_WIFI_SORT, Integer.toString(prefWifiSort)));
    prefMapOffline = mSharedPreferences.getBoolean(Const.KEY_PREF_MAP_OFFLINE, prefMapOffline);
    prefMapPath = mSharedPreferences.getString(Const.KEY_PREF_MAP_PATH, prefMapPath);

    ActionBar actionBar = getSupportActionBar();

    setContentView(R.layout.activity_main);

    // Find out default screen orientation
    Configuration config = getResources().getConfiguration();
    WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    int rot = wm.getDefaultDisplay().getRotation();
    isWideScreen = (config.orientation == Configuration.ORIENTATION_LANDSCAPE
            && (rot == Surface.ROTATION_0 || rot == Surface.ROTATION_180)
            || config.orientation == Configuration.ORIENTATION_PORTRAIT
                    && (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270));
    Log.d(TAG, "isWideScreen=" + Boolean.toString(isWideScreen));

    // Create the adapter that will return a fragment for each of the
    // primary sections of the app.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    Context ctx = new ContextThemeWrapper(getApplication(), R.style.AppTheme);
    mTabLayout = new TabLayout(ctx);
    LinearLayout.LayoutParams mTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    mTabLayout.setLayoutParams(mTabLayoutParams);

    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        TabLayout.Tab newTab = mTabLayout.newTab();
        newTab.setIcon(mSectionsPagerAdapter.getPageIcon(i));
        mTabLayout.addTab(newTab);
    }

    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setCustomView(mTabLayout);

    mTabLayout.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
    mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout));

    // This is needed by the mapsforge library.
    AndroidGraphicFactory.createInstance(this.getApplication());

    // Get system services for event delivery
    locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mOrSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
    mAccSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mGyroSensor = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
    mMagSensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    mLightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
    mProximitySensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
    mPressureSensor = sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE);
    mHumiditySensor = sensorManager.getDefaultSensor(Sensor.TYPE_RELATIVE_HUMIDITY);
    mTempSensor = sensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE);
    telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
}

From source file:li.zeitgeist.android.worker.ThumbnailWorker.java

/**
 * Constructs the thumbnail loader./*from w  w w  .j a v a  2 s  . co  m*/
 *
 * This starts the thread pool, initializes the memory cache,
 * and creates the directories for the disk-cache (if necessary).
 * 
 * @param context of the gallery service.
 */
public ThumbnailWorker(Context context) {
    Log.v(TAG, "constructed");

    api = ZeitgeistApiFactory.createInstance(context);

    // start thread pool
    pool = Executors.newFixedThreadPool(THREADS);

    // initialize memory cache
    /*
            
     TODO: somehow that doesn't work at all, why?
            
    int memCacheSize = 2 * 1024 * 1024; // 2 MiB
    memCache = new LruCache<Integer, Bitmap>(memCacheSize) {
        protected int sizeOf(Integer key, Bitmap value) {
            return value.getRowBytes() * value.getHeight();
        }
    };
            
    */
    // 150 * ~16 KiB = 2250 KiB
    memCache = new LruCache<Integer, Bitmap>(150);

    // create disk cache directory
    File externalStorageDirectory = context.getExternalFilesDir(null);
    diskCache = new File(externalStorageDirectory, "cache");
    if (!diskCache.exists()) {
        diskCache.mkdirs();
    }
    Log.d(TAG, "disk cache: " + diskCache.getAbsolutePath());

    // load video overlay bitmap
    videoOverlayBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.video_overlay);
}

From source file:com.nextgis.mobile.map.MapBase.java

/**
 * The base map class/* ww  w .j a  v a2 s .co  m*/
 */

public MapBase(Context context) {
    super(context);

    mName = context.getString(R.string.default_map_name);
    mNewId = 0;
    mListeners = new ArrayList<MapEventListener>();
    mLayers = new ArrayList<Layer>();

    mCPUTotalCount = Runtime.getRuntime().availableProcessors() - 1;
    if (mCPUTotalCount < 1)
        mCPUTotalCount = 1;
    mContinueDrawing = false;

    newtworkUtil = new NetworkUtil(context);

    createHandler();

    //initialise display
    mDisplay = new GISDisplay(context);

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    File defaultPath = context.getExternalFilesDir(PREFS_MAP);
    mMapPath = new File(sharedPreferences.getString(KEY_PREF_MAP_PATH, defaultPath.getPath()));

    mDrawWorkQueue = new LinkedBlockingQueue<Runnable>();
    mDrawThreadPool = new ThreadPoolExecutor(1, mCPUTotalCount, KEEP_ALIVE_TIME, KEEP_ALIVE_TIME_UNIT,
            mDrawWorkQueue);

    setKeepScreenOn(true);
}