jueves, 14 de marzo de 2019

ASP.NET - Hello World

Create your app

In your command prompt, run the following commands:
dotnet new webApp -o myWebApp --no-https
cd myWebApp

What do these commands mean?

The dotnet new command creates a new application.
  • The webApp parameter selects what template to use when creating your app.
  • The -o parameter creates a directory named myWebApp where your app is stored.
  • The --no-https flag specifies not to enable HTTPS.
The cd myWebApp command puts you into the newly created app directory.

What files were created?

Several files were created in the myWebApp directory, to give you a simple web application that is ready to run.
  • Startup.cs contains all the settings and configurations.
  • The myWebApp/Pages directory contains some example web pages for the application.
  • myWebbApp.csproj defines what libraries are referenced etc.

Run your app

In your command prompt, run the following command:
dotnet run
Once the command completes, browse to http://localhost:5000
The home page of your site contains some placeholder content about ASP.NET.
Congratulations, you've built and run your first .NET web app!

https://dotnet.microsoft.com/learn/web/aspnet-hello-world-tutorial/intro

viernes, 8 de febrero de 2019

Esconder la barra de estatus. (Android Studio)


post original .- https://es.stackoverflow.com/questions/187331/c%C3%B3mo-quitar-barra-de-notificaciones


public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Si la versión android es menor que Jellybean, usa este llamado para esconder la barra de estatus.
        if (Build.VERSION.SDK_INT > 16) {
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }

        setContentView(R.layout.activity_main);
       ...
       ...
    }
    ...
}

jueves, 7 de febrero de 2019

@JavascriptInterface and RewardedVideoAd Android Admob

There is an Android mechanism that allows you to run Android function from javascript:
      <input class="button" type="button" value="FREE life" onclick="startRewardVideo('some parameters can be passed to Android from here')">
            <script type="text/javascript">
                function startRewardVideo(paramFromJS) {
                    Android.startRewardVideoAndroidFunction(paramFromJS);
                }
            </script>
now you need class that knows what to do with your javascript:
package fr.bbbb.myapplication;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.WebSettings;
import android.widget.Toast;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.reward.RewardItem;
import com.google.android.gms.ads.reward.RewardedVideoAd;
import com.google.android.gms.ads.reward.RewardedVideoAdListener;
public class MainActivity extends AppCompatActivity implements RewardedVideoAdListener{
    private WebView webView;
    private RewardedVideoAd mRewardedVideoAd;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        webView = (WebView) findViewById(R.id.webview);
        webView.setWebViewClient(new WebViewClient());
        WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(true);
        webView.setWebChromeClient(new WebChromeClient());
        MobileAds.initialize(this"ca-app-pub-3940256099942544~3347511713");
        mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
        mRewardedVideoAd.setRewardedVideoAdListener(this);
        webView.addJavascriptInterface(new MyJavascriptInterface(this) , "Android");
        webView.loadUrl("http://www.bbbb.fr");
        mRewardedVideoAd.loadAd("ca-app-pub-3940256099942544/5224354917"new AdRequest.Builder().build());
    }
  public class MyJavascriptInterface {
        private Context context;
        public MyJavascriptInterface(Context context){
            this.context = context;
        }
        @JavascriptInterface
        public void startRewardVideoAndroidFunction(){
            runOnUiThread(new Runnable() {
                public void run() {
                    if (mRewardedVideoAd.isLoaded()) {
                        mRewardedVideoAd.show();
                    }
                }
            });
        }
    }
    private void loadRewardedVideoAd() {
        mRewardedVideoAd.loadAd("ca-app-pub-8182467776458634/7199599910"new AdRequest.Builder().build());
    }
    @Override
    public void onRewardedVideoAdLeftApplication() {
        Toast.makeText(this"onRewardedVideoAdLeftApplication",Toast.LENGTH_SHORT).show();
    }
    @Override
    public void onRewardedVideoAdClosed() {
        Toast.makeText(this"onRewardedVideoAdClosed", Toast.LENGTH_SHORT).show();
    }
    @Override
    public void onRewardedVideoAdFailedToLoad(int errorCode) {
        Toast.makeText(this"onRewardedVideoAdFailedToLoad", Toast.LENGTH_SHORT).show();
    }
    @Override
    public void onRewardedVideoAdLoaded() {
        Toast.makeText(this"onRewardedVideoAdLoaded", Toast.LENGTH_SHORT).show();
    }
    @Override
    public void onRewardedVideoAdOpened() {
        Toast.makeText(this"onRewardedVideoAdOpened", Toast.LENGTH_SHORT).show();
    }
    @Override
    public void onRewardedVideoStarted() {
        Toast.makeText(this"onRewardedVideoStarted", Toast.LENGTH_SHORT).show();
    }
    @Override
    public void onRewardedVideoCompleted() {
        Toast.makeText(this"onRewardedVideoCompleted", Toast.LENGTH_SHORT).show();
    }
    @Override
    public void onRewarded(RewardItem rewardItem) {
    loadRewardedVideoAd();
    }
}

Here you have full tutorial:
https://stackoverflow.com/questions/48403912/webview-remote-site-and-reward-videos?rq=1
https://openclassrooms.com/forum/sujet/rewarded-video-sur-une-application-webview?page=1