Tuesday, April 8, 2014

How to handle textview link click to open new activity?

Step 1: Here is how the Textview looks like.
Activity 1:
TextView tv = (TextView) findViewById(R.id.buy_tc_label);
tv.setMovementMethod(LinkMovementMethod.getInstance());
tv.setText(Html.fromHtml(getString(R.string.terms_and_condition_start) + " <a href='com.package.name://tc/terms'>" + getString(R.string.terms_and_conditions) + "</a>"));

Strings.xml
    <string name="terms_and_condition_start">I accept the</string>
    <string name="terms_and_conditions">Terms &amp; Conditions</string>

Step 2: manifest.xml
<activity
            android:name=".TCsActivity"
            android:theme="@style/Theme" >
            <intent-filter>
                <data
                    android:scheme="com.package.name" />
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>
</activity>

This means that links starting with com.package.name:// will be handled by TCsActivity.

So all I have to do is construct a URL that contains the information I want to convey:

com.package.name://action-to-be-needed/abc
In my TCsActivity, I can retrieve this.

TCsActivity:

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.terms_conds);
WebView webView = (WebView) findViewById(R.id.terms_and_conditions);
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.GINGERBREAD)
{

MyWebViewClient webViewClient = new MyWebViewClient(this);

webView.setWebViewClient(webViewClient);
}

webView.setWebChromeClient(new WebChromeClient());
String tc = "blah blah blah terms and condition content goes here";
webView.loadDataWithBaseURL (null, tc, "text/html", "utf-8", "about:blank");
}

output Xml layout: terms_conds.xml
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/terms_and_conditions"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />




Wednesday, March 26, 2014

Steps for decoding .apk files

Step 1:

- Copy .apk file in your folder.
- Rename the extension of this .apk file to .zip (eg.: rename from filename.apk to filename.zip) and save it.
- There are assets, meta-inf, res, classes.dex files, etc.
At this stage you are able to see drawable but not xml and java files.

Step 2:

- Extract the zip file.
- Download dex2jar from this link http://code.google.com/p/dex2jar/ and extract it to the same folder.
- Move the classes.dex file into the dex2jar folder.
- Now open command prompt and change directory to that folder.
- Then write dex2jar classes.dex and press enter. Now you get classes_dex2jar.jar file in the same folder.
- Then download java decompiler from http://jd.benow.ca/ and now double click on jd-gui and click on open file.
- Then open classes_dex2jar.jar file from that folder.
- Now you get class files and save all these class files (click on file then click "save all sources" in jd-gui) by src name.
At this stage you get java source but the xml files are still unreadable, so continue.

Step 3:

- Open another folder and put .apk file which you want to decode

- download apktool v1.x  and apktool install window (both can be downloaded at the same location) and put in the same folder

- download framework-res.apk file and put in the same folder (Not all apk file need framework-res.apk file)

- Open a command window

- Navigate to the root directory of APKtool and type the following command:  apktool if framework-res.apk

- apktool d "fname".apk ("fname" denotes filename which you want to decode)

now you get a file folder in that folder and now you can easily read xml files also.

Step 4:

It's not any step just copy contents of both folder(in this case both new folder)to the single one

Src: http://stackoverflow.com/