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;
    }




Tidak ada komentar:

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...