Jumat, 07 Desember 2018

Play Audio Video from Url use WebView with String HTML Android Studio

assalamu'alaikum,,

today I want to give you a way to make a audioview and videoview on a webview by using html code. and run on an android application.

first of all create xml code such as the following

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    <WebView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/wView"
        android:layout_alignParentTop="true"/>
    <WebView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/web"
        android:layout_alignParentBottom="true"/>
</RelativeLayout>

than the activity code
public class MainActivity extends AppCompatActivity {
    WebView w;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        webAudio();
        webVideo();
    }
    private void webVideo() {
        w=findViewById(R.id.web);
        String about=
                "<html>\n"+
                "<body>\n" +
                "\t<h6>PLAY</h6>\n" +
                "\t<br>\n" +
                "<audio " +
                "class=\"audio\" style=\"width: 100%;display: 
                 block;height: auto !important;padding-bottom:0;\""+
                "controls=\"\" autoplay=\"\" name=\"media\">" +
                "<source src=\"http://ia800303.us.archive.org/5/items/
                 Nasser_Al_Qatami_1433/001.mp3\" " +
                "type=\"audio/mpeg\">" +
                "</audio>" +
                "</body>" +
                "</html>";
        TypedArray ta = obtainStyledAttributes(new int[]{
          android.R.attr.textColorPrimary, R.attr.colorAccent});
        String textColor = String.format("#%06X", 
          (0xFFFFFF & ta.getColor(1, Color.WHITE)));
        String accentColor = String.format("#%06X",
          (0xFFFFFF & ta.getColor(9, Color.BLUE)));
        ta.recycle();        about = "<style media=\"screen\" type=\"text/css\">" +
                "body {\n" +
                "    color:" + textColor + ";\n" +
                "}\n" +
                "a:link {color:" + accentColor + "}\n" +
                "</style>" + about;
        w.setBackgroundColor(Color.TRANSPARENT);
        w.getSettings().setJavaScriptEnabled(true);
        w.setWebViewClient(new MyWebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String Url) {
                return super.shouldOverrideUrlLoading(view, Url);            }
        });        w.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
        w.getSettings().setAppCacheEnabled(true);
        w.getSettings().setDomStorageEnabled(true);
        w.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        w.getSettings().setUseWideViewPort(true);
        w.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        w.getSettings().setAllowUniversalAccessFromFileURLs(true);
        w.setFocusable(true);
        w.setScrollBarStyle(w.SCROLLBARS_OUTSIDE_OVERLAY);
        w.getSettings().getLoadWithOverviewMode();
        w.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
        w.getSettings().setDisplayZoomControls(true);
        w.getSettings().setDatabaseEnabled(true);
        w.loadData(about, "text/html", "UTF-8");    }

    private void webAudio() {
        w=findViewById(R.id.wView);
        String about=
                "<html>\n"+
                        "<body>\n" +
                        "\t<h6>PLAY</h6>\n" +
                        "\t<br>\n" +
                        "<video " +
                        "class=\"audio\" style=\"width: 100%;display:
                         block;height: auto !important;padding-bottom:0;\""+
                        "controls=\"\" autoplay=\"\" name=\"media\">" +
                        "<source src=\"https://video-sin2-1.xx.fbcdn.net/v/
t42.9040-2/47361555_329233531223948_8855508624823287808_n.mp4?_nc_cat=101&efg
=eyJ2ZW5jb2RlX3RhZyI6InN2ZV9zZCJ9&_nc_eui2=AeEy4GY9rb-95uGjFGIzUN4JyspjZXXSZmIYckXnfBSr8
_gcAiVkBnotSV45_x5vKQq0e5cNTMZj3h09ThpJcht61mWz6Cl_FiUOH3bhZWKjtw&_nc_ht=video-sin2-1
.xx&oh=3920f3369cfeb0be6c3db27d3eddb96d&oe=5C0A1194\" " +
                        "type=\"audio/mpeg\">" +
                        "</video>" +
                        "</body>" +
                        "</html>";
        TypedArray ta = obtainStyledAttributes(new int[]
          {android.R.attr.textColorPrimary, R.attr.colorAccent});
        String textColor = String.format("#%06X",
          (0xFFFFFF & ta.getColor(1, Color.WHITE)));
        String accentColor = String.format("#%06X",
          (0xFFFFFF & ta.getColor(9, Color.BLUE)));
        ta.recycle();        about = "<style media=\"screen\" type=\"text/css\">" +
                "body {\n" +
                "    color:" + textColor + ";\n" +
                "}\n" +
                "a:link {color:" + accentColor + "}\n" +
                "</style>" + about;
        w.setBackgroundColor(Color.TRANSPARENT);
        w.getSettings().setJavaScriptEnabled(true);
        w.setWebViewClient(new MyWebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String Url){
                return super.shouldOverrideUrlLoading(view, Url);
            }
        });
        w.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
        w.getSettings().setAppCacheEnabled(true);
        w.getSettings().setDomStorageEnabled(true);
        w.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        w.getSettings().setUseWideViewPort(true);
        w.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        w.getSettings().setAllowUniversalAccessFromFileURLs(true);
        w.setFocusable(true);
        w.setScrollBarStyle(w.SCROLLBARS_OUTSIDE_OVERLAY);
        w.getSettings().getLoadWithOverviewMode();
        w.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
        w.getSettings().setDisplayZoomControls(true);
        w.getSettings().setDatabaseEnabled(true);
        w.loadData(about, "text/html", "UTF-8");    }
}

