Search This Blog

Tuesday, December 23, 2014

Add JavaScript/CSS syntax highlighting in Android Studio

  • From Android Studio Menu, go to File -> Import Settings...
  • Locate the settings.jar file from this repository
  • From "Select Components to Import" make sure you have "File types" checked, then press OK

Download this file:
https://github.com/manifestinteractive/android-studio-filetypes/blob/master/settings.jar



Friday, December 12, 2014

Android: get sha from *.apk file; validate *.apk content; check apk integrity

The apk file might get destroyed when it's transferred through a network. If the file is signed with a certificate (most Android applications are signed by the publisher) you can check the file integrity from the command line before installing the application. The following methods check the certificate validity as well as validate apk file contents.



keytool -list -printcert -jarfile app-sa.apk

(java/jre/bin/keytool)


 Signer #1:  
   
 Signature:  
   
 Owner: CN=Somevalue, OU=Developers, O=Somevalue. Somevalue, L=Somevalue, ST=Somevalue, C=PL  
 Issuer: CN=Somevaluei, OU=Developers, O=Somevalue Somevalue, L=Somevalue, ST=Somevalue, C=PL  
 Serial number: Somevalue  
 Valid from: Thu Jul 17 11:25:00 CEST 2014 until: Mon Jul 11 11:25:00 CEST 2039  
 Certificate fingerprints:  
       MD5: 11:11:11:11:11:11:11:11:11:11:A3:D8:B5:11:11:11  
       SHA1: 11:11:11:11:11:11:11:11:11:0D:42:BC:2D:01:11:11:11:11:11:11  
       SHA256: 11:11:11:11:11:11:11:11:11:11:11:11:D4:7C:B7:1C:C8:14:8E:43:11:11:11:11:11:11:11:11:3E:11:11:11  
       Signature algorithm name: SHA256withRSA  
       Version: 3  
   
 Extensions:   
   
 #1: ObjectId: 2.5.29.14 Criticality=false  
 SubjectKeyIdentifier [  
 KeyIdentifier [  
 0000: 11 11 11 11 11 11 11 11  11 11 11 11 11 11 36 F3 ..]....%.B....6.  
 0010: 11 11 11 11                    ....  
 ]  
 ]  
   



jarsigner -verbose -verify -certs app-sa.apk

(java/jre/bin/jarsigner)


 sm    162096 Thu Dec 11 16:39:46 CET 2014 resources.arsc

      X.509, CN=Somevalue, OU=Developers, O=Somevalue Somevalue, L=Somevalue, ST=Somevalue, C=PL
      [certificate is valid from 7/17/14 11:25 AM to 7/11/39 11:25 AM]
      [CertPath not validated: Path does not chain with any of the trust anchors]

sm    4416396 Thu Dec 11 16:40:46 CET 2014 classes.dex

      X.509, CN=Somevalue, OU=Developers, O=Somevalue Somevalue, L=Somevalue, ST=Somevalue, C=PL
      [certificate is valid from 7/17/14 11:25 AM to 7/11/39 11:25 AM]
      [CertPath not validated: Path does not chain with any of the trust anchors]

sm       621 Thu Dec 11 16:40:48 CET 2014 androidannotations-api.properties

      X.509, CN=Somevalue, OU=Developers, O=Somevalue Somevalue, L=Somevalue, ST=Somevalue, C=PL
      [certificate is valid from 7/17/14 11:25 AM to 7/11/39 11:25 AM]
      [CertPath not validated: Path does not chain with any of the trust anchors]

s      32963 Thu Dec 11 16:40:50 CET 2014 META-INF/MANIFEST.MF

      X.509, CN=Somevalue, OU=Developers, O=Somevalue Somevalue, L=Somevalue, ST=Somevalue, C=PL
      [certificate is valid from 7/17/14 11:25 AM to 7/11/39 11:25 AM]
      [CertPath not validated: Path does not chain with any of the trust anchors]

       32984 Thu Dec 11 16:40:50 CET 2014 META-INF/CERT.SF
        1495 Thu Dec 11 16:40:50 CET 2014 META-INF/CERT.RSA

  s = signature was verified 
  m = entry is listed in manifest
  k = at least one certificate was found in keystore
  i = at least one certificate was found in identity scope

jar verified.
The latter of the methods verifies apk content as well. 



Monday, December 8, 2014

Android Studio - new Android 5.0 Lollipop emulators; Intel hardware-assisted virtualization; Android Studio Android 5.0 emulator landscape mode


