Saturday, November 17, 2012

How to create user defined Server Role to manage permissions easily in SQL Server 2012

Until SQL 2008 R2, you don't have option to create user defined server role. In SQL Server 2012, you can create a server role with permissions. It would help easily to manage the login with limited permissions. 


For example, in your company, there are  two teams to manage the front end and back end. Back end team should able to create obejcts and manage database. Front end team should have only access to read and write the records and not allow to create/alter sql objects. To achieve this, you can do either by create login with permissions or by means of server role. It would be easy for you to manage the login with server role with permission set.

Follow the below step on how to create a server role, permissions and logins.

Step1: Create a Server Role.

















Step 2: Assigning permissions to server role.






Step 3: After server role created.





Step 4: Create Login with assigning newly created user defined server role.


Sunday, November 04, 2012

How to open Google Map with locating address in Android

In this post, I am going to explain how google map with locating address in Android. Just three lines of code is enough to make this happen. Before run the application, make sure that you have selected Google Map API in AVD Manager configuration.


 String address = "Jawaharlal Nehru Rd Kasi Estate Jafferkhanpet Chennai Tamil Nadu";   
 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=" + address));  
 context.startActivity(intent);  


 Here is the complete code.

Layout File:


 <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" >  
   <Button  
     android:id="@+id/btnGoogleMap"  
     android:layout_width="wrap_content"  
     android:layout_height="wrap_content"  
     android:layout_centerHorizontal="true"  
     android:layout_marginTop="30dp"  
     android:text="Google Map" />  
 </RelativeLayout>  


Activity Class:


 import android.net.Uri;  
 import android.os.Bundle;  
 import android.app.Activity;  
 import android.content.Context;  
 import android.content.Intent;  
 import android.view.Menu;  
 import android.view.View;  
 import android.view.View.OnClickListener;  
 import android.widget.Button;  
 public class GoogleMapActivity extends Activity {  
      final Context context = this;  
      Button btnGoogleMap;  
   @Override  
   public void onCreate(Bundle savedInstanceState) {  
     super.onCreate(savedInstanceState);  
     setContentView(R.layout.google_map);  
     btnGoogleMap.setOnClickListener(new OnClickListener() {  
             public void onClick(View v) {  
                  String address = "Jawaharlal Nehru Rd Kasi Estate Jafferkhanpet Chennai Tamil Nadu";   
                  Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=" + address));  
                  context.startActivity(intent);  
              }  
             }  
        );  
   }  
   @Override  
   public boolean onCreateOptionsMenu(Menu menu) {  
     getMenuInflater().inflate(R.menu.google_map, menu);  
     return true;  
   }  
 }  



Manifest File:



 <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
   package="com.ayyanar.helloworld"  
   android:versionCode="1"  
   android:versionName="1.0" >  
   <uses-sdk  
     android:minSdkVersion="8"  
     android:targetSdkVersion="15" />  
   <uses-permission android:name="android.permission.INTERNET" />  
   <application  
     android:icon="@drawable/ic_launcher"  
     android:label="@string/app_name"  
     android:theme="@style/AppTheme" >  
      <activity  
       android:name=".GoogleMapActivity"  
       android:label="@string/title_activity_google_map" >  
       <intent-filter>  
         <action android:name="android.intent.action.MAIN" />  
         <category android:name="android.intent.category.LAUNCHER" />  
       </intent-filter>  
     </activity>  
   </application>  
 </manifest>  


Screenshots:





 

How to load web site in native Android application using WebView control

In this post, I am going to explain how to load website in native android web application using webview control. Just three lines of code is enough to make it happen.

Just use the below code to load the website either during oncreate event or button click event.

 webView = (WebView) findViewById(R.id.webView1);  
 webView.getSettings().setJavaScriptEnabled(true);  
 webView.loadUrl("http://ayyanar.blogspot.com");  


And also, you have to set INTERNET PERMISSION in manifest file like below.

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


Here is the complete code to do this.

Layout File:

 <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" >  
   <TextView  
     android:id="@+id/textView1"  
     android:layout_width="wrap_content"  
     android:layout_height="wrap_content"  
     android:layout_centerHorizontal="true"  
     android:layout_centerVertical="true"  
     android:padding="@dimen/padding_medium"  
     android:text="@string/hello_world"  
     tools:context=".WebViewActivity" />  
   <WebView  
     android:id="@+id/webView1"  
     android:layout_width="match_parent"  
     android:layout_height="match_parent"  
     android:layout_alignParentBottom="true"  
     android:layout_alignParentRight="true" />  
 </RelativeLayout>  


