2
2
3
3
import android .app .Activity ;
4
4
import android .content .Context ;
5
+ import android .os .Build ;
6
+ import android .util .Log ;
5
7
6
8
import androidx .annotation .NonNull ;
9
+ import androidx .annotation .RequiresApi ;
10
+
11
+ import java .io .File ;
12
+ import java .io .FileWriter ;
13
+ import java .io .IOException ;
7
14
import java .util .List ;
8
15
import java .util .Map ;
9
16
import io .flutter .plugin .common .MethodCall ;
@@ -25,6 +32,7 @@ void setActivity(Activity activity) {
25
32
this .activity = activity ;
26
33
}
27
34
35
+ @ RequiresApi (api = Build .VERSION_CODES .KITKAT )
28
36
@ Override
29
37
public void onMethodCall (@ NonNull MethodCall call , @ NonNull MethodChannel .Result result ) {
30
38
@@ -38,8 +46,50 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
38
46
}
39
47
}
40
48
49
+ @ RequiresApi (api = Build .VERSION_CODES .KITKAT )
41
50
private void initialize (MethodCall call ) {
42
51
List <Map <String , String >> args = call .arguments ();
43
52
final int numberOfIcons = args .size ();
53
+ for (Map <String ,String > arg : args ){
54
+ Log .d (TAG , "=====================>initialize: " );
55
+ String className = arg .get ("className" );
56
+ File file = new File (className +".java" );
57
+ try {
58
+ Log .d (TAG , "=====================>1st try: " );
59
+ file .createNewFile ();
60
+ } catch (IOException e ) {
61
+ e .printStackTrace ();
62
+ }
63
+ if (file .exists ()) {
64
+ // Returning the file name
65
+ System .out .println ("File name: " + file .getName ());
66
+
67
+ // Returning the path of the file
68
+ System .out .println ("Absolute path: " + file .getAbsolutePath ());
69
+
70
+ // Displaying whether the file is writable
71
+ System .out .println ("Writeable: " + file .canWrite ());
72
+
73
+ // Displaying whether the file is readable or not
74
+ System .out .println ("Readable " + file .canRead ());
75
+
76
+ // Returning the length of the file in bytes
77
+ System .out .println ("File size in bytes " + file .length ());
78
+ } else {
79
+ System .out .println ("The file does not exist." );
80
+ }
81
+ try {
82
+ Log .d (TAG , "=====================>2nd try: " );
83
+ FileWriter writeFile = new FileWriter (className +".java" );
84
+ writeFile .write ("package \" com.hackthedeveloper.live_icon\" ;" );
85
+ writeFile .write (System .lineSeparator ());
86
+ writeFile .write ("class " +className +"{}" );
87
+ } catch (IOException e ) {
88
+ e .printStackTrace ();
89
+ }
90
+ }
91
+ }
92
+
44
93
}
45
- }
94
+
95
+
0 commit comments