Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android studio 颤振法_Android Studio_Kotlin_Smsmanager - Fatal编程技术网

Android studio 颤振法

Android studio 颤振法,android-studio,kotlin,smsmanager,Android Studio,Kotlin,Smsmanager,我在颤振中实现了一个方法通道,使用默认的消息传递应用程序发送文本消息,但它不起作用。Rest所有程序流工作正常,只是没有发送消息。首先,它试图发送消息,但在设备消息应用程序中获得失败状态,现在它什么也不做。相反,我在Android Studio中从频道返回节目流后收到此消息 V/PhoneWindow(5722):DecorView设置可见性:可见性=0,父级=android.view。ViewRootImpl@76c918b,这=DecorView@a148268[主要活动] 我刚开始学习颤振

我在颤振中实现了一个方法通道,使用默认的消息传递应用程序发送文本消息,但它不起作用。Rest所有程序流工作正常,只是没有发送消息。首先,它试图发送消息,但在设备消息应用程序中获得失败状态,现在它什么也不做。相反,我在Android Studio中从频道返回节目流后收到此消息

V/PhoneWindow(5722):DecorView设置可见性:可见性=0,父级=android.view。ViewRootImpl@76c918b,这=DecorView@a148268[主要活动]

我刚开始学习颤振和科特林 我正在Xiomi Redmi 6A,API 28上测试这段代码

import androidx.annotation.NonNull
import android.Manifest
import android.view.View
import android.telephony.SmsManager
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel

class MainActivity: FlutterActivity() {

      private val channel  = "com.myReflectionThoughts/sendConfirmation";

     override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine){
        super.configureFlutterEngine(flutterEngine)

    MethodChannel(flutterEngine.dartExecutor.binaryMessenger,channel).setMethodCallHandler{
        call,result->
        val arguments = call.arguments<Map<String,Any>>()
        if(call.method == "sendConfirmation"){
        var confirmationMessage = "Your Order has been Accepted !!\n"+"TOD:- "+arguments["Tod"]+" ,Amount:- \u20B9"+arguments["amount"]+" ,Address:- "+arguments["address"]
        requestPermissions(arrayOf(Manifest.permission.SEND_SMS),10)

            val smsManager = SmsManager.getDefault()
            smsManager.sendTextMessage(arguments["contact"].toString(),null,confirmationMessage,null,null)
            result.success("Confirmation Sent!!")
        }
        else{
            result.error("Pta nahi","Kuch galat ho gya",null)
        }
    }
    }
}
import androidx.annotation.NonNull
导入android.Manifest
导入android.view.view
导入android.telephony.smsmsmanager
导入io.flatter.embedding.android.flatterActivity
导入io.flatter.embedding.engine.flatterengine
导入io.flatter.plugin.common.MethodChannel
类MainActivity:activity(){
private val channel=“com.myreflectionthroughts/sendConfirmation”;
覆盖fun配置颤振引擎(@NonNull颤振引擎:颤振引擎){
超级配置颤振引擎(颤振引擎)
MethodChannel(FlatterEngine.dartExecutor.binaryMessenger,channel).setMethodCallHandler{
呼叫,结果->
val arguments=call.arguments()
if(call.method==“发送确认”){
var confirmationMessage=“您的订单已被接受!!\n”+“TOD:-”+参数[“TOD”]+,金额:-\u20B9”+参数[“金额”]+,地址:-“+参数[“地址”]
requestPermissions(arrayOf(Manifest.permission.SEND_SMS),10)
val smsmsmanager=smsmsmanager.getDefault()
smsManager.sendTextMessage(参数[“contact”].toString(),null,confirmationMessage,null,null)
结果.成功(“发送确认!!”)
}
否则{
结果.错误(“Pta nahi”,“Kuch galat ho gya”,空)
}
}
}
}
这是我从中调用MEthodChannel的dart文件

class SwipeOrderTile extends StatefulWidget {
  @override
  _SwipeOrderTileState createState() => _SwipeOrderTileState();
}

class _SwipeOrderTileState extends State<SwipeOrderTile> {
  // bool to check if we need to see the order delivery
  bool _showOrderDetails = false;
  Order ord;
  static const platformchannel =
  MethodChannel("com.myReflectionThoughts/sendConfirmation");

  Widget createCustomContainer(dynamic child) {
    return Container(
        margin: EdgeInsets.all(2),
        padding: EdgeInsets.all(2),
        height: 25,
        width: double.infinity,
        child: child);
  }