Google has released the new Android Studio 1.0 RC 4. It consists new Android emulators (in the SDK of course) which take full advantage of Intel hardware-assisted virtualization and can use the host GPU.

Here is how to enable these on your Intel machine.


Android Emulator Shortcuts

Ctrl+F11 Switch layout orientation portrait/landscape backwards

Ctrl+F12 Switch layout orientation portrait/landscape forwards

Main Device Keys
Home Home Button

F2 Left Softkey / Menu / Settings button (or Page up)

Shift+f2 Right Softkey / Star button (or Page down)

Esc Back Button

F3 Call/ dial Button

F4 Hang up / end call button

F5 Search Button

Other Device Keys
Ctrl+F5 Volume up (or + on numeric keyboard with Num Lock off) Ctrl+F6 Volume down (or + on numeric keyboard with Num Lock off) F7 Power Button Ctrl+F3 Camera Button

Ctrl+F11 Switch layout orientation portrait/landscape backwards

Ctrl+F12 Switch layout orientation portrait/landscape forwards

F8 Toggle cell network

F9 Toggle code profiling

Alt+Enter Toggle fullscreen mode

F6 Toggle trackball mode



Sunday, December 7, 2014

Ubuntu mount nfs share

Ubuntu does not come with nfs server so we need to install it:

$ sudo apt-get install nfs-kernel-server

Then we can mount nfs shares like this:

$ sudo mount 1.2.3.4:/home /home/user/nfs/home


to check whether the share mounted successfully:

mount -t nfs


more info

Friday, November 28, 2014

Ubuntu 14.04 - how to create shortcuts in unity launcher

To create a shortcut to an application in unity launcher just make in a symlink in one of the following locations:

/home/user/.local/share/applications

or

/usr/share/applications

or

/usr/local/share/applications

Example command:

ln -s /home/user/applicationsFolder/app1 /usr/share/applications/app1






Build Android apps as Chrome apps/extensions, Build Android apps for ChromeOS, configure build server

What I want to accomplish is configure a build server (like TeamCity) to build an Android application from source and convert it to a chrome extension that can be published on Chrome WebStore as an application.

First of all you can read this source which explains how to run android apps in chrome.

1. Download ARChon runtime and install it as an extenion in Chrome.

2. You can convert your apk manually with this chrome extension - Twerk

3. To enable Chrome App Launcher on Ubuntu (speeds up app launching) - follow this link.

4. Install chromeos-apk
asdsa

  1. In a terminal, run the following command: sudo apt-get install npm
  2. (Ubuntu only): Run the following command: sudo apt-get install lib32stdc++6
  3. Download node.js.
  4. Unzip the tar.gz file you downloaded from the above link.
  5. Per the README file, open a terminal to the unzipped folder containing node.js. And run the following commands in order:
    1. ./configure
    2. make
    3. make install
  6. Run the command: sudo npm install chromeos-apk -g
  7. To make sure you're updated to the latest version (now or in the future), run: sudo npm install -g chromeos-apk@latest
5. Convert your compiled application in apk to chrome app with:

chromeos-apk --tablet --scale --name ApplicationName application.apk


5. Remember - to update the chromeos-apk plugin just run:

sudo npm install -g chromeos-apk@latest

Thursday, November 27, 2014

Install CyanogenMod 11 on XPeria P running stock Android 4.1

