Skip to content

Commit 09e5732

Browse files
committed
File Handling Implemented
1 parent c424a3d commit 09e5732

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

android/src/main/java/com/hackthedeveloper/live_icon/LiveIconPlugin.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
public class LiveIconPlugin implements FlutterPlugin, ActivityAware {
1515
private static final String CHANNEL_ID = "com.hackthedeveloper.live_icon";
16-
private static final String TAG = "[Flutter Shortcuts]";
16+
private static final String TAG = "[flutter_live_icon]";
1717

1818
public static String getTAG() {
1919
return TAG;

android/src/main/java/com/hackthedeveloper/live_icon/MethodCallImplementation.java

+51-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@
22

33
import android.app.Activity;
44
import android.content.Context;
5+
import android.os.Build;
6+
import android.util.Log;
57

68
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;
714
import java.util.List;
815
import java.util.Map;
916
import 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+

lib/live_icon.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import './src/helper/helper.dart';
66
export './src/helper/helper.dart';
77

88
class LiveIcon {
9-
static const MethodChannel _channel = const MethodChannel('live_icon');
9+
static const MethodChannel _channel =
10+
const MethodChannel('com.hackthedeveloper.live_icon');
1011

1112
Future<void> initialize({List<LiveIconData> icons}) async {
1213
List<Map<String, String>> iconData = _serializeLiveIconData(icons);

0 commit comments

Comments
 (0)