[Q]Copy files from assets to system directory - Java for Android App Development

I'm developing an Android app that purchase errors copying files from /assets to /system. I have this code but I don't know why isn't works. Can anybody help me, This is my code:
Code:
public class MainActivity extends Activity
{
ProgressDialog progressDialog = null;
/** Called when the activity is first created. */
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
{
}}
public void reparar(View view) throws IOException {
progressDialog = ProgressDialog.show(MainActivity.this, "Instalando parche", "Por favor, espere...", true);
//Aqi poner el conjunto de acciones hasta mover los archivos al
//directorio system
try {
ProcessBuilder pb = new ProcessBuilder(new String[] { "su", "mount -o rw, remount -t yaffs2 /dev/block/mtdblock4 /system", "cp /assets/keypad/file.format /system", "mount -o ro, remount -t yaffs2 /dev/block/mtdblock4 /system" });
java.lang.Process process = pb.start();
process.waitFor();
} catch (IOException e) {
}
catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
progressDialog.dismiss();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Debe reiniciar el terminal. Desea hacerlo ahora?")
.setTitle("Instalacion satisfactoria!")
.setCancelable(false)
.setNegativeButton("Reiniciar mas tarde",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
})
.setPositiveButton("Reiniciar ahora",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// metodo que se debe implementar
try {
ProcessBuilder pb = new ProcessBuilder(new String[] { "su", "-c", "/system/bin/reboot" });
java.lang.Process process = pb.start();
process.waitFor();
} catch (IOException e) {
}
// TODO Auto-generated method stub
catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
AlertDialog alert = builder.create();
alert.show();
}
[user=439709]@override[/user]
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.options, menu);
return true;
}
}
Enviado desde mi GT-S5570I usando Tapatalk 2

Please! Help me :crying:

DannyGM16 said:
Please! Help me :crying:
Click to expand...
Click to collapse
first you'll have to copy the file from the apk-assets folder to /data/data/your.pqackage.name/file/file.format, after that you can copy it as root to the system partition.
Code:
String data_storage_root = mContext.getFilesDir().toString();
InputStream is= null;
OutputStream os = null;
File h = new File(data_storage_root+"/file.format");
if (h.exists()) h.setWritable(true, true);
try {
is = mContext.getResources().getAssets().open("keypad/file.format");
os = new FileOutputStream(data_storage_root+"/file.format");
IOUtils.copy(is, os);
is.close();
os.flush();
os.close();
os = null;
Log.d(TAG, "success copying");
} catch (IOException e) {
Log.w(TAG, "failed copying");
}
h.setExecutable(false, true);
h.setReadable(true, true);
h.setWritable(false, true);

Zatta said:
first you'll have to copy the file from the apk-assets folder to /data/data/your.pqackage.name/file/file.format, after that you can copy it as root to the system partition.
Code:
String data_storage_root = mContext.getFilesDir().toString();
InputStream is= null;
OutputStream os = null;
File h = new File(data_storage_root+"/file.format");
if (h.exists()) h.setWritable(true, true);
try {
is = mContext.getResources().getAssets().open("keypad/file.format");
os = new FileOutputStream(data_storage_root+"/file.format");
IOUtils.copy(is, os);
is.close();
os.flush();
os.close();
os = null;
Log.d(TAG, "success copying");
} catch (IOException e) {
Log.w(TAG, "failed copying");
}
h.setExecutable(false, true);
h.setReadable(true, true);
h.setWritable(false, true);
Click to expand...
Click to collapse
Thanks for the info, I didn't know it!
When I use this code I have two issues, in mContext and IOUtils, what am I doing wrong?
And Copying from data to system I preffer doing it with RootTools. Can u help me pls??

