@@ -15,58 +15,41 @@ public void installAPK(String path) {
15
15
startActivity (intent );
16
16
}
17
17
18
- public void downloadAPK (String url ) {
19
- // BAD: the url is not checked
20
- Intent intent = new Intent (Intent .ACTION_VIEW );
21
- intent .setDataAndType (Uri .parse (url ), "application/vnd.android.package-archive" );
22
- startActivity (intent );
23
- }
24
-
25
- public void installAPK2 () {
26
- String path = "file:///sdcard/Download/MyApp.apk" ;
27
- Intent intent = new Intent (Intent .ACTION_VIEW );
28
- intent .setType ("application/vnd.android.package-archive" );
29
- intent .setData (Uri .parse (path ));
30
- startActivity (intent );
31
- }
32
-
33
18
public void installAPK3 (String path ) {
34
19
Intent intent = new Intent (Intent .ACTION_VIEW );
35
20
intent .setType (APK_MIMETYPE );
21
+ // BAD: the path is not checked
36
22
intent .setData (Uri .fromFile (new File (path )));
37
23
startActivity (intent );
38
24
}
39
25
40
- public void installAPK4 (String path ) {
26
+ public void installAPKFromExternalStorage (String path ) {
27
+ // BAD: file is from external storage
41
28
File file = new File (Environment .getExternalStorageDirectory (), path );
42
29
Intent intent = new Intent (Intent .ACTION_VIEW );
43
30
intent .setDataAndType (Uri .fromFile (file ), APK_MIMETYPE );
44
31
startActivity (intent );
45
32
}
46
33
47
- public void installAPK5 (String path ) {
34
+ public void installAPKFromExternalStorageWithActionInstallPackage (String path ) {
35
+ // BAD: file is from external storage
48
36
File file = new File (Environment .getExternalStorageDirectory (), path );
49
37
Intent intent = new Intent (Intent .ACTION_INSTALL_PACKAGE );
50
38
intent .setData (Uri .fromFile (file ));
51
39
startActivity (intent );
52
40
}
53
41
54
- public void installAPK6 (String path ) {
42
+ public void installAPKInstallPackageLiteral (String path ) {
55
43
File file = new File (Environment .getExternalStorageDirectory (), path );
56
44
Intent intent = new Intent ("android.intent.action.INSTALL_PACKAGE" );
57
45
intent .setData (Uri .fromFile (file ));
58
46
startActivity (intent );
59
47
}
60
48
61
- public void openWebsite () {
62
- Intent intent = new Intent (Intent .ACTION_VIEW );
63
- intent .setData (Uri .parse ("http://www.example.com" ));
64
- startActivity (intent );
65
- }
66
-
67
49
public void otherIntent (File file ) {
68
50
Intent intent = new Intent (this , OtherActivity .class );
69
51
intent .setAction (Intent .ACTION_VIEW );
52
+ // BAD: the file is from unknown source
70
53
intent .setData (Uri .fromFile (file ));
71
54
}
72
55
}
0 commit comments