html5 (33)


WebRTC demo

Tutorial to use PeerJS HTML5 webrtc technology




html5 canvas

base64 data to html5 canvas in pure javascript with filesystem API




Send SMS message in Android HybridApp HTML5

Another useful snippet HTML5 hybrid app for Android, using the method addJavascriptInterface to send sms:

// sms permission in your manifest file of Android project

    
    ...


// start code
@SuppressLint({"SetJavaScriptEnabled","JavascriptInterface"})
public class MainActivity extends Activity {
public WebView webView;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main); // source activity_main.xml
webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(new WebAppInterface(this), "Android");
webView.setWebViewClient(new WebViewClient());
// important set Web Chrome Client
webView.setWebChromeClient(new WebChromeClient());
webView.loadUrl(url); //local or remote
}
// final class for save and write file in external storage
final class WebAppInterface {
        Context mContext;

        /** Instantiate the interface and set the context */
        WebAppInterface(Context c) {
            mContext = c;
        }
        /**
            Built-in SMS application
        */
        public void sendBSMS(String contentsms, String tag) {
            try {
               Intent sendIntent = new Intent(Intent.ACTION_VIEW);
	       sendIntent.putExtra("sms_body", contentsms); 
	       sendIntent.setType("vnd.android-dir/mms-sms");
	       startActivity(sendIntent);
            }
            catch (IOException e) {
                Log.e(tag, "Action failed: " + e.toString());
            }
        }
        /**
         *Send with SmsManager API
         */
        public void sendSMSM(String phoneNo, String contentsms, String tag) {
            try {
               SmsManager smsManager = SmsManager.getDefault();
	       smsManager.sendTextMessage(phoneNo, null, contentsms, null, null);
            }
            catch (IOException e) {
                Log.e(tag, "SMS failed: " + e.toString());
            }
        }
    }

}
// Now open html file in www folder





 *
optional *










Add Javascript Interface Android Write File

A useful snippet HTML5 hybrid app for Android, using the method addJavascriptInterface to save and write file in external storage:

// write storage permission in your manifest file of Android project

    
    ...


// start code
@SuppressLint({"SetJavaScriptEnabled","JavascriptInterface"})
public class MainActivity extends Activity {
public WebView webView;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main); // source activity_main.xml
webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(new WebAppInterface(this), "Android");
webView.setWebViewClient(new WebViewClient());
// important set Web Chrome Client
webView.setWebChromeClient(new WebChromeClient());
webView.loadUrl(url); //local or remote
}
// final class for save and write file in external storage
final class WebAppInterface {
        Context mContext;

        /** Instantiate the interface and set the context */
        WebAppInterface(Context c) {
            mContext = c;
        }
        public void writeToFile(String data, String filename, String tag) {
            try {
                File root = android.os.Environment.getExternalStorageDirectory();
                File dir = new File (root.getAbsolutePath() + "/foldercustom");
                dir.mkdirs();
                File file = new File(dir, filename);
                FileOutputStream f = new FileOutputStream(file);
                PrintWriter pw = new PrintWriter(f);
                pw.println(data);
                pw.flush();
                pw.close();
                f.close();
            }
            catch (IOException e) {
                Log.e(tag, "File write failed: " + e.toString());
            }
        }
    }

}
// Now open html file in www folder













NewUlmDesign web site

Desidero informarti che ho pubblicato il mio nuovo sito – NewUlmDesign con i dettagli che riguardano le mie competenze sia come Front-end developer nonché come esperto SEO e web application developer. Infine nel medesimo sito sono disponibili link e approfondimenti sull’impiego di nuove tecnologie per la progettazione di applicazioni web client e web server e app per i più diffusi dispositivi mobile. Se ti occorre un professionista con una consolidata esperienza nel settore, bene, sei giunto al posto giusto nel momento più appropriato: sono disponibile per una consulenza immediata.