Oh, sorry. This is a snipplet from one of my apps, it uses a library called commons-io-2.1.jar for the IOUtils. The context is just the context from the loader where this snipplet comes from.
I've never used RootUtils so I can't help you with that, sorry.
When I'm not on my phone but at a computer I'll search for an alternative to extract the file from the apk for you (if you haven't found it by then, SO will have an answer for sure).
Taptalked u see .. əəs n pəʞlɐʇdɐʇ

Zatta said:
Oh, sorry. This is a snipplet from one of my apps, it uses a library called commons-io-2.1.jar for the IOUtils. The context is just the context from the loader where this snipplet comes from.
I've never used RootUtils so I can't help you with that, sorry.
When I'm not on my phone but at a computer I'll search for an alternative to extract the file from the apk for you (if you haven't found it by then, SO will have an answer for sure).
Taptalked u see .. əəs n pəʞlɐʇdɐʇ
Click to expand...
Click to collapse
Lots of thanks! I'm waiting for you
Enviado desde mi GT-S5570I usando Tapatalk 2

Zatta said:
Oh, sorry. This is a snipplet from one of my apps, it uses a library called commons-io-2.1.jar for the IOUtils. The context is just the context from the loader where this snipplet comes from.
I've never used RootUtils so I can't help you with that, sorry.
When I'm not on my phone but at a computer I'll search for an alternative to extract the file from the apk for you (if you haven't found it by then, SO will have an answer for sure).
Taptalked u see .. əəs n tapatalked
Click to expand...
Click to collapse
Code:
import android.app.*;
import android.content.*;
import android.os.*;
import android.os.Process;
import android.util.*;
import android.view.*;
import android.view.View.*;
import android.widget.Button;
import android.widget.Toast;
import java.io.*;
import com.stericson.RootTools.RootTools;
import com.stericson.RootTools.execution.CommandCapture;
import java.util.concurrent.*;
import com.stericson.RootTools.exceptions.*;
import org.apache.commons.io.*;
public class MainActivity extends Activity {
{
}
ProgressDialog progressDialog = null;
/** Called when the activity is first created. */
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
if (RootTools.isAccessGiven()) {
} else {
makeToast("Se necesitan permisos de Superusuario!");
finish();
}
}
public void reparar(View view) throws IOException, TimeoutException, RootDeniedException, InterruptedException {
CopyFromAssets();
CopyFromAssetstosystem();
End();
}
public void CopyFromAssets() {
progressDialog = ProgressDialog.show(MainActivity.this, "Instalando parche", "Por favor, espere...", true);
String data_storage_root = getFilesDir().toString();
InputStream is= null;
OutputStream os = null;
File h = new File(data_storage_root+"/caca.txt");
File p = new File(data_storage_root+"/caca2.txt");
if (h.exists()) h.setWritable(true, true);
if (p.exists()) h.setWritable(true, true);
try {
is = getResources().getAssets().open("keypad/caca.txt");
is = getResources().getAssets().open("keypad/caca2.txt");
os = new FileOutputStream(data_storage_root+"/sec_key.kl");
os = new FileOutputStream(data_storage_root+"/sec_keypad.kl");
IOUtils.copy(is, os);
is.close();
os.flush();
os.close();
os = null;
} catch (IOException e) {
makeToast("Fallo al copiar");
finish();
}
h.setExecutable(false, true);
h.setReadable(true, true);
h.setWritable(false, true);
}
public void CopyFromAssetstosystem() throws TimeoutException, IOException, RootDeniedException {
CommandCapture command = new CommandCapture(0, "su", "mount -o rw, remount -t yaffs2 /dev/block/mtdblock4 /system", "cp /data/data/com.fixer.gminipop/files/caca.txt /system", "mount -o ro, remount -t yaffs2 /dev/block/mtdblock4 /system");
RootTools.getShell(true).add(command).waitForFinish();
}
public void End() {
ClosePD();
AlertDialog();
}
public void AlertDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Es necesario reiniciar para que se apliquen los cambios. Desea hacerlo ahora?")
.setTitle("Instalacion satisfactoria!")
.setCancelable(false)
.setNegativeButton("Reiniciar mas tarde",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
})
.setPositiveButton("Reiniciar ahora",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// metodo que se debe implementar
try {
ProcessBuilder pb = new ProcessBuilder(new String[] { "su", "-c", "/system/bin/reboot" });
java.lang.Process process = pb.start();
process.waitFor();
} catch (IOException e) {
}
// TODO Auto-generated method stub
catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
AlertDialog alert = builder.create();
alert.show();
}
public void ClosePD() {
progressDialog.dismiss();
}
private static void copy(InputStream is, OutputStream os) {
// TODO Auto-generated method stub
}
public void makeToast(String msg) {
Context context = getApplicationContext();
CharSequence text = msg;
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
public void RootActions() {
}
}
This is all my code, I use your library and RootTool library.
I have two issues:
1- Error in waitForFinish();
2- processDialog don't appear.
Enviado desde mi GT-S5570I usando Tapatalk 2

Hi,
I've rewrote my snipplet not to use the apache library (eventually it is just one method that was used so this is more clean) and added that to a asynctask.
Better late than never now you have rewritten yours as well :S Attached is the eclipse project.
Also, in your code you are trying to copy two files, that is not going to work like that. You define the inputstream and the outputstream twice. I will make this thing work for you if you haven't figured it out tomorrow, will take 24 hrs for me to come back on this. I don't use roottools as I said but maybe I'll look into that as well. Else I will give you an alternative.
Code:
package by.zatta.copyassets;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.widget.Toast;
public class MainActivity extends Activity {
private static final String TAG = "Copy Example";
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new PlantFiles().execute();
}
private void doneBackground(boolean succes){
// this method should be used to progress further after,
// update the ui, do other things like copying the file to /system
if (succes)
Toast.makeText(this, "Copied!", Toast.LENGTH_LONG).show();
else
Toast.makeText(this, "Failed", Toast.LENGTH_LONG).show();
}
private class PlantFiles extends AsyncTask<Void, Void, Boolean> {
protected Boolean doInBackground(Void... arg0) {
String data_storage_root = getApplicationContext().getFilesDir().toString();
boolean copied=false;
InputStream is= null;
OutputStream os = null;
File h = new File(data_storage_root+"/file.format");
if (h.exists()) h.delete();
try {
is = getApplicationContext().getResources().getAssets().open("keypad/file.format");
os = new FileOutputStream(data_storage_root+"/file.format");
if (copy(is, os)) copied = true;
is.close();
os.flush();
os.close();
os = null;
Log.d(TAG, "success copying certificate generic");
} catch (IOException e) {
Log.w(TAG, "failed copying certificate generic");
}
return copied;
}
protected void onPostExecute(Boolean result){
doneBackground(result);
}
private boolean copy(InputStream in, OutputStream out){
try {
byte[] buffer = new byte[1024];
int read;
while (( read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
return true;
} catch (IOException e) {
Log.w(TAG, "problems copying");
return false;
}
}
}
}

Zatta said:
Hi,
I've rewrote my snipplet not to use the apache library (eventually it is just one method that was used so this is more clean) and added that to a asynctask.
Better late than never now you have rewritten yours as well :S Attached is the eclipse project.
Also, in your code you are trying to copy two files, that is not going to work like that. You define the inputstream and the outputstream twice. I will make this thing work for you if you haven't figured it out tomorrow, will take 24 hrs for me to come back on this. I don't use roottools as I said but maybe I'll look into that as well. Else I will give you an alternative.
Code:
package by.zatta.copyassets;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.widget.Toast;
public class MainActivity extends Activity {
private static final String TAG = "Copy Example";
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new PlantFiles().execute();
}
private void doneBackground(boolean succes){
// this method should be used to progress further after,
// update the ui, do other things like copying the file to /system
if (succes)
Toast.makeText(this, "Copied!", Toast.LENGTH_LONG).show();
else
Toast.makeText(this, "Failed", Toast.LENGTH_LONG).show();
}
private class PlantFiles extends AsyncTask<Void, Void, Boolean> {
protected Boolean doInBackground(Void... arg0) {
String data_storage_root = getApplicationContext().getFilesDir().toString();
boolean copied=false;
InputStream is= null;
OutputStream os = null;
File h = new File(data_storage_root+"/file.format");
if (h.exists()) h.delete();
try {
is = getApplicationContext().getResources().getAssets().open("keypad/file.format");
os = new FileOutputStream(data_storage_root+"/file.format");
if (copy(is, os)) copied = true;
is.close();
os.flush();
os.close();
os = null;
Log.d(TAG, "success copying certificate generic");
} catch (IOException e) {
Log.w(TAG, "failed copying certificate generic");
}
return copied;
}
protected void onPostExecute(Boolean result){
doneBackground(result);
}
private boolean copy(InputStream in, OutputStream out){
try {
byte[] buffer = new byte[1024];
int read;
while (( read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
return true;
} catch (IOException e) {
Log.w(TAG, "problems copying");
return false;
}
}
}
}
Click to expand...
Click to collapse
I'm frustrated... You change the name of my functions an now I don't understand anything.
public void reparar is the name of the button function, in your code the functions starts "onCreate".
I prefer my dirty but understable (for me) code
Now I have only one problem, the app works, but it take a long time to reemplace the file in system directory. In other words, I pulse the button, close the application, an in one minute the file is reemplaced. How can I fix that an take this time in a progress dialog?
Sorry for my bad english! I'm spanish
This is my code, is dirty but I think you understand it. Add functions and edit, but no the name of the functions, Please!
Code:
public class MainActivity extends Activity {
ProgressDialog progress;
private static final String TAG = "Copy Example";
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
if (RootTools.isRootAvailable()) {
} else {
finish();
}
}
public void reparar(View view) throws IOException, TimeoutException, RootDeniedException {
progress = ProgressDialog.show(this, "dialog title",
"dialog message", true);
copyfile1();
copyfile2();
copyfile1tosystem();
copyfile2tosystem();
End();
}
public void copyfile1() {
String data_storage_root = getApplicationContext().getFilesDir().toString();
InputStream is= null;
OutputStream os = null;
File h = new File(data_storage_root+"/sec_key.kl");
if (h.exists()) h.delete();
try {
is = getApplicationContext().getResources().getAssets().open("keypad/sec_key.kl");
os = new FileOutputStream(data_storage_root+"/sec_key.kl");
if (copy(is, os))
is.close();
os.flush();
os.close();
os = null;
Log.d(TAG, "success");
} catch (IOException e) {
Log.w(TAG, "failed copying certificate generic");
}
return;
}
public void copyfile2() {
String data_storage_root = getApplicationContext().getFilesDir().toString();
InputStream is= null;
OutputStream os = null;
File h = new File(data_storage_root+"/sec_keypad.kl");
if (h.exists()) h.delete();
try {
is = getApplicationContext().getResources().getAssets().open("keypad/sec_keypad.kl");
os = new FileOutputStream(data_storage_root+"/sec_keypad.kl");
if (copy(is, os))
is.close();
os.flush();
os.close();
os = null;
} catch (IOException e) {
finish();
}
return;
}
public void copyfile1tosystem() throws IOException, TimeoutException, RootDeniedException {
CommandCapture command = new CommandCapture(0, "su", "mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system", "cp /data/data/com.fixer.gminipop/files/sec_key.kl /system/usr/keylayout/sec_key.kl", "mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system");
RootTools.getShell(true).add(command);
}
public void copyfile2tosystem() throws IOException, TimeoutException, RootDeniedException {
CommandCapture command = new CommandCapture(0, "su", "mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system", "cp /data/data/com.fixer.gminipop/files/sec_keypad.kl /system/usr/keylayout/sec_keypad.kl", "mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system");
RootTools.getShell(true).add(command);
}
public void End() {
progress.dismiss();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Es necesario reiniciar")
.setTitle("Instalacion satisfactoria!")
.setCancelable(false)
.setNegativeButton("Hacerlo mas tarde",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
})
.setPositiveButton("Reiniciar",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// metodo que se debe implementar
try {
ProcessBuilder pb = new ProcessBuilder(new String[] { "su", "-c", "/system/bin/reboot" });
java.lang.Process process = pb.start();
process.waitFor();
} catch (IOException e) {
}
// TODO Auto-generated method stub
catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
AlertDialog alert = builder.create();
alert.show();
}
private boolean copy(InputStream in, OutputStream out){
try {
byte[] buffer = new byte[1024];
int read;
while (( read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
return true;
} catch (IOException e) {
Log.w(TAG, "fallo al copiar");
finish();
return false;
}
}
}

Hi, I haven't had time to produce more code for you.
Just some remarks looking at your code:
1 you duplicate a lot of code
2 your application does everything on the main thread
3 you do a lot of unnescasairy code on the terminal
1)
copyfle 1 and 2 are almost the same, why not use it only once? copyFile(String filename){ ... } for example?
2)
extracting the files form the apk to /data schould be done at the loading of the app, in the background and preferably only once (now it tis done everytime the app starts), then copy it to system at a press of the button. In my example there is a function doneBackground(boolean succes), from there you could set the visiblity of your button to View.VISIBLE, allowing the user to copy the file to /system, now everything is done after the button press.
3)
Code:
"su"
"mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system"
"cp /data/data/com.fixer.gminipop/files/sec_key.kl /system/usr/keylayout/sec_key.kl"
"mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system")
"su"
"mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system"
"cp /data/data/com.fixer.gminipop/files/sec_keypad.kl /system/usr/keylayout/sec_keypad.kl"
"mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system");
this calls 2 times su and it mounts 2 times the system as rw and back to ro, can hugely be optimized
Edit, just read Nikwens reply in your other thread, you don't have to call su at all according to him. However,as I said, I am not a user of Roottools so can't confirm that.

