1

I am a new in android development and i have a question.

I developed my application with Android Studio and installed it on my phone(not rooted).

I can not see it in /data/"package name".

But i can see other applications: Facebook ,Whatsapp etc.

Why? How can i install it and see it like Facebook package directory.

Thanks

user3428151
  • 449
  • 6
  • 23
  • I'm sure we have a duplicate of this, but am not finding it. Anyway, /data is not readable via debug tools on a *secured* device in the way it is on an emulator or hacked/engineering device where adb runs as root. There are ways to make exceptions in your own apps' directories, especially in debug builds. – Chris Stratton Jul 31 '14 at 18:05

2 Answers2

3

On a system standpoint, /data refers to the system's data directory located at the root of the device's filesystem. However, on a user standpoints, it can be understood as the data directory located at the root of the external storage of your device (often, but not always, a SD card). For the system, this directory's path is different: /mnt/sdcard/data for example.

As the system's /data directory is not accessible through adb shell, ddms or any filesytem explorer on a non-rooted production device, I'm assuming that you are referring to the external storage's data directory.

  • External storage

<external-storage>/data, or preferably <external-storage>/Android/data, is used to store application-related data under a directory that have the same name as your application package name (typically ext.yourbrandname.yourappname).

But your application doesn't create such a directory automatically. Your app has to create this directory if needed. Hence the fact you don't see such a directory is not an evidence that the application is not installed.

I use the code below (usually: createRootDirectory((Activity) this)) to create such directories. This code is designed for minSdkVersion="8" targetSdkVersion="19". Optimizations might exist for higher minSdkVersion, I didn't investigate in this:

public static String storagePathToAbsolutePath(String pathFromStorageRoot) {
    final StringBuffer buffer = new StringBuffer(255);

    buffer.append(Environment.getExternalStorageDirectory().getAbsolutePath());

    if (pathFromStorageRoot.charAt(0) != '/') {
        buffer.append('/');
    }

    buffer.append(pathFromStorageRoot);

    return buffer.toString();
}

public static boolean createRootDirectory(Context ctx) {
    // Constant, copied here: private static final String BASE_DIR = "/Android/data/";
    final String dataDir = storagePathToAbsolutePath(BASE_DIR + getPackageName(ctx) + "/")  
    final File f = new File(dataDir);
    return f.mkdirs();
}

Side note: using [external-storage]/Android/data/<your application package name> is a clean and interesting solution: if the user uninstalls the application, this corresponding data directory will automatically be deleted. This won't happen if <your application package name> is located anywhere else, at least with old versions of Android such as 8.

  • Internal storage

/data is a system directory used to store app-related libraries, caches, etc. Directory /data

It contains a data directory (so its path is /data/data/). In this one, you'll actually find one directory per installed application package:

Directory /data/data

Each and every installed package has a directory named after its package name ("ext.yourbrandname.yourappname") in the /data/data directory, for system use. Your application, whatever it is has a directory there if it is installed.

Shlublu
  • 10,917
  • 4
  • 51
  • 70
  • Thank you to the downvoter, but what I said is accurate. – Shlublu Jul 31 '14 at 18:06
  • How can i program this directory creation? – user3428151 Jul 31 '14 at 18:06
  • Thank you, just a little question where i need to put this code? or from where to call one of this functions? My phone is not rooted. it will work? – user3428151 Aug 03 '14 at 06:37
  • Yes, the code above will work if your application requests the permission `` in `AdroidManifest.xml`. The best is to use it just before anything else in your app need to read or write something to this directory. – Shlublu Aug 03 '14 at 09:10
  • After i install the application via debug . all the data(data,database,images) will be stored on the new path? or every change i need to update/copy the files that changed? – user3428151 Aug 03 '14 at 10:22
  • @user3428151 Nothing will be automatic there, this directory is like any other on the application standpoint. SHould you wish the databases, images, or any other files to be stored there, you have to explicitely specify this path when creating/saving these objects. – Shlublu Aug 03 '14 at 10:28
-1
  1. Android Will automatically create a Directory of your full Package Name if you store a file in Internal Storage.
  2. Saving files in External Storage is Preferable.
  3. Before Posting a Query first search in the Stack Overflow forums question as Answered Already. Similar Post Answered Already click on this Links

here is my code for you: Am reading a Picture file in res/raw folder and Writing it to Internal Storage

        package com.splash.myapp;

        import java.io.IOException;
        import java.io.InputStream;
        import java.io.OutputStream;

        import android.app.Activity;
        import android.content.Context;
        import android.os.Bundle;

        public class SavingFiles extends Activity {

            OutputStream fos;

            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main_activity);
                try {
                    InputStream inputStreamObj = getResources().openRawResource(R.raw.pics);
                    fos = openFileOutput("pics.png", Context.MODE_PRIVATE);
                    final byte[] buffer = new byte[1024];
                    int bytesRead = 0;
                    while ((bytesRead = inputStreamObj.read(buffer)) > 0) {

                        fos.write(buffer);
                    }
                    inputStreamObj.close();

                } catch (Exception e) {

                    e.printStackTrace();
                } finally {
                    try {
                        fos.flush();
                        fos.close();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                }
            }

        }

You can check in DDMS data/data /your packageName/file

Community
  • 1
  • 1
VegeOSplash
  • 214
  • 1
  • 3