  @override
  Widget build(BuildContext context) {
    final order = Provider.of<Order>(context);
    ord = order;

    return Dismissible(
      key: ValueKey(order.orderId),
      dismissThresholds: {DismissDirection.endToStart: 0.40},
      confirmDismiss: (direction) {
        if (direction == DismissDirection.endToStart)
          // Code To Remove this Order
          return showDialog(
              context: context,
              builder: (ctx) {
                return AlertDialog(
                  title: Text(
                    '!! Confirm Action !!',
                    style: TextStyle(fontWeight: FontWeight.bold),
                    textAlign: TextAlign.center,
                  ),
                  contentPadding: const EdgeInsets.all(4),
                  content: Text(
                    'Accept this Order ?',
                    style: TextStyle(
                      fontWeight: FontWeight.bold,
                    ),
                    textAlign: TextAlign.center,
                  ),
                  actions: [
                    FlatButton(
                        child: Text('Yes',
                            style: TextStyle(fontWeight: FontWeight.bold)),
                        onPressed: () async {
                          try {
                            Navigator.of(context).pop(false);

                            final dataMap = <String, dynamic>{
                              'Tod': order.timeOfDelivery,
                              'amount': order.amount,
                              'address': order.address,
                              'contactNumber': order.contact
                            };
                         final response = await platformchannel.invokeMethod("sendConfirmation", dataMap);
                             print(response + " DartFile");
                           await Provider.of<RestaurantManager>(context,
                            listen: false)
                            .setOrderStatus(order.serverId, true);
                          } catch (error) {
                            print(error.toString());
                            print("Error Occured while Sending Message");
                          }
                        }),
                    FlatButton(
                      child: Text('NO',
                          style: TextStyle(fontWeight: FontWeight.bold)),
                      onPressed: () {
                        Navigator.of(context).pop(false);
                      },
                    )
                  ],
                );
              });
        else {
          return showDialog(
              context: context,
              builder: (ctx) {
                return AlertDialog(
                  title: Text(
                    '!! Confirm Action !!',
                    textAlign: TextAlign.center,
                  ),
                  contentPadding: const EdgeInsets.all(4),
                  content: Text(
                    'Decline this Order ?',
                    textAlign: TextAlign.center,
                  ),
                  actions: [
                    FlatButton(
                        child: Text('Yes'),
                        onPressed: () {
                          Navigator.of(context).pop(true);
                          Provider.of<RestaurantManager>(context, listen: false)
                              .setOrderStatus(order.serverId, false);
                        }),
                    FlatButton(
                      child: Text('NO'),
                      onPressed: () {
                        Navigator.of(context).pop(false);
                      },
                    )
                  ],
                );
              });
        }
      },

 
类SwipeOrderTile扩展StatefulWidget{
@凌驾
_SwipeOrderItemState createState()=>\u SwipeOrderItemState();
}
类_SwipeOrderTileState扩展状态{
//bool检查我们是否需要查看订单交付情况
bool\u showOrderDetails=false;
命令命令;
静态常数平台通道=
MethodChannel(“com.myReflectionThroughts/sendConfirmation”);
小部件createCustomContainer(动态子项){
返回容器(
保证金:所有(2),
填充:边缘设置。全部(2),
身高:25,
宽度:double.infinity,
儿童:儿童);
}
@凌驾
小部件构建(构建上下文){
最终订单=提供者(上下文);
ord=订单;
可驳回的回报(
key:ValueKey(order.orderId),
dismissThresholds:{DismissDirection.endToStart:0.40},
确认人:(指示){
if(direction==DismissDirection.endToStart)
//删除此订单的代码
返回显示对话框(
上下文:上下文,
建造商:(ctx){
返回警报对话框(
标题:正文(
“!!确认操作!!”,
样式:TextStyle(fontWeight:fontWeight.bold),
textAlign:textAlign.center,
),
contentPadding:const EdgeInsets.all(4),
内容:文本(
“接受这个订单吗?”,
样式:TextStyle(
fontWeight:fontWeight.bold,
),
textAlign:textAlign.center,
),
行动:[
扁平按钮(
子项:文本('是',
样式:TextStyle(fontWeight:fontWeight.bold)),
onPressed:()异步{
试一试{
Navigator.of(context.pop)(false);
最终数据映射={
“Tod”:order.timeOfDelivery,
“金额”:order.amount,
“地址”:order.address,
“联系人号码”:order.contact
};
最终响应=等待平台通道.invokeMethod(“发送确认”,数据映射);
打印(响应+DartFile);
等待(上下文)的提供者,
听:错)
.setOrderStatus(order.serverId,true);
}捕获(错误){
打印(error.toString());
打印(“发送消息时出错”);
}
}),
扁平按钮(
子:文本('否',
样式:TextStyle(fontWeight:fontWeight.bold)),
已按下:(){
Navigator.of(context.pop)(false);
},
)
],
);
});
否则{
返回显示对话框(
上下文:上下文,
建造商:(ctx){
返回警报对话框(
标题:正文(
“!!确认操作!!”,
textAlign:textAlign.center,
),
contentPadding:const EdgeInsets.all(4),
内容:文本(
“拒绝这个订单?”,
textAlign:textAlign.center,
),
行动:[
扁平按钮(
子项:文本('Yes'),
已按下:(){
Navigator.of(context.pop)(true);
Provider.of(上下文,侦听:false)