on Sunday, April 19, 2015


I have been searching around the web for some days and I have not found any known way/tool/library to disassemble APK file into source code from my app.


My goal is to get readable java files from the APK file only by using programmed functions of my app (or usable Android integrated features) but without external third-party solutions.


Dexdump have already been tried, but it didn’t output java files.


This step is crucial for my current educational project, any help will be highly appreciated. Thank you in advance and sorry for my bad English.




i want to extract all links of special webpage i try this:



URL url;
InputStream is = null;
BufferedReader br;
String line;
try {
url = new URL("http://www.stackoverflow.com");
is = url.openStream(); // throws an IOException
br = new BufferedReader(new InputStreamReader(is));

while ((line = br.readLine()) != null) {
if(line.contains("href="))
t1.setText(t1.getText()+line.trim());
}
} catch (MalformedURLException mue) {
mue.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
try {
if (is != null) is.close();
} catch (IOException ioe) {
//exception
}
}


but it doesnt do anything... please help me if you have otherway please help




i am setting a repeated alarm in the android. which fires the activity. This activity is having two buttons stop and snooze. when i click on snooze alarm is postponed to 10 minutes. but alarm is in slider window. i.e it is in onresume state.

i want to stop alarm completely. on both the buttons.



public class RingAlarm extends Activity {

MediaPlayer mp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ring_alarm);
Intent in;
in = getIntent();

String s=in.getStringExtra("habbit_id");
int col= in.getIntExtra("habbit_Color",0);
ScrollView sv = (ScrollView)findViewById(R.id.sv_ra);
if(col<0)
{
sv.setBackgroundResource(R.color.red);
}
if(col>0) {
sv.setBackgroundResource(R.color.green);
}
if(col==0)
{
sv.setBackgroundResource(R.color.yellow);
}
System.out.println("alarm string" + s);
TextView tv = (TextView)findViewById(R.id.habbit_ra);
tv.setText(s);
// mp = MediaPlayer.create(getApplicationContext(), R.raw.song1);
//mp.start();

}
public void onthecancelringclicked(View view){
//mp.stop();
int id=Process.myPid();
finish();
Process.killProcess(id);
//System.exit(0);

}

public void onthesnoozeringclicked(View view){
//mp.stop();
long l=System.currentTimeMillis();
Intent i = this.getIntent();
Random r = new Random();
int ri =r.nextInt(1000000)+64;
PendingIntent pi = PendingIntent.getActivity(this,ri,i,0 );
AlarmManager am = (AlarmManager)this.getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP,l+600000,pi);

finish();
Process.killProcess(Process.myPid());
}
}


and my xml file is



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:background="@color/background"
>

<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="@string/app_name"
android:gravity="left|center"
android:padding="7dp"
android:background="@color/user_profile"/>

<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/sv_ra">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:id="@+id/habbit_ra"
android:text="habbit_name"/>

<AnalogClock
android:text="time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:layout_gravity="center"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="bsy your self"
android:layout_marginTop="20dp"
android:gravity="center"
android:id="@+id/habbit_message_ra"/>

</LinearLayout>
</ScrollView>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="0"
android:background="@color/user_profile">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="stop"
android:background="@color/user_profile"
android:onClick="onthecancelringclicked"/>
<Button
android:background="@color/user_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="snooze 10 min"
android:onClick="onthesnoozeringclicked"/>

</LinearLayout>


as you can see i have implemented Process.killProcess(pid) method. still my alarm is getting saved into the navigation drawer. i want to remove the activity from everywhere




I want to add layout with controls dynamically and in the future I want to save this data to DB.



public void onClickAdd(View view) {
LayoutInflater ltInflater = getLayoutInflater();
final LinearLayout subLayoutFields = (LinearLayout) findViewById(R.id.subLayoutFields);
LinearLayout subLayoutFields1;
final View view1 = ltInflater.inflate(R.layout.sub_fields, subLayoutFields, true);
subLayoutFields.setId(countID);
countID++;
}


And compiler did not finish successful.What's wrong with this?I get error on the



subLayoutFields.setId(countID);


Thank you...




I have a JavaCard with applet which returns simple "HelloWorld". Now I'm trying to send APDU to card from my smartphone.


Basing on Sajedul's respone from here: How to read and write Android NFC tags? I wrote something like this


MainActivity.java



import android.app.PendingIntent;
import android.content.Intent;
import android.nfc.NfcAdapter;
import android.nfc.Tag;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import java.io.IOException;


public class MainActivity extends ActionBarActivity {
NfcAdapter mAdapter;
PendingIntent mPendingIntent;
Tag tag;

@Override
protected void onCreate(Bundle savedInstanceState) {

mAdapter = NfcAdapter.getDefaultAdapter(this);
mPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}

@Override
public void onResume(){
mAdapter.enableForegroundDispatch(this, mPendingIntent, null, null);
}

@Override
public void onPause(){
if(mAdapter != null){
mAdapter.disableForegroundDispatch(this);
}
}

@Override
public void onNewIntent(Intent intent){
getTagInfo(intent);
}

private void getTagInfo(Intent intent){
tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
}

public void doWork(View view) throws IOException {
Tag tagFromIntent = getIntent().getParcelableExtra(NfcAdapter.EXTRA_TAG);

IsoDep isoDep = IsoDep.get(tagFromIntent);
isoDep.connect();

byte[] SELECT = {
(byte) 0x00, // CLA = 00 (first interindustry command set)
(byte) 0xA4, // INS = A4 (SELECT)
(byte) 0x04, // P1 = 04 (select file by DF name)
(byte) 0x0C, // P2 = 0C (first or only file; no FCI)
(byte) 0x06, // Lc = 6 (data/AID has 6 bytes)
(byte) 0x31, (byte) 0x35,(byte) 0x38,(byte) 0x34,(byte) 0x35,(byte) 0x46 // AID = 15845F
};

byte[] result = isoDep.transceive(SELECT);

}
}