may be you find some error message
how to overcome it..?
lets go create a new class.
by clicking on the word in red. like this MyWebViewClient()  place the cursor on the word red. then Alt + Enter create a new class
and create code such as the following
public class MyWebViewClient extends WebViewClient {
    @Override    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if(Uri.parse(url).getHost().endsWith
     ("http://ia800303.us.archive.org/5/items/Nasser_Al_Qatami_1433/001.mp3")){
            return false;        }
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        view.getContext().startActivity(intent);
        return true;    }
}

oke may be useful..

Minggu, 02 Desember 2018

Acces WhatsApp Chat from your Aplication

Assalamu'alaikum. sobat
the first time we think about when we want to access another application is of course the API

and are there ways other than API
the answer is there. because he is an application in the same device. certainly can be connected by using Package

this time I will provide a way to access Personal Chat whatsapp from other applications that you created yourself with two methods, namely the API method and the Package method

#first with API

private void openWhatsApp(){
        Uri uri = Uri.parse
            ("https://api.whatsapp.com/send?phone=60138811227&text=hai saya lupa ini siapa");
        try{
            Intent i =new Intent(Intent.ACTION_VIEW,uri);
            startActivity(i);
        }catch (Exception e){
            Toast.makeText(this,"Silahkan Download Aplikasi terlebih 
            dahulu",Toast.LENGTH_LONG).show();
        }
    }


second with Package

 private void openWhatsapp2(){
        String smsNumber = "971556847589";
        boolean isWhatsappInstalled = whatsappInstalledornot("com.whatsapp");
        if (isWhatsappInstalled) {
            Intent sendIntent = new Intent("android.intent.action.MAIN");
            sendIntent.setComponent(new ComponentName
            ("com.whatsapp", "com.whatsapp.Conversation"));
            sendIntent.putExtra
            ("jid", PhoneNumberUtils.stripSeparators(smsNumber) + "@s.whatsapp.net");
            //phone number without "+" prefix
            startActivity(sendIntent);
        } else {
            Uri uri = Uri.parse("market://details?id=com.whatsapp");
            Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
            Toast.makeText(this, "WhatsApp not Installed",
                    Toast.LENGTH_SHORT).show();
            startActivity(goToMarket);
        }
    }

    private boolean whatsappInstalledornot(String uri){
        PackageManager pm=getPackageManager();
        boolean appinstall=false;
        try{
            pm.getPackageInfo(uri,PackageManager.GET_ACTIVITIES);
            appinstall=true;
        } catch (PackageManager.NameNotFoundException e) {
            appinstall=true;
        }
        return appinstall;
    }




how to update playonlinux? || bagaimana update playonlinux di linux mint

open terminal wget -q "http://deb.playonlinux.com/public.gpg" -O - | sudo apt-key add - sudo wget http://deb.playonlinux.com/pla...