Hello, i just need to change a String i get from an Intent to a File so i can use listFiles().
The linecode that messes up is:
root = (File)extras.getString("newFilePath");
root is the File variable,
newFilePath is the extra i put in the Intent.
I know it could be a very easy solution but i'm out of ideas right now and i could use your help if you can help me. :cyclops:
Thanx in advance!!!
Hi!
You cannot cast file to string
Try this:
File root = new File(extras.get string("newFilePath"));
xcesco89 said:
Hi!
You cannot cast file to string
Try this:
File root = new File(extras.get string("newFilePath"));
Click to expand...
Click to collapse
This.
Just to add: when declaring a file, the syntax is:
File foo = new File(<string>);
The string can be a regular (typed) string, or can be constructed as long as the result is a string.
e.g.
File foo = new File("C:\\MyDocs\\FileName.TXT");
Edwin Bos said:
This.
Just to add: when declaring a file, the syntax is:
File foo = new File(<string>);
The string can be a regular (typed) string, or can be constructed as long as the result is a string.
e.g.
File foo = new File("C:\\MyDocs\\FileName.TXT");
Click to expand...
Click to collapse
Thanx very much both of u guys. Finally figured out and as i said it was so simple, but i'm not so experienced with Android or Java for that matter...
Now app works correctly
Related
I'm trying to launch TCPMP from a small CF.NET 2.0 application, but I can't get System.Diagnostics.Process.Start to do anything for me. Here's a sample:
Code:
const string TCPMPLocation = @"\Progam Files\TCPMP\player.exe";
System.Diagnostics.ProcessStartInfo TCPMPInfo = new System.Diagnostics.ProcessStartInfo();
TCPMPInfo.FileName = TCPMPLocation;
TCPMPInfo.UseShellExecute = false;
TCPMPInfo.Arguments = null;
TCPMPInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(TCPMPLocation);
System.Diagnostics.Process.Start(TCPMPInfo);
But everytime I try to run the code in the emulator, I get a Win32Exception: "The system cannot find the file specified."
I installed TCPMP on the emulator to the default location, so player.exe does appear to be in \Program Files\TCPMP. Am I specifying the path incorrectly or something?
I am not sure why is it not working since i don't have TCPMP installed. but try to run it from the explorer on the emulator and check if it runs or exists or not.
I tried ur code on another application (\windows\clock.exe) and it worked fine..
Well, it resolved itself somehow. I decided to go ahead and move the location of TCPMP to my config file instead of a constant while I waited on a reply. And of course it's working fine now that I put it there.
Thanks for looking at it.
Can you please tell me how did you resolve the issue.
did you place the path in config file?
please let me know because even i am facing the same issue
Thanks in advace!!
Dromio said:
I'm trying to launch TCPMP from a small CF.NET 2.0 application, but I can't get System.Diagnostics.Process.Start to do anything for me. Here's a sample:
Code:
const string TCPMPLocation = @"\Progam Files\TCPMP\player.exe";
System.Diagnostics.ProcessStartInfo TCPMPInfo = new System.Diagnostics.ProcessStartInfo();
TCPMPInfo.FileName = TCPMPLocation;
TCPMPInfo.UseShellExecute = false;
TCPMPInfo.Arguments = null;
TCPMPInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(TCPMPLocation);
System.Diagnostics.Process.Start(TCPMPInfo);
But everytime I try to run the code in the emulator, I get a Win32Exception: "The system cannot find the file specified."
I installed TCPMP on the emulator to the default location, so player.exe does appear to be in \Program Files\TCPMP. Am I specifying the path incorrectly or something?
Click to expand...
Click to collapse
mmmmm... Isn't it ProgRam files instead of Progam? ...
That could have been it. I posted the original message months ago. And as I mentioned, it was resolved when I started using a setting to specify the path rather than hard-coding it. It's very likely that it was that typo.
Hey guys
I declared an image in the layout.xml file and now I want it do disappear with a command from the java file.
Any ideas how I could do this?
thx and greez visosilver
You need to give the ImageView an id and then simply reference it from inside the code with something like this:
Code:
ImageView iv = (ImageView) findViewById(id); // id is the id of the image you want to remove
iv.setVisibility(8);
thx a lot dude, thats working!
greez visosilver
I was task to allocate only 1GB of space to store my videos in a particular file directory where it is going to auto-delete the oldest video file in that directory once its about to reach/hit 1GB?
And i eventually found these code but i was left with a problem on how to incorporate these example 1/2 codes into my current existing mainActivity.java file because of the differences in names like "dirlist,tempFile" compared with other examples 1/2 given to perform the task of size checking and deleting.
Sorry i'm kinna new in android/java therefore i don't really know what "fields" to change to suit my current coding needs? Can someone help on how am i going to complie these set of codes into a single set of code which perform the above mention functions??
My Current existing mainActivity.java
Code:
File dirlist = new File(Environment.getExternalStorageDirectory() + "/VideoList");
if(!(dirlist.exists()))
dirlist.mkdir();
File TempFile = new File(Environment.getExternalStorageDirectory()
+ "/VideoList", dateFormat.format(date) + fileFormat);
mediaRecorder.setOutputFile(TempFile.getPath());
(Example 1) code for summing up directory file size in a given folder..
Code:
private static long dirSize(File dir) {
long result = 0;
Stack<File> dirlist= new Stack<File>();
dirlist.clear();
dirlist.push(dir);
while(!dirlist.isEmpty())
{
File dirCurrent = dirlist.pop();
File[] fileList = dirCurrent.listFiles();
for (int i = 0; i < fileList.length; i++) {
if(fileList[i].isDirectory())
dirlist.push(fileList[i]);
else
result += fileList[i].length();
}
}
return result;
}
(Example 2) set of code for getting all the files in an array, and sorts them depending on their modified/created date. Then the first file in your array is your oldest file and delete it.
Code:
// no idea what are the parameters i should enter
// here for my case in mainActivity??
File directory = new File((**String for absolute path to directory**);
File[] files = directory.listFiles();
Arrays.sort(files, new Comparator<File>() {
@Override
public int compare(File f1, File f2)
{
return Long.valueOf(f1.lastModified()).compareTo(f2.lastModified());
}});
file[0].delete();
imso said:
And i eventually found these code but i was left with a problem on how to incorporate these example 1/2 codes into my current existing mainActivity.java file because of the differences in names like "dirlist,tempFile" compared with other examples 1/2 given to perform the task of size checking and deleting.
Click to expand...
Click to collapse
if its a matter of variable names and discrepancies from the sample code to your code then i would recommend an ide with really good refactoring built in. it will let you in a couple clicks rename all the new vars to vars that are already in your code. i use IntelliJ (i know alot of people use Eclipse, but i cant stand it. IntelliJ is really way better to code on)
beyond that id have to sit down and look at what this code is doing to try and help. ill give it a look over but its hard to know whats going on when you havent written the code.
Good day.
Wrote an application that uses the class SharedPreferentses to store and retrieve settings. On the emulator works fine, but the device is not present.
After installing the application does not create a folder shared_prefs where it should be stored configuration file.
Please tell me why not create a configuration file?
Can you show us the piece of code where you instantiate sharedPrefs and the piece where you push values?
I think this will help to find the solution
xcesco89 said:
Can you show us the piece of code where you instantiate sharedPrefs and the piece where you push values?
I think this will help to find the solution
Click to expand...
Click to collapse
Code:
public String loadProperty(String nameProp) {
SharedPreferences sPref = view.getSharedPreferences("Properties", Context.MODE_PRIVATE);
return sPref.getString(nameProp, "");
}
public void saveProperty(String nameProp,String valueProp){
SharedPreferences sPref = view.getSharedPreferences("Properties", Context.MODE_PRIVATE);
Editor editor = sPref.edit();
editor.putString(nameProp, valueProp);
editor.commit();
}
Hmmm...
Have you already tried to instantiate sPrefs inside onCreate instead of instantiate it every time you have to read a value?
Basically there are no errors here.
You can eventually call:
SharedPreferences.Editor editor = sPrefs.edit();
I think the problem is in the editor because shared preferences file will be created/modified when you commit changes and "Editor" could be a bad import (I don't think, but let's exclude obvious things first)
You can also try to use default shared preferences and see what happens :
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
xcesco89 said:
Hmmm...
You can also try to use default shared preferences and see what happens :
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
Click to expand...
Click to collapse
I will try that , thanks
xcesco89 said:
Hmmm...
Have you already tried to instantiate sPrefs inside onCreate instead of instantiate it every time you have to read a value?
Basically there are no errors here.
You can eventually call:
SharedPreferences.Editor editor = sPrefs.edit();
I think the problem is in the editor because shared preferences file will be created/modified when you commit changes and "Editor" could be a bad import (I don't think, but let's exclude obvious things first)
You can also try to use default shared preferences and see what happens :
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
Click to expand...
Click to collapse
No that is not a problem, you can instantiate shared prefs as often and where you like. Only thing is that this may be bad for your performance but that is a diffferent question.
Another little thing: you should use editor.apply() instead of editor.commit(), as apply looks for the next best possibility to write the changes to the file instead of immediately doing this. But this also just helps performance, it isnt crucial
---------------------------------
Phone : Nexus 4
OS :
- KitKat 4.4.4 stock
- Xposed: 58(app_process); 54(bridge)
- SU: SuperSU
- no custom recovery
---------------------------------
4d 61 73 72 65 70 75 73 20 66 74 77
Gesendet von Tapatalk
ive created a clean implementation rpc client that calls remote procedures to the FCRouter service. its more of a proof of concept. it doesnt use any part of RPCComponent, just straight up low level rpc. right now it only has 2 methods exposed, copyfile and createprocess. i will add more later. copyfile AFAIK isnt in RPCComponent. i could be wrong though, but it allows file copying anywhere on the system, even from hidden folders. for example, C:\dpp\microsoft\microsoft.pvk (oops). watch out though, you could hard brick your device messing with the wrong files.
i have a similar library for lumia that allows full file and reg access,but my screen on my lumia is broken, and the code is messy and has alot of hard coded memory addresses,so it wont run on any other device. when i get my replacement screen, ill fix it up and make it available (hello caps unlock).
heres the lib and the src code for anyone curious and wants to play around with it. have fun.
How to use the library
-----------------------
add <Capability Name="ID_CAP_INTEROPSERVICES"/> to WMAppManifest.xml
add a reference to RPClib.winmd
add "using RPClib" or "using namespace RPClib" declaration
c# silverlight code example
-------------------------
//instantiate the library
RPClib.ativ arpc = new RPClib.ativ();
//initialize and bind the RPC connection
arpc.RPC_Init();
//CopyFile
String src = "C:\\Data\\Users\\Public\\Pictures\\mypic.jpg";
String dst = "C:\\mypic.jpg";
UInt32 flag = 0;
arpc.RPC_CopyFileEx(src, dst, flag);
flag is a flag that determines if the copyfile operation will overwrite a file if it already exists.
1 = FAIL and do not overwrite if file exists.
0 = overwrite if file exists.
please test the flag option just in case.
//CreateProcess
String cmdline = "C:\\windows\\system32\\someinterestingfile.exe /somecommandlineoption";
arpc.RPC_CreateProcessA(cmdline);
first application using this lib + source code :
It works for file copy correctly but I weren't able to use for running process maybe I don't know how to use it
You did a amazing job.
No one to know, How to write such RPC stuff. SO Why all are uses OEM stuff ? But, You did It !!!
Thanks again @vcfan