Zatta said:
Hi, I haven't had time to produce more code for you.
Just some remarks looking at your code:
1 you duplicate a lot of code
2 your application does everything on the main thread
3 you do a lot of unnescasairy code on the terminal
1)
copyfle 1 and 2 are almost the same, why not use it only once? copyFile(String filename){ ... } for example?
2)
extracting the files form the apk to /data schould be done at the loading of the app, in the background and preferably only once (now it tis done everytime the app starts), then copy it to system at a press of the button. In my example there is a function doneBackground(boolean succes), from there you could set the visiblity of your button to View.VISIBLE, allowing the user to copy the file to /system, now everything is done after the button press.
3)
Code:
"su"
"mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system"
"cp /data/data/com.fixer.gminipop/files/sec_key.kl /system/usr/keylayout/sec_key.kl"
"mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system")
"su"
"mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system"
"cp /data/data/com.fixer.gminipop/files/sec_keypad.kl /system/usr/keylayout/sec_keypad.kl"
"mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system");
this calls 2 times su and it mounts 2 times the system as rw and back to ro, can hugely be optimized
Edit, just read Nikwens reply in your other thread, you don't have to call su at all according to him. However,as I said, I am not a user of Roottools so can't confirm that.
Click to expand...
Click to collapse
Thank's! I'm going to fix that, Optimice code and clear it. But the problem persist, the copy of the file to system take a long time, and the process to do it is after I close the app, This is my only important error..
Enviado desde mi GT-S5570I usando Tapatalk 2

