Hai... I developing a root access app using RootTools library .... When I copy file using CAT command ... it is not working if the file path has space or any special character... please help me to escape space and special characters or tell any other better solution....
Thanks in Advance..
Maybee something like this:
private static final String UNIX_ESCAPE_EXPRESSION = "(\\(|\\)|\\[|\\]|\\s|\'|\"|`|\\{|\\}|&|\\\\|\\?)";
/**
* Adds escaping. Used for file paths.
*
* @param input Input command line param
* @return input string with escaped characters
*/
public static String getCommandLineString(String input) {
return input.replaceAll(UNIX_ESCAPE_EXPRESSION, "\\\\$1");
}
Gesendet von meinem K00C mit Tapatalk
tschmid said:
Maybee something like this:
private static final String UNIX_ESCAPE_EXPRESSION = "(\\(|\\)|\\[|\\]|\\s|\'|\"|`|\\{|\\}|&|\\\\|\\?)";
/**
* Adds escaping. Used for file paths.
*
* @param input Input command line param
* @return input string with escaped characters
*/
public static String getCommandLineString(String input) {
return input.replaceAll(UNIX_ESCAPE_EXPRESSION, "\\\\$1");
}
Gesendet von meinem K00C mit Tapatalk
Click to expand...
Click to collapse
Thanks for the help bro....but still its not working... I got another regex to escape all the special characters and it works... will you please add space escape to the below regex...
Code:
replaceAll("(?=[]\\[+&|!(){}^\"~*?:\\\\-])", "\\\\");
Fixed
I fixed it.... here is the complete code which escape space and all the special characters..
Code:
string.replaceAll("(?=[]\\[+&|!(){}^\\s\'\";~*?:\\\\-])", "\\\\");
Related
im trying to write a Serializable Object to the data folder of my app. I was using this code to specify the path to the file and write the Serializable Object
Code:
/**
* writeMissedCalls()
*
* @param context - the Context of the application
* @return if the missedCalls were written to file successfully
*/
public static boolean writeMissedCalls(Context context) {
String filename = context.getApplicationInfo().dataDir + "/" + MCWUtils.MCW_DATA_FILE;
FileOutputStream fos;
ObjectOutputStream out;
try {
fos = context.openFileOutput(filename, Context.MODE_PRIVATE);
out = new ObjectOutputStream(fos);
out.writeObject(MissedCallWidget.missedCalls);
out.close(); }
catch (FileNotFoundException e) { return false; }
catch (IOException e) { return false; }
return true;
}
when i try to write this Object in the onDisabled() of my AppWidgetProvider class i get an error of this sort
java.lang.RuntimeException: Unable to start receiver com.tsb.fistfulofneurons.missedcallwidget.MissedCallWidget: java.lang.IllegalArgumentException: File /data/data/com.tsb.fistfulofneurons.missedcallwidget/missed_calls.dat contains a path separator
do i not need to specify the path to my apps data folder? will the openFileOutput() specify the path to the data for me?
so instead of passing the path "/data/data/com.tsb.fistfulofneurons.missedcallwidget/missed_calls.dat" just pass "missed_calls.dat"?
thanks!
I've not tried to open a file in this manner, but I would guess that it defaults to the apps data directory. Why not give it a try and see?
Gene Poole said:
I've not tried to open a file in this manner, but I would guess that it defaults to the apps data directory. Why not give it a try and see?
Click to expand...
Click to collapse
yea it appears to default to the /data/data folder for your package. the documentation appears to be lacking. thanks
Hi!
I am loading a text to TextView from a file on a webpage with my Android app but the problem is that the text is full of ASCII characters, so when the text is loaded to the TextView, I can't see any of these ASCII characters or it shows me a "?" within a black square.
My question is, how can I convert an ASCII character to string?
Thanks for helping.
adamhala007 said:
Hi!
I am loading a text to TextView from a file on a webpage with my Android app but the problem is that the text is full of ASCII characters, so when the text is loaded to the TextView, I can't see any of these ASCII characters or it shows me a "?" within a black square.
My question is, how can I convert an ASCII character to string?
Thanks for helping.
Click to expand...
Click to collapse
Code:
char c = 'e';
String s = String.valueOf(c);
Are you sure that there's no other problem with your code? It doesn't sound like a conversion error.
nikwen said:
Code:
char c = 'e';
String s = String.valueOf(c);
Are you sure that there's no other problem with your code? It doesn't sound like a conversion error.
Click to expand...
Click to collapse
I don't know, but here is my code:
Code:
TextView textMsg;
final String textSource = "PATH/TO/MY/.CRL/FILE";
BufferedReader reader;
URL textUrl;
try {
textUrl = new URL(textSource);
BufferedReader bufferReader = new BufferedReader(
new InputStreamReader(textUrl.openStream()));
String StringBuffer;
String stringText = "";
while ((StringBuffer = bufferReader.readLine()) != null) {
stringText += StringBuffer;
}
bufferReader.close();
textMsg.setText(stringText);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
textMsg.setText(e.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
textMsg.setText(e.toString());
}
I have forgotten to mention that my file where I load the text from has .crl extension. I have tried the code you posted, but the problem still remains. So it shows me still the "?" within the black squares.
adamhala007 said:
I don't know, but here is my code:
Code:
TextView textMsg;
final String textSource = "PATH/TO/MY/.CRL/FILE";
BufferedReader reader;
URL textUrl;
try {
textUrl = new URL(textSource);
BufferedReader bufferReader = new BufferedReader(
new InputStreamReader(textUrl.openStream()));
String StringBuffer;
String stringText = "";
while ((StringBuffer = bufferReader.readLine()) != null) {
stringText += StringBuffer;
}
bufferReader.close();
textMsg.setText(stringText);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
textMsg.setText(e.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
textMsg.setText(e.toString());
}
I have forgotten to mention that my file where I load the text from has .crl extension. I have tried the code you posted, but the problem still remains. So it shows me still the "?" within the black squares.
Click to expand...
Click to collapse
Could you please post an example file?
Can CRL files really be read using a Buffered reader? Aren't the encrypted?
nikwen said:
Could you please post an example file?
Can CRL files really be read using a Buffered reader? Aren't the encrypted?
Click to expand...
Click to collapse
OK. I know why you cannot do it that way:
*.crl files are no text files. When you open them in a browser that supports it, you might see the entries. However, it is no plain text. (You might be able to read some parts, but it is not completely text.)
Proof:
I downloaded a CRL file on my Linux machine.
The way to get its content if it is a textfile is to use the cat command:
Code:
cat <path>
That way I am able to read parts of the file, but most characters aren't real characters. (Things like your ?s.)
So we need another way to do that.
---------- Post added at 09:34 AM ---------- Previous post was at 09:30 AM ----------
You can find classes for reading CRLs in the java.security.cert package: http://developer.android.com/reference/java/security/cert/package-summary.html
EDIT: This seems to be the best tutorial I found so far: http://www.javaworld.com/javaworld/jw-03-2001/jw-0316-howto.html
I found that tutorial with some code snippets: http://jce.iaik.tugraz.at/sic/Support/Technical-Articles/Parsing-Large-CRLs-in-Java
Another tutorial related to CRLs: http://www.nakov.com/blog/2009/12/0...rify-chain-and-verify-clr-with-bouncy-castle/
Hello everyone,
I'm trying to develop an calculator app and for this purpose I'm using the ViewPager to create 3 panels with different options.
My main layout looks like this:
========================
| |
| EditText |
| |
========================
| |
| |
| ViewPager |
| |
| |
| |
========================
Every panel has its own fragment and my problem is that i can't edit or update the edit text from the fragment. I have tried creating a static method in the main activity and run it on the ui thread without any luck.
I also tried this code:
mainLayout=inflater.inflate(R.layout.activity_main, container, false);
output = (EditText) mainLayout.findViewById(R.id.outputView);
output.setText("someText");
With the same result.
Wich is the appropiate way to do this?
Thank you!
alex-p690 said:
Hello everyone,
I'm trying to develop an calculator app and for this purpose I'm using the ViewPager to create 3 panels with different options.
My main layout looks like this:
========================
| |
| EditText |
| |
========================
| |
| |
| ViewPager |
| |
| |
| |
========================
Every panel has its own fragment and my problem is that i can't edit or update the edit text from the fragment. I have tried creating a static method in the main activity and run it on the ui thread without any luck.
I also tried this code:
mainLayout=inflater.inflate(R.layout.activity_main, container, false);
output = (EditText) mainLayout.findViewById(R.id.outputView);
output.setText("someText");
With the same result.
Wich is the appropiate way to do this?
Thank you!
Click to expand...
Click to collapse
Just create a public method in your activity which sets the text:
Code:
public void setEditText(CharSequence text) {
EditText output = (EditText) mainLayout.findViewById(R.id.outputView);
output.setText(text);
}
Then, in your Fragment, call that method on the activity object you get from getActivity():
Code:
((YourActivity) getActivity()).setEditText("Some text");
If you aim to use your fragment across different activities, you'll need to use an interface which must be implemented by every activity.
SimplicityApks said:
Just create a public method in your activity which sets the text:
Code:
public void setEditText(CharSequence text) {
EditText output = (EditText) mainLayout.findViewById(R.id.outputView);
output.setText(text);
}
Then, in your Fragment, call that method on the activity object you get from getActivity():
Code:
((YourActivity) getActivity()).setEditText("Some text");
If you aim to use your fragment across different activities, you'll need to use an interface which must be implemented by every activity.
Click to expand...
Click to collapse
This is just awesome!! Thank you very much. I have tried something similar to this but I was getting the "cannot reference non-static method from static context".
alex-p690 said:
This is just awesome!! Thank you very much. I have tried something similar to this but I was getting the "cannot reference non-static method from static context".
Click to expand...
Click to collapse
Change the setEditText to a static method then
From:
public void setEditText(CharSequence text) {
to:
public static void setEditText(CharSequence text) {
Edit: Also the method does not need to be public - you are providing much more access to that method than is needed by defining it as public, and for the sake of doing it properly and good practices you should rename it to a package-local method like below:
static void setEditText(CharSequence text) {
Jonny said:
Change the setEditText to a static method then
From:
public void setEditText(CharSequence text) {
to:
public static void setEditText(CharSequence text) {
Edit: Also the method does not need to be public - you are providing much more access to that method than is needed by defining it as public, and for the sake of doing it properly and good practices you should rename it to a package-local method like below:
static void setEditText(CharSequence text) {
Click to expand...
Click to collapse
Good to know! Thanks a lot!
Hello!
Sorry for my bad english.
I'm trying to develop an app that send a push notification from device A (android) to device B (android).
How can I make this app?
I can't use GCM/Parse server, 'cause a push notification is sent ONLY from server to device!
I must use a DB that save MY contacts? And then, with a query (?), sent a push notif. to user B (B have downloaded the app, of course!)?
Thanks!
Venus88 said:
I can't use GCM/Parse server,
Click to expand...
Click to collapse
Yes you can, you would just need to create an API that would capture a message sent to the server from device A then send it to device B.
Jonny said:
Yes you can, you would just need to create an API that would capture a message sent to the server from device A then send it to device B.
Click to expand...
Click to collapse
Thanks a lot!
And how I can do that? The code for GCM server, i.e. gcm.php:
PHP:
<?php
class GCM {
//put your code here
// constructor
function __construct() {
}
/**
* Sending Push Notification
*/
public function send_notification($registatoin_ids, $message) {
// include config
include_once './config.php';
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registatoin_ids,
'data' => $message,
);
$headers = array(
'Authorization: key=' . GOOGLE_API_KEY,
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Disabling SSL Certificate support temporarly
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
// Close connection
curl_close($ch);
echo $result;
}
}
?>
and
PHP:
<?php
// response json
$json = array();
/**
* Registering a user device
* Store reg id in users table
*/
if (isset($_POST["name"]) && isset($_POST["email"]) && isset($_POST["regId"])) {
$name = $_POST["name"];
$email = $_POST["email"];
$gcm_regid = $_POST["regId"]; // GCM Registration ID
// Store user details in db
include_once './db_functions.php';
include_once './GCM.php';
$db = new DB_Functions();
$gcm = new GCM();
$res = $db->storeUser($name, $email, $gcm_regid);
$registatoin_ids = array($gcm_regid);
$message = array("product" => "shirt");
$result = $gcm->send_notification($registatoin_ids, $message);
echo $result;
} else {
// user details missing
}
?>
allows send notification from server page to one/a group of devices.
Can i "reverse" the direction? from Device A to server (and then from server to device B) automatically?
Up :\
I'm learning how to manage data that I pull from DB (MYSQL) from this coding. I tried to figure out from free source coding but got stuck on this function, can anybody explain to me flow of this coding?
Code:
protected void onPostExecute(Void aVoid) {
name = names.split(":");
email = emails.split(":");
phone = phones.split(":");
combinedArray = combinedText.split(":");
listView.setAdapter(new ArrayAdapter<String>(RetrieveData.this,
android.R.layout.simple_list_item_1, combinedArray));
progressDialog.dismiss();
}
and when I tried to use this code, red line prompt out and saying that cannot resolved this constructor on if i change
Code:
listItems
to
Code:
names
variables on this
Code:
adapter=new ArrayAdapter<String>(this,
R.layout.list_item, R.id.txtitem, listItems);
I don't understand why I need to use 'split' to pull out the output on listview.