android (30)


Share Content in Android WebView

Inter-workings JavaScript and Java Layer: use Intent to Share content in html5 Android hybrid app

// no permission require in your manifest file of Android project

        ...

// Open MainActivity Java File of your hybrid Android Project and copy and paste this code

public class MainActivity extends Activity {
public WebView webView;
ClipboardManager myClipboard;

@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 to add in Web App
final class WebAppInterface {
        Context mContext;

        /** Instantiate the interface and set the context */
        WebAppInterface(Context c) {
            mContext = c;
        }
        /**
            Interface to use in web application
        */
        
	@JavascriptInterface
	    public void shareContent(String webdata, String mysubject){
	    	Intent sendIntent = new Intent();
	    	sendIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
	    	sendIntent.putExtra(Intent.EXTRA_SUBJECT, mysubject);
	    	sendIntent.putExtra(Intent.EXTRA_TEXT, webdata);
	    	sendIntent.setType("text/plain");
	    	startActivity(sendIntent);
	    }

}
===============================
// Now open main html file in www sub-folder of assets folder of your Android project and use this code













Clipboard Manager in Android Web View

Inter-workings JavaScript and Java Layer: use Clipboard Manager APIs directly in WebView component of Android library:

// no permission require in your manifest file of Android project

        ...


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

@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 to add in Web App
final class WebAppInterface {
        Context mContext;

        /** Instantiate the interface and set the context */
        WebAppInterface(Context c) {
            mContext = c;
        }
        /**
            Interface to use in web application
        */
        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
	@SuppressLint("NewApi")
	@JavascriptInterface
	    public void copyToClipboard(String text) {
	        try {
	        	myClipboard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
	        	ClipData myClip;
	        	myClip = ClipData.newPlainText("text", text);
	        	myClipboard.setPrimaryClip(myClip);
	        	Toast.makeText(getApplicationContext(), "Text Copied",Toast.LENGTH_SHORT).show();
	        } catch (Exception e) {
	        	Toast.makeText(getApplicationContext(), "Copy failed: " + e.toString(), Toast.LENGTH_SHORT).show();
	        }
	    }
    }

}
// Now open html file in www folder of you Android project












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













SlidingPuzzleUlm

Un puzzle di numeri da riordinare, è questo SlidingPuzzleUlm, stile antico Giappone, per allenare la tua mente e rilassarti durante le tue pause di lavoro o prima di andare a dormire. Puoi scegliere di riordinare i numeri di tre tavole predefinite oppure personalizzarle fino ad un massimo di nove per nove per elevare il livello di difficoltà. Niente banner o pubblicità indesiderata e soprattutto il gioco è completamente gratuito.

Get it on Google Play




Boot to Gecko

Un sistema operativo smartphone progettato interamente in HTML 5.0? Mozzilla è riuscito a compiere questa straordinaria impresa! Mi limito ad annunciarti questo, per il resto parlano le immagini del video che segue sotto per la presentazione dell’open source. Boot to Gecko in action!