But after instllation on phone, app crashes.



java.lang.RuntimeException: Unable to resume activity {com.example.korek.moja/com.example.korek.moja.MainActivity}: android.app.SuperNotCalledException: Activity {com.example.korek.moja/com.example.korek.moja.MainActivity} did not call through to super.onResume()
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2937)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2966)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2367)
at android.app.ActivityThread.access$700(ActivityThread.java:168)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1329)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5493)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.app.SuperNotCalledException: Activity {com.example.korek.moja/com.example.korek.moja.MainActivity} did not call through to super.onResume()
at android.app.Activity.performResume(Activity.java:5452)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2922)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2966)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2367)
at android.app.ActivityThread.access$700(ActivityThread.java:168)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1329)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5493)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
at dalvik.system.NativeStart.main(Native Method)


Even before applying Sajedul's tips app was crashing on click. What to do to get it working? I'm using SGS4, AndroidStudio and 14443-4b card.




I am new to android.I want to work with list view that contain both image and text.getView method is not getting called while I am trying to debug.I need a solution for this.I am trying to bind the item data to list view.Here is my code



public class ResultActivity extends ActionBarActivity {
public List<String> itemList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
JSONObject obj = null;
try {
obj = new JSONObject(getIntent().getStringExtra("json"));
} catch (JSONException e) {
e.printStackTrace();
}
try {
parseJsonData(obj);
} catch (JSONException e1) {
e1.printStackTrace();
}
}
public void parseJsonData(JSONObject obj) throws JSONException {


try {

int j=0;
String ack = (String) obj.get("ack");
int itemCount =obj.getInt("itemCount");
String ItemPrice="";

for(j=0;j<itemCount;j++) {
itemList = new ArrayList<String>();
String itemObject = "item"+1;

JSONObject itemObj = obj.getJSONObject(itemObject);

JSONObject BasicInfoObj =itemObj.getJSONObject("basicInfo");
JSONObject sellerInfoObj =itemObj.getJSONObject("sellerInfo");
JSONObject shippingInfoObj = itemObj.getJSONObject("shippingInfo");
String galleryURL = BasicInfoObj.getString("galleryURL");
String pictureURLSuperSize =BasicInfoObj.getString("pictureURLSuperSize");
int CurrentPrice=BasicInfoObj.getInt("convertedCurrentPrice");
int shippingServiceCost =BasicInfoObj.getInt("shippingServiceCost");
String title =BasicInfoObj.getString("title");

if(CurrentPrice == 0)
{
ItemPrice ="Price:"+" "+"$"+shippingServiceCost+" "+"(FREE Shipping)";
}
else
{
ItemPrice = "Price:"+" "+"$"+shippingServiceCost+" "+ "(+$"+ CurrentPrice+ "for Shipping)";
}
itemList.add(0,galleryURL);
itemList.add(1,pictureURLSuperSize);
itemList.add(2,title);
itemList.add(3,ItemPrice);
populateListView();

}
}


catch (JSONException e) {
e.printStackTrace();
}
}

private void populateListView()
{
ArrayAdapter<String> adapter =new MyListAdapter();
ListView list =(ListView) findViewById(R.id.ItemListView);
list.setAdapter(adapter);
adapter.getCount();


}
private class MyListAdapter extends ArrayAdapter<String> {
public MyListAdapter()
{
super(ResultActivity.this,R.layout.item_view,itemList);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View itemView = convertView;
if(itemView==null) {
itemView =getLayoutInflater().inflate(R.layout.item_view,parent,false);
}
String itemtowork =itemList.get(position);
ImageView imageView =(ImageView)itemView.findViewById(R.id.item_icon);
//String ImageUrl=itemtowork.;
//imageView.setImageURI();

return itemView;
}


}




@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);

}


}



after updated support libraries for material design I get this crash on some devices ( Samsung , Wiko )



java.lang.ClassCastException
com.wax.app.MainActivity.onOptionsItemSelected(MainActivity.java:310)
android.app.Activity.onMenuItemSelected(Activity.java:2612)
android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:350)
android.support.v7.app.ActionBarActivity.onMenuItemSelected(ActionBarActivity.java:152)
android.support.v7.app.ActionBarActivityDelegate$1.onMenuItemSelected(ActionBarActivityDelegate.java:75)
android.support.v7.widget.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:44)
android.support.v7.internal.app.ToolbarActionBar$2.onMenuItemClick(ToolbarActionBar.java:76)
android.support.v7.widget.Toolbar$1.onMenuItemClick(Toolbar.java:164)
android.support.v7.widget.ActionMenuView$MenuBuilderCallback.onMenuItemSelected(ActionMenuView.java:738)
android.support.v7.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:802)
android.support.v7.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:153)
android.support.v7.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:949)
android.support.v7.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:939)
android.support.v7.widget.ActionMenuView.invokeItem(ActionMenuView.java:596)
android.support.v7.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:145)
android.view.View.performClick(View.java:4439)
android.view.View$PerformClick.run(View.java:18395)
android.os.Handler.handleCallback(Handler.java:725)
android.os.Handler.dispatchMessage(Handler.java:92)
android.os.Looper.loop(Looper.java:176)
android.app.ActivityThread.main(ActivityThread.java:5319)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
dalvik.system.NativeStart.main(Native Method)


java


I just added this to Progruard



-keep class !android.support.v7.internal.view.menu.**,android.support.v7.** {*;}


What can I do? Thanks :)