Thursday, 18 December 2014

how to Creating SOAP Parsar in android example


/** Call this Method **/
WebserviceCall com = new WebserviceCall();
SoapResponse = com.getConvertedWeight("enter your method name");

/** Creating SOAP Parsar Method **/
    class WebserviceCall {
        /** Variable Decleration **/

        String namespace = "http://testing.org/";
        private String url = "http://testing/demo/details.asmx";
        String SOAP_ACTION;
        SoapObject request = null, objMessages = null;
        SoapSerializationEnvelope envelope;       
        AndroidHttpTransport androidHttpTransport;
        WebserviceCall() {
        }
        /** Set Envelope */       
        protected void SetEnvelope() {
            try {
                // Creating SOAP envelope
                envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                // You can comment that line if your web service is not .NET
                // one.
                envelope.dotNet = true;
                envelope.setOutputSoapObject(request);
                androidHttpTransport = new AndroidHttpTransport(url);
                androidHttpTransport.debug = true;
            } catch (Exception e) {
                System.out.println("Soap Exception---->" + e.toString());
            }
        }

        // MethodName variable is define for which webservice function will call
        public String getConvertedWeight(String MethodName) {

            try {
                SOAP_ACTION = namespace + MethodName;
                // Adding values to request object
                request = new SoapObject(namespace, MethodName);
                // Adding Double value to request object
                    PropertyInfo weightProp = new PropertyInfo();
                    weightProp.setName("id");
                    weightProp.setValue(0);
                    weightProp.setType(int.class);
                    request.addProperty(weightProp);
                    request.addProperty("Username", "testing");
                    request.addProperty("Password", "1234567");
                 }             
                SetEnvelope();

                try {
                    // SOAP calling webservice
                    androidHttpTransport.call(SOAP_ACTION, envelope);
                    // Got Webservice response
                    String result = envelope.getResponse().toString();
                   
                    System.out.println("result----->"+result);
                  return result;

                } catch (Exception e) {
                    // TODO: handle exception
                    return e.toString();
                }
            } catch (Exception e) {
                // TODO: handle exception
                return e.toString();
            }

        }
    }


 Note :
//download jar file for soap parsar
Name for jar file -ksoap2-android-assembly-2.5.8-jar-with-dependencies

simple call Intent in android


Intent callIntent = new Intent(Intent.ACTION_CALL);                    callIntent.setData(Uri.parse("tel:"+"1234567890");
startActivity(callIntent);

simple email Intent in android



Intent email = new Intent(Intent.ACTION_SEND);
                email.putExtra(Intent.EXTRA_EMAIL,new String[] { test@gmail.com });
                email.putExtra(Intent.EXTRA_SUBJECT, "subject");
                email.putExtra(Intent.EXTRA_TEXT, "message");
                email.setType("message/rfc822");
                startActivity(Intent.createChooser(email,"Choose an Email client :"));

Skype Intent in android


initiateSkypeUri(context, " ");

//****************************************************************
public void initiateSkypeUri(Context myContext, String mySkypeUri) {

          // Make sure the Skype for Android client is installed.
          if (!isSkypeClientInstalled(myContext)) {
            goToMarket(myContext);
             

          return;
          }

          // Create the Intent from our Skype URI.
          Uri skypeUri = Uri.parse(mySkypeUri);
          Intent myIntent = new Intent(Intent.ACTION_VIEW, skypeUri);

          // Restrict the Intent to being handled by the Skype for Android client only.
          myIntent.setComponent(new ComponentName("com.skype.raider", "com.skype.raider.Main"));
          myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

          // Initiate the Intent. It should never fail because you've already established the
          // presence of its handler (although there is an extremely minute window where that
          // handler can go away).
          myContext.startActivity(myIntent);

          return;
        }


//***********************************************************************
//Determine whether the Skype for Android client is installed on this device.
public boolean isSkypeClientInstalled(Context myContext) {
          PackageManager myPackageMgr = myContext.getPackageManager();
          try {
            myPackageMgr.getPackageInfo("com.skype.raider", PackageManager.GET_ACTIVITIES);
          }
          catch (PackageManager.NameNotFoundException e) {
            return (false);
          }
          return (true);
        }

//**********************************************************************
//Install the Skype client through the market: URI scheme.
        public void goToMarket(Context myContext) {
          Uri marketUri = Uri.parse("market://details?id=com.skype.raider");
          Intent myIntent = new Intent(Intent.ACTION_VIEW, marketUri);
          myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          myContext.startActivity(myIntent);
   
          return;
        }

Saturday, 22 November 2014

how to create simple alert dialog in android


AlertDialog

// Internet Connection Error alertDialog
            final AlertDialog alertDialog = new AlertDialog.Builder(mContext).create();
            alertDialog.setTitle("Internet Connection Error");
            alertDialog.setMessage("Please connect to working Internet connection");
            alertDialog.setIcon(R.drawable.ic_alert);
            alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {   
                    alertDialog.dismiss();
                    MainActivity.this.finish();
                }
            });
            alertDialog.show();

how to use simple spinner in android example


main_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Spinner
        android:id="@+id/spinner1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:prompt="@string/spinner_prompt" />
</LinearLayout>

MainActivity.java

public class MainActivity extends Activity {

    private Spinner spinner1;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);

        spinner1 = (Spinner) findViewById(R.id.spinner1);
        List<String> list = new ArrayList<String>();
        list.add("aaaaa");
        list.add("bbbbb");
        list.add("ccccc");
        list.add("ddddd");
        list.add("eeeee");
        
        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>
                     (this, android.R.layout.simple_spinner_item,list);
                     
        dataAdapter.setDropDownViewResource
                     (android.R.layout.simple_spinner_dropdown_item);
                     
        spinner1.setAdapter(dataAdapter);
         }

    }

Thursday, 13 November 2014

how to paly youtube video for webview in andriod example

main_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    android:orientation="vertical" >

    <WebView
        android:id="@+id/webView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>


MainActivity.java


public class MainActivity extends Activity {

WebView mWebView;

       @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);

 mWebView = (WebView) findViewById(R.id.webView1);

/** unfortunately, we have to check sdk version ***/
        if (Build.VERSION.SDK_INT < 8) {
            mWebView.getSettings().setPluginsEnabled(true);
        } else {
            mWebView.getSettings().setPluginState(PluginState.ON);
        }
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.getSettings().setUserAgent(0);
        mWebView.setWebChromeClient(new WebChromeClient() {
        });


        /**
         * <iframe id="ytplayer" type="text/html" width="640" height="360"
         * src="https://www.youtube.com/embed/WM5HccvYYQg" frameborder="0"
         * allowfullscreen>
         **/


 String html = "<iframe class=\"youtube-player\" "
         + "style=\"border: 0; width: 100%; height: 95%;"
         + "padding:0px; margin:0px\" "
         + "id=\"ytplayer\" type=\"text/html\" "
         + "src=\"//www.youtube.com/embed/" + videoId
         + "?fs=1\" frameborder=\"0\" " + "allowfullscreen autobuffer "
         + "controls onclick=\"this.play()\">\n" + "</iframe>\n";


        final String mimeType = "text/html";
        final String encoding = "UTF-8";                                  

        mWebView.loadDataWithBaseURL("", html, mimeType, encoding, "");

   }
}

AndroidManifest.xml

 <uses-permission android:name="android.permission.INTERNET" />

 <application
        android:allowBackup="true"

        android:hardwareAccelerated="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

</application>