1. First of all you need to unlock your bootloader. [worked]
Go developer_sony to proceed with unlocking (official SONY's website)

  1. In your device, open the dialler and enter *#*#7378423#*#* to access the service menu.
  2. Tap Service info > Configuration > Rooting Status. If Bootloader unlock allowed says Yes, then you can continue with the next step. If it says No, or if the status is missing, your device cannot be unlocked.


2. Then you need to root your XPeria P [worked]
The following root method worked for me:
DooMLoRD Easy Rooting Toolkit (v17)


3. To install CWM [worked]

CWM xda link
You need to have root access in order to use this method.
It worked fine for me.

CyanogenMod 11 did NOT install from CWM for me. It started fine and then couldn't read the phone model number properly.


4. To install TWRP [did not work as expected]

extract boot.img from cm-11-20141012-SNAPSHOT-M11-nypon.zip and copy it to the main script directory.

flash the boot image in fastboot mode with:
sudo fastboot flash boot boot.img


4. Cyanogemod 11 link

http://forum.xda-developers.com/xperia-u/p-development/rom-cyanogenmod-11-0-t2626639


Workaround:
After 1,2,4 (After flashing boot.img )
enter CWM and try to flash CyanogenMod. The device will restart and enter bootloop. Try pressing power button to enter TWRP.
Then flash cyanogenmod normally.


HOW TO ENTER RECOVERY MODE in Xperia P

howto

CyanogenMod:
1.press power + volume up for 3 seconds until the phone vibrates
2. keep on pressing volume up multiple times until clockworkmod recovery shows

TWRP
1.press power + volume up for 3 seconds until the phone vibrates
2. keep on pressing power until twrp shows

Monday, October 20, 2014

Android Annotations - create @EBean instance from code; Android Annotations inject from code; create instance dynamically

Usually when you need an instance of @EBean you simply use inversion of control:

@EBean
public class Upgrade0001 implements IUpgrade {

    @Bean
    protected SDao mSDao;
}


@EActivity(R.layout.activity_some)
public class SomeActivity extends Activity {
    @Bean
    protected Upgrade0001 mUpgrade0001;
}


but what if you wanted to dynamically create an instance of @EBean from code?

Simple reflection won't help - mSDao will be null:


IUpgrade upgrade = (IUpgrade) Class.forName("Upgrade0001_").newInstance();


Just call the getInstance_ method which every AndroidAnnotations class implements:


Method m = Class
                         .forName(upgradeItem.getUpgradeClassName())
                         .getMethod("getInstance_", Context.class);

Object result = m.invoke(null, this.getApplicationContext());
IUpgrade upgrade = (IUpgrade)result;

Thursday, July 24, 2014

Ubuntu 14.04 - convert multiple images to *.pdf

To convert all (multiple) images in a folder to a single pdf file you can just type:


convert -compress jpeg * output_file.pdf


inside the folder with the photos.



Tuesday, July 22, 2014

Ubuntu 14.04 - install BIMP - Batch image manipulation

BIMP is useful to apply filter to multiple images in GIMP.

HOW TO INSTALL BIMP on Ubuntu 14.04 x64

sudo apt-get install libgimp2.0-dev
(optionally:
sudo apt-get build-dep gimp)

make
make install


Homepage: http://registry.gimp.org/node/26259

Compiled binary for Ubuntu 14.04 x64
download

just copy this binary to:
~/.gimp-2.8/plug-ins/bimp
chmod 772  ~/.gimp-2.8/plug-ins/bimp





Wednesday, July 2, 2014

Android L preview Emulator under UBUNTU 14.04 x64 & Windows 7 x64 - optimal settings

UBUNTU 14.04 x64:

 sudo apt-get install cpu-checker


$ kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be used


sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils

export LD_LIBRARY_PATH=/home/your_user_name/Develop/android-sdk/tools/lib:$LD_LIBRARY_PATH

sudo apt-get install libgl1-mesa-dev

sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so





Start the emulator with:

./emulator-x86 -avd your_avd_name -qemu -m 2047 -enable-kvm

1) select Intel Atom (x86) - for VT-x to work
2) skin - select WVGA800 - for other skins the emulator is too big/small
3) remember to check "Use host GPU"



WINDOWS:

Install:
Intel(R) Hardware Accelerated Execution Manager (HAXM)
with Intel(R) Virtualization Technology (VT)

It's really a must. Without HAXM the emulator is dead slow. Also remember to enable VT-x on your mainboard's BIOS settings for HAXM to work.

1) select Intel Atom (x86) - for VT-x to work
2) skin - select WVGA800 - for other skins the emulator is too big/small
3) do not set more than 700 MB of RAM - Windows does not handle that well
4) remember to check "Use host GPU"




Monday, June 16, 2014

Ubuntu - setup port forwarding

To enable port forwarding on Ubuntu:

nano /etc/sysctl.conf

uncomment:
net.ipv4.ip_forward=1


Restart the system and check whether ip forwarding is enabled:
cat /proc/sys/net/ipv4/ip_forward

192.168.0.0   - NETWORK you're forwarding the traffic TO
10.0.0.0. - NETWORK you're forwarding the traffic FROM
IP - just your ip address in 10.0.0.0 network taken from eth0 interface


#!/bin/sh
IP="$(ifconfig eth0 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}')"
iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -d 0.0.0.0/0 -j SNAT --to-source $IP
iptables -t nat -A POSTROUTING -s 192.168.0.123/32 -d 0.0.0.0/0 -j SNAT --to-source 192.168.0.100

