-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8de7429
commit 694c20e
Showing
2 changed files
with
64 additions
and
32 deletions.
There are no files selected for viewing
69 changes: 38 additions & 31 deletions
69
android/app/src/main/kotlin/com/example/mdeditor/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,45 @@ | ||
package com.deathblade666.mdeditor | ||
|
||
//import io.flutter.embedding.android.FlutterActivity | ||
|
||
//class MainActivity: FlutterActivity() | ||
|
||
import android.content.Intent; | ||
import android.net.Uri; | ||
import android.os.Bundle; | ||
import io.flutter.embedding.android.FlutterActivity; | ||
import io.flutter.plugin.common.MethodChannel; | ||
|
||
public class MainActivity extends FlutterActivity { | ||
private static final String CHANNEL = "markdown editor"; | ||
import io.flutter.embedding.android.FlutterActivity | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.annotation.NonNull | ||
import io.flutter.embedding.engine.FlutterEngine | ||
import io.flutter.plugin.common.MethodChannel | ||
import io.flutter.plugins.GeneratedPluginRegistrant | ||
import java.io.File | ||
|
||
class MainActivity: FlutterActivity() { | ||
private val CHANNEL = "Markdown_Editor_Channel" | ||
|
||
var openPath: String? = null | ||
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { | ||
GeneratedPluginRegistrant.registerWith(flutterEngine) | ||
val channel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL) | ||
channel.setMethodCallHandler { call, result -> | ||
when (call.method) { | ||
"getOpenFileUrl" -> { | ||
result.success(openPath) | ||
} | ||
else -> result.notImplemented() | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
handleOpenFileUrl(intent) | ||
} | ||
|
||
new MethodChannel(getFlutterEngine().getDartExecutor().getBinaryMessenger(), CHANNEL) | ||
.setMethodCallHandler((call, result) -> { | ||
if (call.method.equals("getFileUri")) { | ||
Intent intent = getIntent(); | ||
String action = intent.getAction(); | ||
Uri data = intent.getData(); | ||
override fun onNewIntent(intent: Intent) { | ||
super.onNewIntent(intent) | ||
handleOpenFileUrl(intent) | ||
} | ||
|
||
if (Intent.ACTION_VIEW.equals(action) && data != null) { | ||
result.success(data.toString()); | ||
} else { | ||
result.error("UNAVAILABLE", "File URI not available.", null); | ||
} | ||
} else { | ||
result.notImplemented(); | ||
} | ||
}); | ||
private fun handleOpenFileUrl(intent: Intent?) { | ||
val path = intent?.data?.path | ||
if (path != null) { | ||
openPath = path | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters