Remove Folders from DDMS - android

I need to remove a particular folder from the /mnt/sdcard/new.
I am looking at the folder with the DDMS in Eclipse.
How do we remove a particular folder.
Thanks in advance.

You can use rm command with -r parameter to delete a nonempty folder.
C:\> adb shell
$ rm -r /mnt/sdcard/Android/data/mydirectory/
NOTE: rmdir can delete only a nonempty folder.

C:\>adb shell
$ rmdir /mnt/sdcard/Android/data/mydirectory/

Please use below method for delete folder from sdcard
// Deletes all files and subdirectories under dir.
// Returns true if all deletions were successful.
// If a deletion fails, the method stops attempting to delete and returns false.
public static boolean deleteDir(File dir) {
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i=0; i<children.length; i++) {
boolean success = deleteDir(new File(dir, children[i]));
if (!success) {
return false;
}
}
}
// The directory is now empty so delete it
return dir.delete();
}
write below code for call deleteDir() method
// Delete an empty directory
boolean success = (new File("directorypath")).delete();
if (!success) {
// Deletion failed Message
}

boolean success = (
new File("/data/data/yourpackege/New Folder")).delete();
if (!success) {
// Deletion failed Message
Toast.makeText(getApplicationContext(),"not deleted : ", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getApplicationContext()," deleted : ", Toast.LENGTH_LONG).show();
}

If you want to delete any folder from ddms first you have to go to adb shell through cmd
simple go to the path where your sdk\platform-tools\ is located ,there is your adb shell
to run command for deleting folders you must first root your device by simply typing
adb root
then you can delete the folder using
rmdir /mnt/sdcard/folder
to delete folder with files
rm -r /mnt/sdcard/folder
hope my answer will help anyone(beginners)

Related

ADB command history

I need ADB command history similar to bash history.
I need a history file to be created in the Android phone.
Is there any such functionality?
If not, can any one point me to the code in ADBD where it receives the commands form the desktop?
I can implement the same.
I tried enabling shell history on Android, but it does not work for the commands invoked by ADB.
I changed the code in ADBD to implement the functionality.
Modified file: system/core/adb/shell_service.cpp
bool Subprocess::ForkAndExec(std::string* error) {
-----------
/* Writing the command to history file just before it is executed. */
addToHistory(command_.c_str());
execle(_PATH_BSHELL, _PATH_BSHELL, "-c", command_.c_str(), nullptr, cenv.data());
-----------
}
void addToHistory(const char * cmd)
{
FILE *fp = fopen("/data/adb_history.txt", "a");
if(NULL == fp)
{
printf("ERROR\n");
return;
}
fwrite(cmd, strlen(cmd), 1, fp);
fwrite("\n", 1, 1, fp);
fclose(fp);
return;
}
For now, it is working in superuser mode only.

Unable to access data/misc folder contents in root mode

I have a rooted device running MarshMallow. I have integrated Chainfire's library Library in my code. I get the superuser prompt and granted the permission. After that I am trying to get the folders inside /data/misc/ but it returns me null. I have READ_EXTERNAL_STORAGE permission also in manifest and in App->Permissions have granted the same.
What I have tried so far ..
Checked /data/misc/ folder in ES File Explorer. It does have folders.
From cmd, ran
adb shell
su
cd /data/misc/
ls
Was able to see the folders in cmd.
Can anyone please help how to solve this?
Code :
private final static String ROOT_DIR = "/data/misc/";
#Override
protected Void doInBackground(Void... params) {
// Let's do some SU stuff
suAvailable = Shell.SU.available();
if (suAvailable) {
Log.d("TAG", "SU there");
//List<String> output = Shell.SU.run("mount -o rw,remount /");
//Log.d("TAG","Output ="+output); // empty
File file = new File(ROOT_DIR);
if (file.exists()) {
Log.d("TAG", "File exists"+ file.getAbsolutePath()+ file.isDirectory());
File file1[] = file.listFiles(); // RETURNS NULL HERE
}
}
}

Copy files to root Partition programatically

I am developing a root app for modifying build.prop programatically.
I copied build.prop from /system/build.prop to /sdcard/
but after modifying it I was unable to copy back to root partition
here is my code for copying build.prop from /system/build.prop to /sdcard/
protected void SUCommand()
{
String sSUCommand = "cp /system/build.prop /sdcard/";
final String[] sCommand = {"su","-c",sSUCommand};
Thread thSUProcess = new Thread()
{
public void run()
{
try
{
Process p = Runtime.getRuntime().exec(sCommand);
}
catch(Exception e){}
}
};
thSUProcess.start();
}
I changed String sSUCommand = "cp /system/build.prop /sdcard/"; to String sSUCommand = "cp /sdcard/build.prop /system/"; to copy it to system partition
but didn't worked
I already rooted my phone and running lot of root apps successfully
please tell me the right way to do it
You might want to mount system partition as rw instead of rd so as to do it
https://android.stackexchange.com/questions/25250/how-to-mount-system-in-rw-mode-if-no-custom-recovery

how to save a csv file in Processing for Android?

For the life of me, I cannot seem to write a simple tsv file on Android 4.2.2 using Processing for Android.
This code simply fails silently...
try {
saveTable(tsv,"data.tsv");
}
catch (Exception e) {
println(e);
}
I have set the permission: WRITE_EXTERNAL_STORAGE but this made no difference.
I am going crazy!!
Thanks for any help!
Bob
Sorry for the noise.... I found the solution finally:
using a terminal app on tyhe Nexus 4 (Android 4.2.2), I created a directory:
$ mkdir /sdcard/MyStuff
the code should now read
saveTable(tsv,"//sdcard/MyStuff/data.tsv");
Note the // before "sdcard" directory name - I guess that somehow makes the system consider the path as "external storage" and so it's ok!
What complexity!
You can also use the GetExternalStorageDirectory method:
String basePath = Environment.getExternalStorageDirectory().getAbsolutePath();
then concatenate the string to match your path:
basePath += "MyStuff";
This requires that you import the Environment Class from the Android SDK:
import android.os.Environment;
Also, in Processing, you can just use the 'sdcard' nomenclature - ie.:
basePath = "//sdcard//MyStuff";
Also, a related answer about making a directory with terminal - here is how you would do it from Processing:
import java.io.File;
import java.io.IOException;
String dirName;
// Create Directory
try{
dirName = "//sdcard//MyStuff"; // Or use te Environment Class -- see above
File newFile = new File(dirName);
newFile.mkdirs();
if(newFile.exists()) {
//
if(newFile.isDirectory()) {
//
}
else {
}
}
else {
println("Directory Doesn't Exist... Creating");
}
}
catch(Exception e) {
e.printStackTrace();
}
This way your code knows about the path automatically... Hope that helps!

Android - OnObbStateChangeListener.MOUNTED is true but isObbMounted() is false, what is wrong?

I have an extension file under "/sdcard/Android/obb/com.example.obbtest/vid-exp1.obb". It contains an MP4 file and I want to mount the .obb to read the file.
This is what I'm doing to mount it:
String obbDir = "/sdcard/Android/obb/com.example.obbtest/vid-exp1.obb";
.
StorageManager storage = (StorageManager) getApplicationContext().getSystemService(STORAGE_SERVICE);
storage.mountObb(obbDir, null, listener);
This is the listener code:
OnObbStateChangeListener listener = new OnObbStateChangeListener() {
#Override
public void onObbStateChange(String path, int state) {
if (state == OnObbStateChangeListener.MOUNTED) {
toastString("Mounted! According to the listener");
//Test it with the isObbMounted()
if (storage.isObbMounted(obbDir)) {
toastString("Efectively mounted!");
} else {
toastString("Not really :(");
}
toastString(storage.getMountedObbPath(obbDir));
} else {
tuestameString("NOT mounted according to the listener");
}
}
};
Unfortunately the output I get is a toast saying "Mounted! According to the listener" followed by "Not really :(". I designed this test because when I tried getMountedObbPath(obbDir) I got a null String instead of the path. I've made sure the .obb file exists and all that, without it or without the correct encription key I don'get "Mounted!...".
I don't understand why OnObbStateChangeListener.MOUNTED is true but isObbMounted(obbDir) false. Does anyone know what I doing wrong?
Had this problem on a Samsung device. It happens when /mnt/sdcard/ is not a directory but a symlink to another dir (in my case that was /storage/sdcard0).
In this case StorageManager uses not the path to the obb that you have specified, but the path with symlinks resolved: isObbMounted("/mnt/sdcard/my.obb") returns false and isObbMounted("/storage/sdcard0/my.obb") is true.
To access the mounted obb, you must not use the path obbDir, but the path passed to onObbStateChange() in the first argument: isObbMounted(path).

Categories

Resources