Skip to content

Commit 2f267f7

Browse files
committed
Added ActivityNotFoundException handle logic
1 parent f59d908 commit 2f267f7

File tree

5 files changed

+54
-30
lines changed

5 files changed

+54
-30
lines changed

Demo/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ buildscript {
99
*/
1010

1111
android {
12-
compileSdkVersion 24
12+
compileSdkVersion 23
1313
buildToolsVersion "24.0.0"
1414

1515
defaultConfig {

Library/Library.iml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,6 @@
6565
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
6666
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
6767
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
68-
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
69-
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
70-
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
71-
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
72-
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
73-
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
74-
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
75-
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
7668
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
7769
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
7870
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
@@ -81,6 +73,14 @@
8173
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
8274
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
8375
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
76+
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
77+
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
78+
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
79+
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
80+
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
81+
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
82+
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
83+
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
8484
<excludeFolder url="file://$MODULE_DIR$/build/docs" />
8585
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
8686
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />

Library/src/main/java/net/sjava/appstore/AmazonStoreApp.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.sjava.appstore;
22

3+
import android.content.ActivityNotFoundException;
34
import android.content.Context;
45
import android.content.Intent;
56
import android.net.Uri;
@@ -27,9 +28,12 @@ public boolean isInstalled(Context ctx) {
2728
@Override
2829
public void openApp(Context ctx, String uniqueId) {
2930
if(isInstalled(ctx)) {
30-
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(APPSTORE_URI +"p=" + uniqueId));
31-
ctx.startActivity(intent);
32-
return;
31+
try {
32+
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(APPSTORE_URI + "p=" + uniqueId));
33+
ctx.startActivity(intent);
34+
return;
35+
} catch (ActivityNotFoundException e) { // ignore
36+
}
3337
}
3438

3539
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(APP_URL + "p=" + uniqueId));
@@ -39,9 +43,12 @@ public void openApp(Context ctx, String uniqueId) {
3943
@Override
4044
public void searchApp(Context ctx, String keyword) {
4145
if(isInstalled(ctx)) {
42-
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(APPSTORE_URI +"s=" + keyword));
43-
ctx.startActivity(intent);
44-
return;
46+
try {
47+
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(APPSTORE_URI +"s=" + keyword));
48+
ctx.startActivity(intent);
49+
return;
50+
} catch (ActivityNotFoundException e) { // ignore
51+
}
4552
}
4653

4754
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(APP_URL + "s="+ keyword));
@@ -51,9 +58,12 @@ public void searchApp(Context ctx, String keyword) {
5158
@Override
5259
public void openPublisherApps(Context ctx, String key) {
5360
if(isInstalled(ctx)) {
54-
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(APPSTORE_URI + "p=" + key +"&showAll=1"));
55-
ctx.startActivity(intent);
56-
return;
61+
try {
62+
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(APPSTORE_URI + "p=" + key +"&showAll=1"));
63+
ctx.startActivity(intent);
64+
return;
65+
} catch (ActivityNotFoundException e) { // ignore
66+
}
5767
}
5868

5969
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(APP_URL + "p=" + key +"&showAll=1"));

Library/src/main/java/net/sjava/appstore/OneStoreApp.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.sjava.appstore;
22

3+
import android.content.ActivityNotFoundException;
34
import android.content.Context;
45
import android.content.Intent;
56
import android.net.Uri;
@@ -26,9 +27,12 @@ public boolean isInstalled(Context ctx) {
2627
@Override
2728
public void openApp(Context ctx, String uniqueId) {
2829
if(isInstalled(ctx)) {
29-
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("tstore://PRODUCT_VIEW/" + uniqueId + "/0"));
30-
ctx.startActivity(intent);
31-
return;
30+
try {
31+
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("tstore://PRODUCT_VIEW/" + uniqueId + "/0"));
32+
ctx.startActivity(intent);
33+
return;
34+
} catch (ActivityNotFoundException e) { // ignore
35+
}
3236
}
3337

3438
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(APP_URL + uniqueId));

Library/src/main/java/net/sjava/appstore/PlayAppStore.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.sjava.appstore;
22

3+
import android.content.ActivityNotFoundException;
34
import android.content.Context;
45
import android.content.Intent;
56
import android.net.Uri;
@@ -28,9 +29,12 @@ public boolean isInstalled(Context ctx) {
2829
@Override
2930
public void openApp(Context ctx, String uniqueId) {
3031
if(isInstalled(ctx)) {
31-
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + uniqueId));
32-
ctx.startActivity(intent);
33-
return;
32+
try {
33+
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + uniqueId));
34+
ctx.startActivity(intent);
35+
return;
36+
} catch (ActivityNotFoundException e) { // ignore
37+
}
3438
}
3539

3640
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(APP_URL + uniqueId));
@@ -40,9 +44,12 @@ public void openApp(Context ctx, String uniqueId) {
4044
@Override
4145
public void searchApp(Context ctx, String keyword) {
4246
if(isInstalled(ctx)) {
43-
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q="+ keyword));
44-
ctx.startActivity(intent);
45-
return;
47+
try {
48+
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=" + keyword));
49+
ctx.startActivity(intent);
50+
return;
51+
} catch (ActivityNotFoundException e) { // ignore
52+
}
4653
}
4754

4855
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(APP_SEARCH_URL + keyword));
@@ -52,9 +59,12 @@ public void searchApp(Context ctx, String keyword) {
5259
@Override
5360
public void openPublisherApps(Context ctx, String key) {
5461
if(isInstalled(ctx)) {
55-
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pub:"+ key));
56-
ctx.startActivity(intent);
57-
return;
62+
try {
63+
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pub:" + key));
64+
ctx.startActivity(intent);
65+
return;
66+
} catch (ActivityNotFoundException e) { // ignore
67+
}
5868
}
5969

6070
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(APP_SEARCH_URL + "pub:" + key));

0 commit comments

Comments
 (0)