diff --git a/android/app/build.gradle b/android/app/build.gradle index 5a6fbe1..abc5234 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -74,6 +74,9 @@ flutter { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + implementation 'com.android.support.constraint:constraint-layout:1.1.3' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index e6f7a9e..db4b2b5 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,46 +1,59 @@ + - + FlutterApplication and put your custom class here. + --> - - + + + - - + + /> + --> - - + + + - + - + + \ No newline at end of file diff --git a/android/app/src/main/java/com/example/aman_kassa_flutter/bank/BankActivity.kt b/android/app/src/main/java/com/example/aman_kassa_flutter/bank/BankActivity.kt new file mode 100644 index 0000000..d1bf682 --- /dev/null +++ b/android/app/src/main/java/com/example/aman_kassa_flutter/bank/BankActivity.kt @@ -0,0 +1,33 @@ +package com.example.aman_kassa_flutter.bank + +import android.app.Activity +import android.content.Intent +import android.os.Bundle +import android.util.Log +import android.view.View +import com.example.aman_kassa_flutter.R +import io.flutter.app.FlutterActivity + + +class BankActivity : FlutterActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + Log.i("BankActivity","onCreate") + setContentView(R.layout.activity_bank) + } + + fun myClickHandler(view: View) { + Log.i("BankActivity","closed") + val returnIntent = Intent() + returnIntent.putExtra("result", "abrakadabra") + setResult(Activity.RESULT_OK, returnIntent) + finish() + } + + override fun onDestroy() { + val returnIntent = Intent() + returnIntent.putExtra("result", "abrakadabra") + setResult(Activity.RESULT_CANCELED, returnIntent) + super.onDestroy() + } +} \ No newline at end of file diff --git a/android/app/src/main/kotlin/com/example/aman_kassa_flutter/MainActivity.kt b/android/app/src/main/kotlin/com/example/aman_kassa_flutter/MainActivity.kt index 95c47d6..4dbc05f 100644 --- a/android/app/src/main/kotlin/com/example/aman_kassa_flutter/MainActivity.kt +++ b/android/app/src/main/kotlin/com/example/aman_kassa_flutter/MainActivity.kt @@ -1,15 +1,10 @@ package com.example.aman_kassa_flutter -import android.content.Context -import android.content.ContextWrapper +import android.app.Activity import android.content.Intent -import android.content.IntentFilter -import android.content.pm.PackageManager -import android.net.Uri -import android.os.BatteryManager -import android.os.Build.VERSION -import android.os.Build.VERSION_CODES import androidx.annotation.NonNull +import com.example.aman_kassa_flutter.bank.BankActivity +import com.example.aman_kassa_flutter.bank.MusicPlugin import io.flutter.embedding.android.FlutterActivity import io.flutter.embedding.engine.FlutterEngine import io.flutter.plugin.common.MethodChannel @@ -17,67 +12,44 @@ import io.flutter.plugins.GeneratedPluginRegistrant class MainActivity: FlutterActivity() { - private val CHANNEL = "samples.flutter.dev/battery" + private val BANK_CHANNEL = "channel:com.amanKassa/bank" + private val ACTIVITY_CHANNEL = "channel:com.amanKassa/activity" + + private lateinit var _result: MethodChannel.Result override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { GeneratedPluginRegistrant.registerWith(flutterEngine); - MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { + MethodChannel(flutterEngine.dartExecutor.binaryMessenger, BANK_CHANNEL).setMethodCallHandler(MusicPlugin()); + MethodChannel(flutterEngine.dartExecutor.binaryMessenger, ACTIVITY_CHANNEL).setMethodCallHandler { // Note: this method is invoked on the main thread. call, result -> - if (call.method == "getBatteryLevel") { - val batteryLevel = getBatteryLevel() - - if (batteryLevel != -1) { - result.success(batteryLevel) - } else { - result.error("UNAVAILABLE", "Battery level not available.", null) - } - } else if (call.method == "sendMessage") { - val batteryLevel = sendMessage() - - if (batteryLevel != -1) { - result.success(batteryLevel) - } else { - result.error("UNAVAILABLE", "Battery level not available.", null) - } + if (call.method == "start") { + _result = result + val intent= Intent(this, BankActivity::class.java) + startActivityForResult(intent, 8989) + //result.success("ActivityStarted") } else { result.notImplemented() } } } - private fun getBatteryLevel(): Int { - val batteryLevel: Int - if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) { - val batteryManager = getSystemService(Context.BATTERY_SERVICE) as BatteryManager - batteryLevel = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY) - } else { - val intent = ContextWrapper(applicationContext).registerReceiver(null, IntentFilter(Intent.ACTION_BATTERY_CHANGED)) - batteryLevel = intent!!.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) * 100 / intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1) + + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + if(requestCode == 8989) { + if (resultCode == Activity.RESULT_OK) { + _result.success(data?.getStringExtra("result")) + } else if (resultCode == Activity.RESULT_CANCELED) { + _result.error("008", "123","aaa") + } else + _result.success(null) } - println("batteryLevel"); - println(batteryLevel); - return batteryLevel + } - private fun sendMessage(): Int { - val packageManager: PackageManager = context.packageManager - val i = Intent(Intent.ACTION_VIEW) - try { - val mobileNo: String = "77774904900" //call.argument("mobileNo") - val message: String = "Hello world" //call.argument("message") - //https://wa.me/919167370647?text=Yes%20We'll%20do%20this%20in%20frag4%20inOCW - println("mobileNo: $mobileNo message: $message") - val url = "https://wa.me/" + mobileNo.trim { it <= ' ' } + "?text=" + message.trim { it <= ' ' } - i.setPackage("com.whatsapp") - i.data = Uri.parse(url) - if (i.resolveActivity(packageManager) != null) { - context.startActivity(i) - } - println("finish method - 2") - } catch (e: Exception) { - e.printStackTrace() - } - return 25 - } + + + } diff --git a/android/app/src/main/res/layout/activity_bank.xml b/android/app/src/main/res/layout/activity_bank.xml new file mode 100644 index 0000000..a4dac4f --- /dev/null +++ b/android/app/src/main/res/layout/activity_bank.xml @@ -0,0 +1,36 @@ + + + + + + + +