Skip to content

Commit 89dd9a9

Browse files
authored
Merge pull request #20 from codeskyblue/fix-19
fix parse of intent-filters, close #19
2 parents 01c4bfa + 4854b78 commit 89dd9a9

File tree

6 files changed

+35
-15
lines changed

6 files changed

+35
-15
lines changed

.travis.yml

-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ language: go
22
sudo: false
33

44
go:
5-
- '1.3.x'
6-
- '1.4.x'
7-
- '1.5.x'
8-
- '1.6.x'
9-
- '1.7.x'
105
- '1.8.x'
116
- '1.9.x'
127
- '1.10.x'

apk/apk.go

+15-5
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,30 @@ func (k *Apk) PackageName() string {
108108
return k.manifest.Package
109109
}
110110

111-
// MainActivty returns the name of the main activity.
111+
func isMainIntentFilter(intent ActivityIntentFilter) bool {
112+
if intent.Action.Name != "android.intent.action.MAIN" {
113+
return false
114+
}
115+
for _, category := range intent.Categories {
116+
if category.Name == "android.intent.category.LAUNCHER" {
117+
return true
118+
}
119+
}
120+
return false
121+
}
122+
123+
// MainActivity returns the name of the main activity.
112124
func (k *Apk) MainActivity() (activity string, err error) {
113125
for _, act := range k.manifest.App.Activities {
114126
for _, intent := range act.IntentFilters {
115-
if intent.Action.Name == "android.intent.action.MAIN" &&
116-
intent.Category.Name == "android.intent.category.LAUNCHER" {
127+
if isMainIntentFilter(intent) {
117128
return act.Name, nil
118129
}
119130
}
120131
}
121132
for _, act := range k.manifest.App.ActivityAliases {
122133
for _, intent := range act.IntentFilters {
123-
if intent.Action.Name == "android.intent.action.MAIN" &&
124-
intent.Category.Name == "android.intent.category.LAUNCHER" {
134+
if isMainIntentFilter(intent) {
125135
return act.TargetActivity, nil
126136
}
127137
}

apk/apk_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ func TestGetIcon(t *testing.T) {
1818

1919
label, err := apk.Label(nil)
2020
assert.NoError(t, err)
21-
assert.Equal(t, label, "HelloWorld")
21+
assert.Equal(t, "HelloWorld", label)
2222
t.Log("app label:", label)
2323

24-
assert.Equal(t, apk.PackageName(), "com.example.helloworld")
24+
assert.Equal(t, "com.example.helloworld", apk.PackageName())
2525

2626
manifest := apk.Manifest()
2727
assert.Equal(t, manifest.SDK.Target, 24)
2828

2929
mainActivity, err := apk.MainActivity()
3030
assert.NoError(t, err)
31-
assert.Equal(t, mainActivity, "com.example.helloworld.MainActivity")
31+
assert.Equal(t, "com.example.helloworld.MainActivity", mainActivity)
3232
}

apk/apkxml.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ type ActivityCategory struct {
2020

2121
// ActivityIntentFilter is an intent filter of an activity.
2222
type ActivityIntentFilter struct {
23-
Action ActivityAction `xml:"action"`
24-
Category ActivityCategory `xml:"category"`
23+
Action ActivityAction `xml:"action"`
24+
Categories []ActivityCategory `xml:"category"`
2525
}
2626

2727
// AppActivity is an activity in an application.

go.mod

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module github.com/shogo82148/androidbinary
2+
3+
require (
4+
github.com/pkg/errors v0.8.1
5+
github.com/stretchr/testify v1.3.0
6+
)

go.sum

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
2+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
4+
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
5+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
6+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
8+
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
9+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=

0 commit comments

Comments
 (0)