22
33import android .app .Activity ;
44import android .content .Context ;
5+ import android .os .Build ;
6+ import android .util .Log ;
57
68import androidx .annotation .NonNull ;
9+ import androidx .annotation .RequiresApi ;
10+
11+ import java .io .File ;
12+ import java .io .FileWriter ;
13+ import java .io .IOException ;
714import java .util .List ;
815import java .util .Map ;
916import io .flutter .plugin .common .MethodCall ;
@@ -25,6 +32,7 @@ void setActivity(Activity activity) {
2532 this .activity = activity ;
2633 }
2734
35+ @ RequiresApi (api = Build .VERSION_CODES .KITKAT )
2836 @ Override
2937 public void onMethodCall (@ NonNull MethodCall call , @ NonNull MethodChannel .Result result ) {
3038
@@ -38,8 +46,50 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
3846 }
3947 }
4048
49+ @ RequiresApi (api = Build .VERSION_CODES .KITKAT )
4150 private void initialize (MethodCall call ) {
4251 List <Map <String , String >> args = call .arguments ();
4352 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+
4493 }
45- }
94+
95+
0 commit comments