Ok! I fix all and I'm going to upload it to Google Play, thanks for all your help in this project!
Now I only need your help to put Ads (If my app have lots of downloads) Can u give me a link of a Tutorial?
Enviado desde mi GT-S5570I usando Tapatalk 2

DannyGM16 said:
Ok! I fix all and I'm going to upload it to Google Play, thanks for all your help in this project!
Now I only need your help to put Ads (If my app have lots of downloads) Can u give me a link of a Tutorial?
Enviado desde mi GT-S5570I usando Tapatalk 2
Click to expand...
Click to collapse
No, I hate ads
Post your play store link here, I'm curious what you made.
Taptalked u see .. əəs n pəʞlɐʇdɐʇ

Zatta said:
No, I hate ads
Post your play store link here, I'm curious what you made.
Taptalked u see .. əəs n pəʞlɐʇdɐʇ
Click to expand...
Click to collapse
You hate ads and you are a developer? ;D Is the most easy form to win money for your work. I develop apps for fun but I want obtain some money for it You can download my app, but If you don't have a galaxy mini S5570I is useless, only you can watch it...
Enviado desde mi GT-S5570I usando Tapatalk 2

This is my application: https://play.google.com/store/apps/details?id=com.fixer.gminipop
Whatch it in Google Play
Enviado desde mi GT-S5570I usando Tapatalk 2

DannyGM16 said:
This is my application: https://play.google.com/store/apps/details?id=com.fixer.gminipop
Whatch it in Google Play
Enviado desde mi GT-S5570I usando Tapatalk 2
Click to expand...
Click to collapse
You should get someone to translate all that Spanish to English. I took the effort to translate it for myself (with Google translator) but I'm sure the advantage potential user won't.
Edit, non the less, congratulations with your play store registration!!
Taptalked u see .. əəs n pəʞlɐʇdɐʇ

Zatta said:
You should get someone to translate all that Spanish to English. I took the effort to translate it for myself (with Google translator) but I'm sure the advantage potential user won't.
Edit, non the less, congratulations with your play store registration!!
Taptalked u see .. əəs n pəʞlɐʇdɐʇ
Click to expand...
Click to collapse
Thank's for show me that error, but I'm going to update it!! Only I have one problem, in one of my update I want to copy a DIRECTORY of assets to /data/data. I watch for the code in a lot o pages, but I don't find it, help me only one more time Pls!
Enviado desde mi GT-S5570I usando Tapatalk 2

Check this for finding translators: http://forum.xda-developers.com/showthread.php?t=2069390

nikwen said:
Check this for finding translators: http://forum.xda-developers.com/showthread.php?t=2069390
Click to expand...
Click to collapse
Nikewn, I know spanish and english, I can translate my app But Thank's. Only I want to resolve my last problem.

