Extract Android APK with ADB

You can easily extract an Android APK file from a device using the Android Debug Bridge (ADB). This is a command line utility provided with the Android SDK that allows you to run commands on a remote device as well as transfer files to and from the device.

1. Connect your device

First connect you Android device to your computer and ensure that that USB debugging is enabled on the phone.

2. Verify the Devices

Check that the device is connected and adb can see the device with the command:

$ adb devices
List of devices attached
06157df64b014d28 device

This will display a list of the devices that are currently attached to the computer.  If there are multiple devices you the argument “-s <serial number>” in the remaining adb commands.

3.  Determine the full package name

Next you will need to determine the full package name.  This is in the URL of the application in the GooglePlay store, or you can search the list of packages to find the one that you want.

$ adb shell pm list packages | grep mobilemusings
package:org.mobilemusings.app1
package:org.mobilemusings.app2
package:org.mobilemusings.app3

4. Determine the path for the package

Then you need to get the path on the device.

$ adb shell pm path org.mobilemusings.app1
package:/data/app/org.mobilemusings.app1-2/base.apk

5. Download the APK file

You can now download the file to your computer with the adb pull command.

$ adb pull /data/app/org.mobilemusings.app1-2/base.apk <target-dir>
/data/app/org.mobilemusings.app1-2/base.apk: 1 file pulled. 24.1 MB/s (36446563 bytes in 1.442s)

Dagger 2 – Named

With the named attribute, you are able to create multiple instances of objects of the same class.  This is useful if you are configuring multiple objects that just have different configuration settings.

This is done using the @Named attribute which allows you to identify different instances that have the same class.

@Module
public class ServiceModule {
 
  @Provides
  @Singleton
  @Named("customerService")
  public ServiceGenerator provideCustomerServiceGenerator() {
    return new ServiceGenerator(Config.CUSTOMER_BASE_URL);
  }
 
  @Provides
  @Singleton
  @Named("paymentService")
  public ServiceGenerator providePaymentServiceGenerator() {
    return new ServiceGenerator(Config.PAYMENT_BASE_URL);
  }
}

Then to inject the named instance in to your application you include the named value as part of the @Inject annotation.

class MyActivity {
  @Inject @Named("customerService") ServiceGenerator customerService;
  @Inject @Named("paymentService") ServiceGenerator paymentService;
  ...
}

You can also inject them as part of an injected constructor.

class Transaction {

  @Inject
  public Transaction(@Named("paymentService") ServiceGenerator service) { 
    ...
  }
}

References:

Android Studio – Setting Member and Static Field Prefixes

While there is huge debate over the advantages and disadvantages of Hungarian notation and I generally disagree with much of it, I do still find it useful to differentiate member and static variables with the prefix m and s.

However, by default in Android Studio if you do that you and use code generation, such a generating getters and setters, it will include the prefix as part of the name for the generated code.  Thus a variable named mName which generate the getter  getmName() which gets annoying pretty quickly.

Fortunately there is an easy fix.  You can configure the prefixes for field and static fields in settings (File->Settings->Editor->Code Style->Java->Code Generation).  In this case the name prefixes can be set to “m” for member fields and “s” for static fields as shown below.

SettingsEditorCodeStyleJavaFields_mAnds

Now when you auto-generate the code you will get what you wanted.

public class User {
 
    String mName;
 
    public String getName() {
        return mName;
    }
 
    public void setName(String name) {
        mName = name;
    }
 
    public User(String name) {
        mName = name;
    }
}

Android Studio – Create Desktop Entry

After installing Android Studio on my Linux laptop, I realized that there wasn’t an icon on the Gnome desktop for me to launch the application.  After a little digging, I found this StackOverflow answer which showed just how easy it is.

In Android Studio, just select Tools -> Create Desktop Entry, provide the admin password.

CreateDesktopEntry

And the next thing you know there’s a beautiful icon all ready for launching Android Studio.

AndroidStudioInDesktop

 

Interesting Stuff for July 2016

Maps:

Android

Coding

Java

  • Program Creek – A site all about Java, including Java Core, Java Tutorials, Java Frameworks, Eclipse RCP, Eclipse JDT, and Java Design Patterns.
    • Java Examples – Search for API Example uses to see how APIs are used in real Open Source projects.  Very useful to see how APIs are actually used.
    • Interview Questions – A list of Java related Interview questions

Android Full Screen Activity

In the application, I wanted all of the activities to display the Action Bar except the WebView.  To accomplish this, I created a new AppThem.NoActionBar which keeps the same style as the rest of the application, except disables the Action Bar and the Title.

<style name="AppTheme.NoActionBar" parent="AppTheme">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

Then we can assign the AppTheme.NoActionBar theme to just those activities that should not have the Action Bar. All of the remaining activities will keep AppTheme.

<activity android:name=".WebViewActivity"
    android:theme="@style/AppTheme.NoActionBar">
    <intent-filter>
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

Reference:

Android Studio – Configure Java SE 7

To configure an Android Studio Project to use Java SE 7:

  • Open the Project Structures window.  Select “Open Module Settings” from the right-select menu from the project’s app folder (F4).

    App_Select_OpenModuleSettings

    App Select Open Module Settings

  • On the properties tab of the app module, select 1.7 for the Source and Target Compatibility settings.ProjectStructure_Select_JavaSE7

Interesting Stuff for June 2016

Windows:

To find which version of Windows you are running, enter the following commands in the Command Prompt or Powershell:

wmic os get caption
wmic os get osarchitecture
  • Web Development:
  • svg-sprite –  a low-level Node.js module that takes a bunch of SVG files, optimizes them and bakes them into SVG sprites
  • Grumpicon – The tool processes a set of SVG files, generates PNG fallback images for legacy browsers, and exports a demo page showing how to use the final icons.
  • svgo – SVG Optimizer is a Nodejs-based tool for optimizing SVG vector graphics files.
  • Android Development
  • jsonschema2pojo – Generate Plain Old Java Objects from JSON or JSON-Schema.
  • http://tools.android.com/tips/layout-designtime-attributes: Android Design Time Layout, display values in the designer, but not included in the build.
  • http://tools.android.com/: Android Studio Project Site

Location

Retrofit

Picasso

 

Motorola Joins the Android Revolution

In a recent development, Motorola is making a major investment in supporting Android on mid-range Motorola phones.  In the high end handhelds they are still supporting Windows Mobile/CE, but in the mid-range they are adopting Android.

This will finally bring a real application environment to the average phone and people will no longer have to make the decision to invest hundreds of dollars in a Blackberry or Windows Mobile Phone.  Now they will have a mobile platform with a complete set of mobile capabilities.

The other advantage that Motorola has in this market is that their legacy in barcode scanning through their Symbol acquisition.  We can now realistically have barcode scanning in a mid-range handheld which will open a whole new world of applications such as ShopSavvy.  In the past Symbol has made attempts to bring scanning to the mobile phone, but with very limited success.

Of course the next question will be with the higher end terminals.  With all of the capabilities that are coming with the Android platform, what will happen to the high-end terminals.