Activity Class:

 
 import android.os.Bundle;  
 import android.app.Activity;  
 import android.view.Menu;  
 import android.webkit.WebView;  
 public class WebViewActivity extends Activity {  
      WebView webView;  
   @Override  
   public void onCreate(Bundle savedInstanceState) {  
     super.onCreate(savedInstanceState);  
     setContentView(R.layout.web_view);  
     webView = (WebView) findViewById(R.id.webView1);  
           webView.getSettings().setJavaScriptEnabled(true);  
           webView.loadUrl("http://ayyanar.blogspot.com");  
   }  
   @Override  
   public boolean onCreateOptionsMenu(Menu menu) {  
     getMenuInflater().inflate(R.menu.web_view, menu);  
     return true;  
   }  
 }  


Manifest File:

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
   package="com.ayyanar.helloworld"  
   android:versionCode="1"  
   android:versionName="1.0" >  
   <uses-sdk  
     android:minSdkVersion="8"  
     android:targetSdkVersion="15" />  
   <uses-permission android:name="android.permission.INTERNET" />  
   <application  
     android:icon="@drawable/ic_launcher"  
     android:label="@string/app_name"  
     android:theme="@style/AppTheme" >  
     <activity  
       android:name=".WebViewActivity"  
       android:label="@string/title_activity_web_view" >  
       <intent-filter>  
         <action android:name="android.intent.action.MAIN" />  
         <category android:name="android.intent.category.LAUNCHER" />  
       </intent-filter>  
     </activity>  
   </application>  
 </manifest>  


 Screenshot:

 

How to create alert dialog box in Android

In this post, I am going to explain about how to create alert dialog in android application. In dialog box interface, you can set the text for title, Yes & No button. And also, you can define the action for each button events.

Please use the below code to create alert dialog in button click event.

 btnAlertDialog.setOnClickListener(new OnClickListener() {  
             public void onClick(View v) {  
                     AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);  
                     // Title of Alert Dialog  
                     alertDialogBuilder.setTitle("Your Title");  
                     // Building alert dialog  
                     alertDialogBuilder  
                          .setMessage("Welcome Ayyanar!.")  
                          .setCancelable(false)   
                          .setPositiveButton("Yes",new DialogInterface.OnClickListener() {  
                          public void onClick(DialogInterface dialog,int id) {  
                                    txtAlertText.setText("OK Thanks!");  
                               }  
                           })  
                          .setNegativeButton("No",new DialogInterface.OnClickListener() {  
                          public void onClick(DialogInterface dialog,int id) {  
                                    txtAlertText.setText("No Thanks!");  
                     // Close the dialog  
                                    dialog.cancel();  
                         }  
                       });  
                     // create alert dialog  
                     AlertDialog alertDialog = alertDialogBuilder.create();  
                     // open dialog  
         alertDialog.show();  
              }  
             }  
        );  


From the above code, you can able to understand on how to set text and event for each button. Everything self descriptive.

Here is the complete code for alert dialog example.

Layout File:

 <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" >  
   <TextView  
     android:id="@+id/txtAlertText"  
     android:layout_width="wrap_content"  
     android:layout_height="wrap_content"  
     android:layout_centerHorizontal="true"  
     android:layout_centerVertical="true"  
     android:padding="@dimen/padding_medium"  
     android:text="[Alert Text]"  
     tools:context=".AlertDialogActivity" />  
   <Button  
     android:id="@+id/btnOpenAlertDialog"  
     android:layout_width="wrap_content"  
     android:layout_height="wrap_content"  
     android:layout_above="@+id/txtAlertText"  
     android:layout_centerHorizontal="true"  
     android:layout_marginBottom="56dp"  
     android:text="Open Alert Dialog" />  
 </RelativeLayout>  