DannyGM16 said:
Nikewn, I know spanish and english, I can translate my app But Thank's. Only I want to resolve my last problem.
Click to expand...
Click to collapse
I see that you can write English.
However, you might want to have it translated to other languages, too.
---------- Post added at 03:42 PM ---------- Previous post was at 03:39 PM ----------
DannyGM16 said:
Thank's for show me that error, but I'm going to update it!! Only I have one problem, in one of my update I want to copy a DIRECTORY of assets to /data/data. I watch for the code in a lot o pages, but I don't find it, help me only one more time Pls!
Enviado desde mi GT-S5570I usando Tapatalk 2
Click to expand...
Click to collapse
Create the directory using the mkdir() method in the java.io.File class. And copy every file to the directory in /data/data. You need to copy the files one by one.

Related

[Q] How to read directories?

Hey guys, this is the first time im trying my hand at android development, im still fairly new to development altogether.
Basically what I'm trying to do at the moment is read a list of folder-names in a particular directory, then write those to another file.
The file I'm writing to is at /data/data/com.rone/files/app_list
I'm trying to read from /data/data/
The app has been given su privileges as well. My issue is that I can't seem to read from any folder other than / (root)
Code:
private OnClickListener sort_listener = new OnClickListener() {
@Override
public void onClick(View v) {
String datafolders ="";
File dir = new File("/data/data/");
if(dir.isDirectory() && dir.canRead()){
Log.v("DEBUG", dir.getName() + " is the searching directory!");
for(int i = 0; i < dir.list().length; i++) {
datafolders += dir.list()[i] + " \n";
}
}
else {
Log.v("ERROR", "directory does not exist or can not be accessed!");
}
writeFile(datafolders, "app_list");
}
};
public void writeFile(String input, String filename) {
try {
FileOutputStream fos = openFileOutput(filename, Context.MODE_PRIVATE);
fos.write(input.getBytes());
fos.close();
return;
} catch (FileNotFoundException e) {
Log.v("ERROR", e.getMessage());
} catch (IOException e) {
Log.v("ERROR", e.getMessage());
}
}
public String readFile(String filename) {
try {
FileInputStream fis = openFileInput(filename);
String temp = "";
int ch;
while ((ch = fis.read()) > -1) {
temp += (char) ch;
}
fis.close();
return temp;
} catch (FileNotFoundException e) {
Log.v("ERROR", e.getMessage());
return "Exception" + e;
} catch (IOException e) {
Log.v("ERROR", e.getMessage());
return "Exception" + e;
}
}
It only writes to the file when I use:
Code:
File dir = new File("./");
Also, my app is specifically written for the SGS and I'm using Eclipse. Any way to get and import a custom SGS skin with the Menu and Back button functionality?
No replies? No one knows how to read the directories? Is there a limitation built-in that stops from reading directories? Even with su permissions?

[Q] help on eclipse app

Hi guys,
First of all i`m completly noob on this so don`t be much hard with me
ok. i`m trying to develop a simple app just to run 4 simple command to install another app but for now the only thing that i can get to work was asking for su permissions...
can someone help me with this?
Thks a lot
HTML:
try {
runtime.exec("su -c busybox mount -o rw,remount /system");
runtime.exec("cp /sdcard/gscript/xrecovery.sh /data/local/tmp/xrecovery.sh");
runtime.exec("chmod 777 /data/local/tmp/xrecovery.sh");
runtime.exec("/data/local/tmp/xrecovery.sh");
runtime.exec("reboot");
}
catch (IOException e) {
e.printStackTrace();
do not think anyone has the knowledge to help me: .- (
My intention is to create a simple program that installs a file which is in sh sdcard,
"sdcard / gscript / xrecovery.sh"
until now could only be granted access to the root but do not know where and what command should I put to run that sh file...
is that no one can / want help?
thks
HTML:
import java.io.DataOutputStream;
import java.io.IOException;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class xRecovery extends Activity {
Button app_name;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
app_name = (Button)findViewById(R.id.TextView01);
xRecovery.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {;
}
});
setContentView(R.layout.main);
try {
Runtime.getRuntime().exec("/sdcard/gscript/xrecovery.sh");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
{
os.writeBytes("mount -o rw,remount -t yaffs2 /dev/block/mtdblock03 /system\n" +
"exit \n");
os.flush();
process.waitFor();
}
Runtime.getRuntime().exec("/sdcard/gscript/xrecovery.sh");
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
protected String[] getPackageResourcePath(String string) {
// TODO Auto-generated method stub
return null;
}
private static void setOnClickListener(OnClickListener onClickListener) {
// TODO Auto-generated method stub
}
}
You should be able to execute a .sh file by using:
Code:
sh xrecovery.sh
spolfliet said:
You should be able to execute a .sh file by using:
Code:
sh xrecovery.sh
Click to expand...
Click to collapse
Without sdcard path! ?
And where should i put?
Thks; )
Sent from my AOSP on Xperia (US) using XDA App
Of course you need to specify the path (it cannot guess where your script is, unless you add it to your PATH). So I guess the following should work for you:
Code:
Runtime.getRuntime().exec("sh /sdcard/gscript/xrecovery.sh");
Unfortunely i cant make this work UK sure that im putting the command Sony the wrong place. I've allready try put Sony a different pplaces but never work: (
Thks anyway; )
Sent from my AOSP on Xperia (US) using XDA App
really need help!
here is my complete code for what i want to do
HTML:
package com.rendeiro2005.xRecovery;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class xRecovery extends Activity {
Button INSTALL;
Button REMOVE;
AlertDialog.Builder builder;
AlertDialog Alert;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try
{
Process process = Runtime.getRuntime().exec("su");
DataOutputStream outputStream = new DataOutputStream(process.getOutputStream());
DataInputStream inputStream = new DataInputStream(process.getInputStream());
outputStream.writeBytes("\n");
outputStream.flush();
outputStream.writeBytes("exit\n");
outputStream.flush();
process.waitFor();
process.waitFor();
if (process.exitValue() != 255) {
toastMessage("root");
}
else {
toastMessage("not root");
}
}
catch (IOException e)
{
try {
throw new Exception(e);
} catch (Exception e1) {
e1.printStackTrace();
}
}
catch (InterruptedException e)
{
try {
throw new Exception(e);
} catch (Exception e1) {
e1.printStackTrace();
}
}
INSTALL = (Button)findViewById(R.id.Button01);
REMOVE = (Button)findViewById(R.id.Button02);
builder = new AlertDialog.Builder(this);
builder.setMessage("Do you want to install xRecovery?");
builder.setCancelable(false);
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
try {
Runtime.getRuntime().exec("sh /sdcard/gscript/xrecovery.sh");
} catch (IOException e) {
e.printStackTrace();
}
Toast.makeText(getApplicationContext(),
"Done",
Toast.LENGTH_SHORT).show();
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
Alert = builder.create();
INSTALL.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Alert.show();
}
});
REMOVE.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
}
});
}
private void toastMessage(String string) {
}
}
i haven`t donne the uninstall part.
the problem here is everything work as it should exept the "sh" doesn`t do anything.
can anyone help me with this? i`m just trying to understand how the process works
thks a lot

