Tag: android

Android marshmallow Runtime Permissions

Dangerous permissions need to be granted explicitly

1
2
3
4
5
6
7
8
9
Activity.this.requestPermissions(new String[]
{
Manifest.permission.RECORD_AUDIO
,Manifest.permission.READ_CONTACTS
,Manifest.permission.WRITE_CONTACTS
,Manifest.permission.READ_EXTERNAL_STORAGE
,Manifest.permission.WRITE_EXTERNAL_STORAGE
}
,REQUEST_PERMISSION);

Table 1. Dangerous permissions and permission groups.

Permission Group Permissions
CALENDAR
CAMERA
CONTACTS
LOCATION
MICROPHONE
PHONE
SENSORS
SMS
STORAGE

Defining and Enforcing Permissions

Tags :

[Q&A]How to specify multiple source directory for Android library project

ant.properties

1
source.dir=src:src1/subpath:src2

tools/ant/build.xml
comment or remove the last fileset tag in jar tag

1
2
3
4
5
6
<jar destfile="${out.library.jar.file}">                        
       <fileset dir="${out.classes.absolute.dir}"
            includes="**/*.class"
            excludes="${project.app.package.path}/R.class ${project.app.package.path}/R$*.class ${project.app.package.path}/Manifest.class ${project.app.package.path}/Manifest$*.class ${project.app.package.path}/BuildConfig.class"/>
       <!--fileset dir="${source.absolute.dir}" excludes="**/*.java ${android.package.excludes}" /-->
    </jar>
Tags :

[Q&A] android Build.CPU_ABI returns wrong cpu type

there is an experience,
in certain android x86 phone, with certain android os version,

a bundle APK includes

/libs/armeabi/a.so
/libs/armeabi-v7a/a.so
/libs/armeabi-v7a/b.so
/libs/x86/a.so
/libs/x86/b.so

String cpu = Build.CPU_ABI; // armeabi-v7a is returned which is wrong, but in other x86 phones, “x86″ is returned correctly

however, if /libs/armeabi/b.so is added back, or /libs/armeabi is removed

String cpu = Build.CPU_ABI; // x86 is returned correctly

I have not figured out the cause yet,
just keep in mind, there must be same amount shared libraries in each arch folders.

Tags : ,

Handy adb commends for Android

list devices

1
adb devices

install & uninstall apk

1
2
adb install -r ~/Download/myapk.apk
adb uninstall com.ynjan.myapp

start an activity

1
2
adb shell am start com.ynjan.myapp/.MainActivity
adb shell am start com.ynjan.myapp/com.ynjan.myapp.MainActivity

list installed packages

1
adb shell pm list packages -f

reboot

1
adb reboot

enter devices’s shell

1
adb shell

make input in shell

1
2
3
4
5
6
7
usage: input ... 
   input text <string> [delay]
   input keyevent <key code number or name>
   input [touchscreen|touchpad] tap <x> <y>
   input [touchscreen|touchpad] swipe <x1> <y1> <x2> <y2>
   input trackball press
   input trackball roll <dx> <dy>

for example

1
2
3
4
#unlock screen
input keyevent 82
#device power on/off
input keyevent 26

android key codes

clear application data

1
adb shell pm clear com.ynjan.myapp

Logging

1
2
3
4
5
6
7
8
9
# log with tag
adb logcat -s TAG_NAME_1
# log with priority
adb logcat "*:PRIORITY"
adb logcat -s TAG_NAME:PRIORITY
# log with keyword (regex)
adb logcat | grep "SOME_KEYWORDS"
# clear log
adb logcat -c
Tags : , ,

[QA] android licensechecker start monitoring timeout

LicenseChecker.java

change

 private static final int TIMEOUT_MS =100 * 1000;
Tags : ,

[QA]ListView itemClick not working

Check if there are any clickable UI Elements in ListView

android:focusable="false" android:focusableInTouchMode="false"
doesn't work for ImageButton.

In your layout xml, add this property to root layout

android:descendantFocusability="blocksDescendants"

It works perfectly for a listview that has ImageButton.

Tags : ,

[QA] How to customize checkbox image

<CheckBox
   android:id="@+id/checkbox"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:button="@drawable/btn_star"
   android:gravity="center_vertical|center_horizontal" />

btn_star.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/btn_star_off_normal"
android:state_checked="false"
android:state_window_focused="false" />
<item android:drawable="@drawable/btn_star_on_normal"
android:state_checked="true"
android:state_window_focused="false" />
 
<item android:drawable="@drawable/btn_star_on_pressed"
android:state_checked="true"
android:state_pressed="true" />
<item android:drawable="@drawable/btn_star_off_pressed"
android:state_checked="false"
android:state_pressed="true" />
 
<item android:drawable="@drawable/btn_star_on_focused"
android:state_checked="true"
android:state_focused="true" />
<item android:drawable="@drawable/btn_star_off_focused"
android:state_checked="false"
android:state_focused="true" />
 
<item android:state_checked="false" android:drawable="@drawable/btn_star_off_normal" />
<item android:state_checked="true" android:drawable="@drawable/btn_star_on_normal" />
</selector>
Tags : ,

[QA] shouldOverrideUrlLoading for iframe

Sorry, this entry is only available in 中文.

Tags : ,

[QA] How to enable c++11 for android and ios

Sorry, this entry is only available in 中文.

Tags : ,

[QA] how to remove HTML from a java string

Sorry, this entry is only available in 中文.

Tags : , ,