Toast通知不起作用

时间:2015-09-19 13:28:24

标签: c# android xamarin

我写了一些代码,检查互联网连接的可用性,但它没有用。

我没有看到任何干杯通知。我在清单文件中写了所有权限。

此代码中有什么问题?

function uploadPics() {
    console.log("Ok, going to upload "+images.length+" images.");
    var defs = [];

    images.forEach(function(i) {
        console.log('processing '+i);
        var def = $.Deferred();

        function win(r) {
            console.log("thing done");
            if($.trim(r.response) === "0") {
                console.log("this one failed");
                def.resolve(0);
            } else {
                console.log("this one passed");
                def.resolve(1);
            }
        }

        function fail(error) {
            console.log("upload error source " + error.source);
            console.log("upload error target " + error.target);
            def.resolve(0);
        }

        var uri = encodeURI("http://localhost/testingzone/test.cfm");

        var options = new FileUploadOptions();
        options.fileKey="file";
        options.fileName=i.substr(i.lastIndexOf('/')+1);
        options.mimeType="image/jpeg";

        var ft = new FileTransfer();
        ft.upload(i, uri, win, fail, options);
        defs.push(def.promise());

    });

    $.when.apply($, defs).then(function() {
        console.log("all things done");
        console.dir(arguments);
    });

}

1 个答案:

答案 0 :(得分:0)

  

此代码中有什么问题?

您没有在任何地方调用您的方法,因此它永远不会显示Toast,因为该方法从不调用。

  

如何解决?

例如,如果要在启动Activity时检查连接,只需按以下方式添加此方法:

 protected override void OnCreate (Bundle bundle)
{
    base.OnCreate (bundle);

    // Set our view from the "main" layout resource
    SetContentView (Resource.Layout.Main);
    ImageButton next = FindViewById<ImageButton> (Resource.Id.nextButton);
    ImageButton previous = FindViewById<ImageButton> (Resource.Id.previousButton);
    ImageButton home = FindViewById<ImageButton> (Resource.Id.homeButton);
    ImageButton cart = FindViewById<ImageButton> (Resource.Id.cartButton);
    Button sushi = FindViewById<Button> (Resource.Id.sushiButton);
    Button sets = FindViewById<Button> (Resource.Id.setsbutton);
    //Button rolli = FindViewById<Button>(Resource.Id.rollibutton);
    ImageButton menu = FindViewById<ImageButton> (Resource.Id.menuButton);


    CheckNetwork(); //Here you'll ask if you have connection or not and Toast will show