Help with RootTools

Hey! I need your help!
This is all my code, I use library common-io-2.2 and RootTool library.
I have two issues:
1- Error in waitForFinish();
2- processDialog don't appear.
Code:
import android.app.*;
import android.content.*;
import android.os.*;
import android.os.Process;
import android.util.*;
import android.view.*;
import android.view.View.*;
import android.widget.Button;
import android.widget.Toast;
import java.io.*;
import com.stericson.RootTools.RootTools;
import com.stericson.RootTools.execution.CommandCapture;
import java.util.concurrent.*;
import com.stericson.RootTools.exceptions.*;
import org.apache.commons.io.*;
public class MainActivity extends Activity {
{
}
ProgressDialog progressDialog = null;
/** Called when the activity is first created. */
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
if (RootTools.isAccessGiven()) {
} else {
makeToast("Se necesitan permisos de Superusuario!");
finish();
}
}
public void reparar(View view) throws IOException, TimeoutException, RootDeniedException, InterruptedException {
CopyFromAssets();
CopyFromAssetstosystem();
End();
}
public void CopyFromAssets() {
progressDialog = ProgressDialog.show(MainActivity.this, "Instalando parche", "Por favor, espere...", true);
String data_storage_root = getFilesDir().toString();
InputStream is= null;
OutputStream os = null;
File h = new File(data_storage_root+"/caca.txt");
File p = new File(data_storage_root+"/caca2.txt");
if (h.exists()) h.setWritable(true, true);
if (p.exists()) h.setWritable(true, true);
try {
is = getResources().getAssets().open("keypad/caca.txt");
is = getResources().getAssets().open("keypad/caca2.txt");
os = new FileOutputStream(data_storage_root+"/sec_key.kl");
os = new FileOutputStream(data_storage_root+"/sec_keypad.kl");
IOUtils.copy(is, os);
is.close();
os.flush();
os.close();
os = null;
} catch (IOException e) {
makeToast("Fallo al copiar");
finish();
}
h.setExecutable(false, true);
h.setReadable(true, true);
h.setWritable(false, true);
}
public void CopyFromAssetstosystem() throws TimeoutException, IOException, RootDeniedException {
CommandCapture command = new CommandCapture(0, "su", "mount -o rw, remount -t yaffs2 /dev/block/mtdblock4 /system", "cp /data/data/com.fixer.gminipop/files/caca.txt /system", "mount -o ro, remount -t yaffs2 /dev/block/mtdblock4 /system");
RootTools.getShell(true).add(command).waitForFinish();
}
public void End() {
ClosePD();
AlertDialog();
}
public void AlertDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Es necesario reiniciar para que se apliquen los cambios. Desea hacerlo ahora?")
.setTitle("Instalacion satisfactoria!")
.setCancelable(false)
.setNegativeButton("Reiniciar mas tarde",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
})
.setPositiveButton("Reiniciar ahora",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// metodo que se debe implementar
try {
ProcessBuilder pb = new ProcessBuilder(new String[] { "su", "-c", "/system/bin/reboot" });
java.lang.Process process = pb.start();
process.waitFor();
} catch (IOException e) {
}
// TODO Auto-generated method stub
catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
AlertDialog alert = builder.create();
alert.show();
}
public void ClosePD() {
progressDialog.dismiss();
}
private static void copy(InputStream is, OutputStream os) {
// TODO Auto-generated method stub
}
public void makeToast(String msg) {
Context context = getApplicationContext();
CharSequence text = msg;
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
public void RootActions() {
}
}
Enviado desde mi GT-S5570I usando Tapatalk 2
Come on... It's easy!
Enviado desde mi GT-S5570I usando Tapatalk 2
Remove that "su" in the CommandCapture. You tell the library that you want to be root by calling getShell() with the parameter true. The parameter true tells RootTools to call su itself.
---------- Post added at 08:42 AM ---------- Previous post was at 08:40 AM ----------
DELETED
nikwen said:
Remove that "su" in the CommandCapture. You tell the library that you want to be root by calling getShell() with the parameter true. The parameter true tells RootTools to call su itself.
---------- Post added at 08:42 AM ---------- Previous post was at 08:40 AM ----------
DELETED
Click to expand...
Click to collapse
I don't understand you. Please, show me an example!
DannyGM16 said:
I don't understand you. Please, show me an example!
Click to expand...
Click to collapse
Change this
Code:
CommandCapture command = new CommandCapture(0, "su", "mount -o rw, remount -t yaffs2 /dev/block/mtdblock4 /system", "cp /data/data/com.fixer.gminipop/files/caca.txt /system", "mount -o ro, remount -t yaffs2 /dev/block/mtdblock4 /system");
to
Code:
CommandCapture command = new CommandCapture(0, "mount -o rw, remount -t yaffs2 /dev/block/mtdblock4 /system", "cp /data/data/com.fixer.gminipop/files/caca.txt /system", "mount -o ro, remount -t yaffs2 /dev/block/mtdblock4 /system");
nikwen said:
Change this
Code:
CommandCapture command = new CommandCapture(0, "su", "mount -o rw, remount -t yaffs2 /dev/block/mtdblock4 /system", "cp /data/data/com.fixer.gminipop/files/caca.txt /system", "mount -o ro, remount -t yaffs2 /dev/block/mtdblock4 /system");
to
Code:
CommandCapture command = new CommandCapture(0, "mount -o rw, remount -t yaffs2 /dev/block/mtdblock4 /system", "cp /data/data/com.fixer.gminipop/files/caca.txt /system", "mount -o ro, remount -t yaffs2 /dev/block/mtdblock4 /system");
Click to expand...
Click to collapse
Thank's!
But I have another problem, I'm developing an app to copy files from assets to system. The code works, but the copy from /data/data/.. to /system/... take a long time and I don't know how to put a progress dialog. But this problem is strange, becouse the copy of the file is abot a minute after I close the app. I want to make a progress dialog in this time. Can you help me?? (I'm spanish, sorry for my english errors)
Notes:
1- Please, don't modify the function names, "reparar" corresponds a button
2- I know that I have a very dirty code, but only help in my problem, don't clean it
3- I wait for you to help me
Code:
public class MainActivity extends Activity {
ProgressDialog progress;
private static final String TAG = "Copy Example";
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
if (RootTools.isRootAvailable()) {
} else {
finish();
}
}
public void reparar(View view) throws IOException, TimeoutException, RootDeniedException {
progress = ProgressDialog.show(this, "dialog title",
"dialog message", true);
copyfile1();
copyfile2();
copyfile1tosystem();
copyfile2tosystem();
End();
}
public void copyfile1() {
String data_storage_root = getApplicationContext().getFilesDir().toString();
InputStream is= null;
OutputStream os = null;
File h = new File(data_storage_root+"/file.format");
if (h.exists()) h.delete();
try {
is = getApplicationContext().getResources().getAssets().open("keypad/file.format");
os = new FileOutputStream(data_storage_root+"/file.format");
if (copy(is, os))
is.close();
os.flush();
os.close();
os = null;
Log.d(TAG, "success");
} catch (IOException e) {
Log.w(TAG, "failed copying certificate generic");
}
return;
}
public void copyfile2() {
String data_storage_root = getApplicationContext().getFilesDir().toString();
InputStream is= null;
OutputStream os = null;
File h = new File(data_storage_root+"/file2.format");
if (h.exists()) h.delete();
try {
is = getApplicationContext().getResources().getAssets().open("keypad/file2.format");
os = new FileOutputStream(data_storage_root+"/file2.format");
if (copy(is, os))
is.close();
os.flush();
os.close();
os = null;
} catch (IOException e) {
finish();
}
return;
}
public void copyfile1tosystem() throws IOException, TimeoutException, RootDeniedException {
CommandCapture command = new CommandCapture(0, "mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system", "cp /data/data/com.fixer.gminipop/files/sec_key.kl /system/usr/keylayout/file.format", "mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system");
RootTools.getShell(true).add(command);
}
public void copyfile2tosystem() throws IOException, TimeoutException, RootDeniedException {
CommandCapture command = new CommandCapture(0, "mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system", "cp /data/data/com.fixer.gminipop/files/sec_keypad.kl /system/usr/keylayout/file2.format", "mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system");
RootTools.getShell(true).add(command);
}
public void End() {
progress.dismiss();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Es necesario reiniciar")
.setTitle("Instalacion satisfactoria!")
.setCancelable(false)
.setNegativeButton("Hacerlo mas tarde",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
})
.setPositiveButton("Reiniciar",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// metodo que se debe implementar
try {
ProcessBuilder pb = new ProcessBuilder(new String[] { "su", "-c", "/system/bin/reboot" });
java.lang.Process process = pb.start();
process.waitFor();
} catch (IOException e) {
}
// TODO Auto-generated method stub
catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
AlertDialog alert = builder.create();
alert.show();
}
private boolean copy(InputStream in, OutputStream out){
try {
byte[] buffer = new byte[1024];
int read;
while (( read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
return true;
} catch (IOException e) {
Log.w(TAG, "fallo al copiar");
finish();
return false;
}
}
}
I've answered your last question in your other thread and I would prefer not to use this thread anymore. If RootTools works without calling "su" implicitly, even better as su is expensive call!
Thread closed.

[Q] Copy Image from Gallery Share (Send To) menu

Moderators... It says I am breaking the rules by asking a question and to ask in the Q&A... But the title of this is "Coding Discussion, Q&A, and Educational Resources" I am not breaking the rules intentionally, I just don't know where else to put this. This is a Coding Question, not a General Question that I would think would get buried and or lost in the General Q&A forum. Please move if you feel I am incorrect.
Hello All, I was hoping someone could help me.
I am trying to create an app that will hide pictures. I want to be able to Pick my App from the Share (Send To) menu from the Users Gallery and have it copy the file to a Directory I have created on my SDCard and then ultimately delete the file from the current location.
Here is what I have so far, but when I pick my app from the Share menu, it crashes the Gallery app. So... I can't even see any errors in my LogCat to even try and troubleshoot my issue.
Can someone point me to a working example of how to do this (I have searched the internet until I am blue in the face) or... I hate to say it... Fix my Code?
Any Help would be appreciated... Thanks!!
Code:
package com.company.privitegallery;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
public class SendToDo extends Activity {
File sdCardLoc = Environment.getExternalStorageDirectory();
File intImagesDir = new File(sdCardLoc,"/DCIM/privgal/.nomedia");
private static final int CAMERA_REQUEST = 1888;
private String selectedImagePath;
String fileName = "capturedImage.jpg";
private static Uri mCapturedImageURI;
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
// Get intent, action and MIME type
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
if ("text/plain".equals(type)) {
handleSendText(intent); // Handle text being sent
} else if (type.startsWith("image/")) {
handleSendImage(intent); // Handle single image being sent
try {
GetPhotoPath();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
if (type.startsWith("image/")) {
handleSendMultipleImages(intent); // Handle multiple images being sent
}
} else {
// Handle other intents, such as being started from the home screen
}
//...
}
void handleSendText(Intent intent) {
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText != null) {
// Update UI to reflect text being shared
}
}
void handleSendImage(Intent intent) {
Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (imageUri != null) {
// Update UI to reflect image being shared
}
}
void handleSendMultipleImages(Intent intent) {
ArrayList<Uri> imageUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
if (imageUris != null) {
// Update UI to reflect multiple images being shared
}
}
public void GetPhotoPath() throws IOException {
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, fileName);
mCapturedImageURI = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
copy(fileName, intImagesDir);
}
[user=439709]@override[/user]
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == CAMERA_REQUEST) {
selectedImagePath = getPath(mCapturedImageURI);
Log.v("selectedImagePath: ", ""+selectedImagePath);
//Save the path to pass between activities
try {
copy(selectedImagePath, intImagesDir);
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
public void copy(String scr, File dst) throws IOException {
InputStream in = new FileInputStream(scr);
OutputStream out = new FileOutputStream(dst);
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
}
private void deleteLatest() {
// TODO Auto-generated method stub
File f = new File(Environment.getExternalStorageDirectory() + "/DCIM/Camera" );
//Log.i("Log", "file name in delete folder : "+f.toString());
File [] files = f.listFiles();
//Log.i("Log", "List of files is: " +files.toString());
Arrays.sort( files, new Comparator<Object>()
{
public int compare(Object o1, Object o2) {
if (((File)o1).lastModified() > ((File)o2).lastModified()) {
// Log.i("Log", "Going -1");
return -1;
} else if (((File)o1).lastModified() < ((File)o2).lastModified()) {
// Log.i("Log", "Going +1");
return 1;
} else {
// Log.i("Log", "Going 0");
return 0;
}
}
});
//Log.i("Log", "Count of the FILES AFTER DELETING ::"+files[0].length());
files[0].delete();
}
}
What's the gallery log output?
Btw, you're not breaking the rules. This is the right forum for Java Q&A.
nikwen said:
What's the gallery log output?
Click to expand...
Click to collapse
How would I get the Logs for the Gallery? I am using and HTC ONE and it's the standard Gallery. Nothing shows up in LogCat so I'm stuck
nikwen said:
Btw, you're not breaking the rules. This is the right forum for Java Q&A.
Click to expand...
Click to collapse
Great, Thanks!!
StEVO_M said:
How would I get the Logs for the Gallery? I am using and HTC ONE and it's the standard Gallery. Nothing shows up in LogCat so I'm stuck
Great, Thanks!!
Click to expand...
Click to collapse
Do you view the logs on your computer?
There should be an error message in the logs.
nikwen said:
Do you view the logs on your computer?
There should be an error message in the logs.
Click to expand...
Click to collapse
Which Logs?? As I said before. LogCat does not give any errors.

[Q]Problem using RootTools library

i am trying to list files of root folders using roottools libary .here is the code
Code:
public ArrayList<File> listFiles(final Context c,final String path) {
final ArrayList<File> a=new ArrayList<File>();
Command command = new Command(0, "ls "+path)
{
@Override
public void commandOutput(int i, String s) {
File f=new File(path+"/"+s);
a.add(f);}
@Override
public void commandTerminated(int i, String s) {
}
@Override
public void commandCompleted(int i, int i2) {
//want to arraylist return from here
}
};
try {
RootTools.getShell(true).add(command);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
now problem is that if i return arraylist<file> from the end of method,its size is zero,to solve it i must return the arraylist from commandCompleted
method.but i am not able to accomplish that.So please solve my problem
Maybee arraylist as static outside your function? So on top of source file? Not sure but maybee

Categories

Resources