#forward :5556 (10.0.0.0 network) -> :22 (192.168.0.0 network)
iptables -t nat -A PREROUTING -p tcp --dport 5556 -j DNAT --to 192.168.0.123:22
iptables -A FORWARD -p tcp -d 192.168.0.123 --dport 5556 -j ACCEPT



Thursday, June 12, 2014

Android - change MAC address of eth0

Requirements: root & busybox

To change:
ifconfig eth0 hw ether 00:11:b2:13:14:55

To check your current MAC address:
iplink show eth0




Thursday, June 5, 2014

Ubuntu 14.04 x64 - install NTP service


sudo apt-get install openntpd

sudo nano /etc/openntpd/ntpd.conf



add lines:
listen on *
servers 127.0.0.1


sudo service openntpd restart





Tuesday, April 29, 2014

Android - show/hide Android system bar (tablet's bottom bar) from adb

To hide Android system bar from adb:

adb shell service call activity 42 s16 com.android.systemui

To restore Android system bar from adb:

adb shell am startservice -n com.android.systemui/.SystemUIService

Wednesday, March 12, 2014

Midnight Commander tutorial

Quick view - Ctrl-x + q     Allows you to view file content in a separate window easily
Search for file  - Ctrl + s    Narrows down the file list to the individual file you're looking for
Compress file  - F2 then 3   compresses the current subdirectory to tar.gz
Refresh file list - Ctrl + r
Show console/Hide panels - Ctrl + O      Shows the underlying console window
Copy the highlighted file name to lower console line - Ctrl+j
Select a group of file -   +         Select a group of files based on a regexp
Frequently selected ftp sites (directory hotlist) -    Ctrl +  \
find files/find file content/find string in text file -   Alt + ?
see directory size/how much space a directory occupies -  Ctrl + space
change the size (width) of tabs, change left-right window width - Ctrl + Shift + left/right arrow
select all files and subfolders - Alt + Shift + '='      and enter '*' pattern
select the same directory on the second pane - Alt + 'i'


Monday, March 10, 2014

Install Midnight Commander (MC) on Android 4.0+

Requirements:

  • ROOT
  • busybox installed
To download an *.apk installer follow this link.

The xda-installer from Recognized Developer viulian installs MC here:
/system/share/mc
/system/libexec/mc
/system/etc/mc
/system/xbin
/system/etc/terminfo

Install script from *.tar.gz:


echo Pushing files....
adb push mclibs.tar.gz /mnt/local/mclibs.tar.gz
adb push xterm.tar.gz /mnt/local/xterm.tar.gz
sleep 2
echo Installing Midnight Commander...
adb shell su -c mount -o remount,rw /system
adb shell su -c cp /mnt/local/mclibs.tar.gz /system 
adb shell su -c cp /mnt/local/xterm.tar.gz /system 
adb shell su -c tar xzvf mclibs.tar.gz
adb shell su -c tar xzvf xterm.tar.gz
adb shell su -c mount -o remount,ro /system


Files:

Thursday, February 20, 2014

Adding Unmanaged Dependencies to a Maven Project

Adding Unmanaged Dependencies to a Maven Project

To add a local jar to maven build you need to deploy it to your project's local repository (that's NOT your local maven's repository placed in home/user/.m2 folder).

Adding the jar file as a system dependency won't work as the jar would have to be copied by hand to every device where you want to install your application.

Changing local system dependency to maven's local project repository:

            <dependency>
            <groupId>com.wagnerandade</groupId>
            <artifactId>coollection</artifactId>
            <version>0.2.2</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/coollection-0.2.2.jar</systemPath>
        </dependency>

Use the command to register a local project repository:

mvn deploy:deploy-file -Durl=file:///android/myapplication/repo/ -Dfile=coollection-0.2.2.jar -DgroupId=com.wagnerandade -DartifactId=coollection -Dpackaging=jar -Dversion=0.2.2



and change the pom to:

          <repositories>
        <repository>
            <id>project.local</id>
            <name>project</name>
            <url>file:${project.basedir}/repo</url>
        </repository>
    </repositories>

[...]

        <dependency>
            <groupId>com.wagnerandade</groupId>
            <artifactId>coollection</artifactId>
            <version>0.2.2</version>
     </dependency>


PDF tutorial



Thursday, February 13, 2014

Android - Integrate scaloid with android annotations, maven and proguard

I managed to integrate Scaloid with android annotations, maven and proguard. The resulting "hello world" project contains:
- main start Activity written in SCALA
- second activity written in SCALA which uses Java classes (example of JAVA & SCALA integration)
- third activity is written in Java and uses Android Annotations
- all in obsfuscated & profiled with ProGuard
- project compiles from maven

Project: here



Wednesday, February 12, 2014

IntelliJ 13 + ProGuard + Android Annotations on Android

Proguard configuration working with:
IntelliJ 13 & Android Annotations

download

ProGuard 4.11
Android annotations 2.7.1

Settings:







Tuesday, February 11, 2014

IntelliJ 13 + Scaloid + maven 3

Some helpful links:

Scaloid:  https://github.com/pocorall/scaloid
Scaloid maven project:  https://github.com/pocorall/hello-scaloid-maven
or https://github.com/kosiara/hello-scaloid-maven
Mavenhttp://maven.apache.org/
Intellij 13http://www.jetbrains.com/idea/
JDK 6: JDK_6
Android API level 8:  http://developer.android.com/sdk/index.html


1. Download&install&set up - maven, intellij 13, Android SDK
2. Install JDK 6 alongside JDK 7 (in my case it was: /usr/lib/jvm/jdk1.6.0_45 )
3. Download API level 8 SDK platform for Android from Android SDK Manager
(adt-linux-x64/sdk/tools/android ), set ANDROID_HOME env variable
4. Clone scaloid maven project repository
5. mvn package -Prelease  in the scaloid maven project
6. Run IntelliJ, install SCALA plugin (worked for me on version:  0.30.380 and 0.26.361)
7. Close IntelliJ, choose Open Project,  navigate to the project directory and open the pom.xml file (hello-scaloid-maven/pom.xml)

upon question:

Language level changes will take effect on project reload.
Would you like to reload project "hello-scaloid-maven" now?

select Yes. Android framework will be loaded.

8. Change project settings according to the attached images.

















Errors:

Unable to execute dex: method ID not in [0, 0xffff]: 65536

Your ProGuard configuration DID not work. Scala has too many methods for dex compiler. Dex has a limit of 65536. ProGuard limits the number of SCALA methods and so the dex compiler succeeds in processing the class files.




Monday, February 3, 2014

HTML :textile advanced table layout

In this example we're going learn how to:
- create a cell spanning 2 rows
- create a cell spanning 2 cells
- create styled links
- create image with specific height/width


Advanced textile table layout


table(#newstable){width:100%; border:0px;border-collapse:collapse}.
|\2{font-weight:bold;color:#FF6700;width:50%}. Topic 1 |\2{font-weight:bold;color:#FF6700;width:50%}. Topic 2 |
|/3{width:1%}.!{height:120px;width:170px}http://www.android.com/media/android_vector.jpg! 
|{height:22px}<. By: example |/3{width:1%}.!{height:120px;width:170px}http://www.android.com/media/android_vector.jpg! |{height:22px}<. 1111 |
|<. text  |<. 2222 |
|{height:22px}<. "{font-style:italic;color:#FF6700}Read more":http://test.com |{height:22px}<. "{font-style:italic;color:#FF6700}Read more":http://test.com |



Download textile

Tuesday, January 14, 2014

Ubuntu 12.04 - make a DVD ISO from command line


Make a DVD ISO from command line. No additional tools required.

sudo dd if=/dev/sr0 of=image_name.iso


Sunday, January 12, 2014

Ubuntu 12.04 - TeamViewer 8 / TeamViewer 9 - no sound/no microphone. Sound problems

TeamViewer 8 run in Wine so if there is no sound - it's probably wine's configuration fault. In my case I had a standard Intel's integrated sound card in Lenovo Workstation.

To resolve the issue, install wine 1.4 and then configure teamviewer's wine settings:

sudo apt-get install wine1.4

and then:

WINEPREFIX=$HOME/.config/teamviewer8 winecfg


For more details go to:

Configuration:



THE PROCEDURE DOES NOT WORK FOR TEAMVIEWER 9,
On Ubuntu 12.04 I tried:

  • removing puleaudio package
  • installing wine1.6 instead wine1.4 (teamviewer9 runs on wine1.6)

sudo apt-get purge pulseaudio

WINEPREFIX=$HOME/.config/teamviewer9 winecfg

$ sudo add-apt-repository ppa:ubuntu-wine/ppa
$ sudo apt-get update
$ sudo apt-get install wine1.6
$ sudo apt-get install winetricks