Categories
discuss

Error in strings.xml file in Android

I have declared a long string in string.xml of an application.

Declared like this

<string name="terms">PLEASE READ THESE TERMS OF USE CAREFULLY  BY ACCESSING THIS .................</string>

But this gives the following error :

error: Apostrophe not preceded by  (in PLEASE READ THESE TERMS OF USE CAREFULLY

Answer

post your complete string. Though, my guess is there is an apostrophe (‘) character in your string. replace it with (‘) and it will fix the issue. for example,

//strings.xml
<string name="terms">
Hey Mr. Android, are you stuck?  Here, I'll clear a path for you.  
</string>

Ref:

http://www.mrexcel.com/forum/showthread.php?t=195353

https://code.google.com/archive/p/replicaisland/issues/48

Categories
discuss

What’s the best way to learn Smali (and how/when to use Dalvik VM opcodes)?

I know Java, and learned C but never used it. I do not know any form of assembly, either for a virtual machine or a real one.

What’s the best way to learn how to hack Smali?

Answer

UPDATE: As I promised yesterday, I added some more links to the list.

Ufff. Not much documentation around! Best advice? Decompile, and read, and tweak, and see how it did, and start the cycle again and again. But you did not ask for that advice, right? 😉

Now, there are a few places out there that wil lhelp a little bit:

http://androidcracking.blogspot.com/search/label/smali
This is the best one. I even asked the guy a question and he answered very quickly, so go and take a look.

http://pallergabor.uw.hu/androidblog/dalvik_opcodes.html
Very comprehensive table – good reference!

http://webchat.freenode.net/?channels=smali
I never tried it, but it’s on the google code page of the baksmali author ( http://code.google.com/p/smali/ )

http://forum.xda-developers.com/showthread.php?t=777707
Lastly, this is a post I made some time ago describing some hacks to the Captivate camera.
You can follow the diffs in there as I comment a little bit on what each .diff file is doing. The good stuff starts at the post #20.

http://www.slideshare.net/paller/understanding-the-dalvik-bytecode-with-the-dedexer-tool
Interesting slide show with some basic concepts. Good way to start.

http://sites.google.com/site/haynesmathew/home/projects/dalvik-notes
Even more low level than the typical .smali. A reference for later, but a good read.

http://jasmin.sourceforge.net/guide.html
Smali syntax is based on Jasmin, so this gives good concepts.

http://groups.google.com/group/apktool?pli=1
Some discussions there are worth reading through. Also a good place to search for when you’re stuck in something.

And last, but not least, the most helpful trick I used: start coding very basic classes and methods in java, compile them and then baksmali your own code. You know exactly what it does, so it will be a lot easier to follow.

Good luck!

Categories
discuss

How to tell when the user is not focused on this activity?

I wasn’t exactly sure how to word this question, but I know it’s a very simple one to answer. How can tell when the user is no longer on the activity I want the user to be on. For example, how do I know if the user has unexpectedly pressed HOME or if a phone call is received and interrupts the current activity?

Answer

You can check if your Activity has focus with this method:

hasWindowFocus()

If you want to capture when the user leaves the activity, you’d want implement this in your Activity:

protected void onPause() {
     super.onPause();

     // Code here...
 }

Also there is more info about activity life cycle here: http://developer.android.com/reference/android/app/Activity.html

Categories
discuss

Using Java Deflater/Inflater with custom dictionary causes IllegalArgumentException

The following code is based on the example given in the javadocs for java.util.zip.Deflater. The only changes I have made is to create a byte array called dict and then set the dictionary on both the Deflater and Inflater instances using the setDictionary(byte[]) method.

The problem I’m seeing is that when I call Inflater.setDictionary() with the exact same array as I used for the Deflater, I get an IllegalArgumentException.

Here is the code in question:

import java.util.zip.Deflater;
import java.util.zip.Inflater;

public class DeflateWithDictionary {
    public static void main(String[] args) throws Exception {
        String inputString = "blahblahblahblahblah??";
        byte[] input = inputString.getBytes("UTF-8");
        byte[] dict = "blah".getBytes("UTF-8");

        // Compress the bytes
        byte[] output = new byte[100];
        Deflater compresser = new Deflater();
        compresser.setInput(input);
        compresser.setDictionary(dict);
        compresser.finish();
        int compressedDataLength = compresser.deflate(output);

        // Decompress the bytes
        Inflater decompresser = new Inflater();
        decompresser.setInput(output, 0, compressedDataLength);
        decompresser.setDictionary(dict);  //IllegalArgumentExeption thrown here
        byte[] result = new byte[100];
        int resultLength = decompresser.inflate(result);
        decompresser.end();

        // Decode the bytes into a String
        String outputString = new String(result, 0, resultLength, "UTF-8");
        System.out.println("Decompressed String: " + outputString);
    }
}

If I try deflating the same compressed bytes without setting the dictionary, I get no error but the result returned is zero bytes.

Is there anything special I need to do in order to use a custom dictionary with Deflater/Inflater?

Answer

I actually figured this out while formulating the question but thought I should post the question anyway so others might benefit from my struggles.

It turns out you have to call inflate() once after setting the input but before setting the dictionary. The value returned will be 0, and a call to needsDictionary() will then return true. After that you can set the dictionary and call inflate again.

The amended code is as follows:

import java.util.zip.Deflater;
import java.util.zip.Inflater;

public class DeflateWithDictionary {
    public static void main(String[] args) throws Exception {
        String inputString = "blahblahblahblahblah??";
        byte[] input = inputString.getBytes("UTF-8");
        byte[] dict = "blah".getBytes("UTF-8");

        // Compress the bytes
        byte[] output = new byte[100];
        Deflater compresser = new Deflater();
        compresser.setInput(input);
        compresser.setDictionary(dict);
        compresser.finish();
        int compressedDataLength = compresser.deflate(output);

        // Decompress the bytes
        Inflater decompresser = new Inflater();
        decompresser.setInput(output, 0, compressedDataLength);
        byte[] result = new byte[100];
        decompresser.inflate(result);
        decompresser.setDictionary(dict);
        int resultLength = decompresser.inflate(result);
        decompresser.end();

        // Decode the bytes into a String
        String outputString = new String(result, 0, resultLength, "UTF-8");
        System.out.println("Decompressed String: " + outputString);
    }
}

This seems very counter intuitive and clunky from an API design perspective, so please enlighten me if there are any better alternatives.

Categories
discuss

JavaDoc: private fields and methods

What JavaDoc tags should I use in private fields and methods in order to generate javaDoc descriptions?

Answer

See Java Javadoc include Private; you still use the standard JavaDoc comment form but you must instruct the JavaDoc tool to generate the documentation for private members using the -private switch.

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..