Activity Class:

 import android.os.Bundle;  
 import android.app.Activity;  
 import android.app.AlertDialog;  
 import android.content.Context;  
 import android.content.DialogInterface;  
 import android.view.Menu;  
 import android.view.View;  
 import android.view.View.OnClickListener;  
 import android.widget.Button;  
 import android.widget.TextView;  
 public class AlertDialogActivity extends Activity {  
      final Context context = this;  
      Button btnAlertDialog;  
      TextView txtAlertText;  
   @Override  
   public void onCreate(Bundle savedInstanceState) {  
     super.onCreate(savedInstanceState);  
     setContentView(R.layout.alert_dialog);  
     btnAlertDialog = (Button) findViewById(R.id.btnOpenAlertDialog);  
     txtAlertText = (TextView) findViewById(R.id.txtAlertText);  
     btnAlertDialog.setOnClickListener(new OnClickListener() {  
             public void onClick(View v) {  
                     AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);  
                     // Title of Alert Dialog  
                     alertDialogBuilder.setTitle("Your Title");  
                     // Building alert dialog  
                     alertDialogBuilder  
                          .setMessage("Welcome Ayyanar!.")  
                          .setCancelable(false)   
                          .setPositiveButton("Yes",new DialogInterface.OnClickListener() {  
                          public void onClick(DialogInterface dialog,int id) {  
                                    txtAlertText.setText("OK Thanks!");  
                               }  
                           })  
                          .setNegativeButton("No",new DialogInterface.OnClickListener() {  
                          public void onClick(DialogInterface dialog,int id) {  
                                    txtAlertText.setText("No Thanks!");  
                     // Close the dialog  
                                    dialog.cancel();  
                         }  
                       });  
                     // create alert dialog  
                     AlertDialog alertDialog = alertDialogBuilder.create();  
                     // open dialog  
         alertDialog.show();  
              }  
             }  
        );  
   }  
   @Override  
   public boolean onCreateOptionsMenu(Menu menu) {  
     getMenuInflater().inflate(R.menu.alert_dialog, menu);  
     return true;  
   }  
 }  



Manifest file:

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
   package="com.ayyanar.helloworld"  
   android:versionCode="1"  
   android:versionName="1.0" >  
   <uses-sdk  
     android:minSdkVersion="8"  
     android:targetSdkVersion="15" />  
   <application  
     android:icon="@drawable/ic_launcher"  
     android:label="@string/app_name"  
     android:theme="@style/AppTheme" >  
      <activity  
       android:name=".AlertDialogActivity"  
       android:label="@string/title_activity_alert_dialog" >  
       <intent-filter>  
         <action android:name="android.intent.action.MAIN" />  
         <category android:name="android.intent.category.LAUNCHER" />  
       </intent-filter>  
     </activity>  
   </application>  
 </manifest>  


Screenshots:





How to make a phone call in Android

In this post, I am going to discuss about on how to make a phone call in android. Just three line statements is enough to make a call in android application.

Just use the below code in button click event to make a phone call.

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


And also, you have to set permission in manifest file. Use the below code for phone call permission.

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



Here is the complete code for making a phone call.

Layout File:

 <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" >  
   <Button  
     android:id="@+id/btnPhoneCall"  
     android:layout_width="match_parent"  
     android:layout_height="wrap_content"  
     android:layout_alignParentLeft="true"  
     android:layout_centerVertical="true"  
     android:text="Call +919999999999" />  
 </RelativeLayout>  



Activity Class:

 import android.net.Uri;  
 import android.os.Bundle;  
 import android.app.Activity;  
 import android.content.Intent;  
 import android.view.Menu;  
 import android.view.View;  
 import android.view.View.OnClickListener;  
 import android.widget.Button;  
 public class PhoneCallActivity extends Activity {  
      Button btnPhoneCall;  
   @Override  
   public void onCreate(Bundle savedInstanceState) {  
     super.onCreate(savedInstanceState);  
     setContentView(R.layout.phonecall);  
     btnPhoneCall = (Button) findViewById(R.id.btnPhoneCall);  
     btnPhoneCall.setOnClickListener(new OnClickListener() {  
             public void onClick(View v) {  
                  Intent callIntent = new Intent(Intent.ACTION_CALL);  
                  callIntent.setData(Uri.parse("tel:+919999999999"));  
                  startActivity(callIntent);  
              }  
             }  
        );  
   }  
   @Override  
   public boolean onCreateOptionsMenu(Menu menu) {  
     getMenuInflater().inflate(R.menu.phonecall, menu);  
     return true;  
   }  
 }  


Android Manifest File:

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
   package="com.ayyanar.helloworld"  
   android:versionCode="1"  
   android:versionName="1.0" >  
   <uses-sdk  
     android:minSdkVersion="8"  
     android:targetSdkVersion="15" />  
     <uses-permission android:name="android.permission.CALL_PHONE" />  
   <application  
     android:icon="@drawable/ic_launcher"  
     android:label="@string/app_name"  
     android:theme="@style/AppTheme" >  
     <activity  
       android:name=".PhoneCallActivity"  
       android:label="@string/title_activity_phone_call" >  
       <intent-filter>  
         <action android:name="android.intent.action.MAIN" />  
         <category android:name="android.intent.category.LAUNCHER" />  
       </intent-filter>  
     </activity>  
   </application>  
 </manifest>  



Screenshots: