Pages

Subscribe:

Ads 468x60px

Labels

Friday, 30 September 2011

Genarate KeyStore to create a Signed APK and Google Maps in Android

To generate the keystore:
==================

----------------------------------------------------------------------------------------------------------------------------------
keytool -genkey -v -keystore myCertificate.keystore -alias myKey -keyalg RSA -keysize 2048 -validity 20000
----------------------------------------------------------------------------------------------------------------------------------

>>Fill the Details:

Enter Keystore Password :- ********
Re-enter new Password    :- ********
What is your first and last Name? :-kkbrothers
What is the name of your organizational unit?:- Elites
What is the name of your organization?:-kkbrothers
What is the name of your City or Locality?:-Hyd
What is the name of your State or Province?:-Ap
What is the two-letter country code for this unit?:- IND



Enter key password for <myKey>
        (RETURN if same as keystore password):-*******
Re-enter new password:-*******







 



For GoogleMaps:
============
Some of the Links link1 , link2

E:\keystore>keytool.exe -list -alias androiddebugkey -keystore "E:\keystore\debu
g.keystore" -storepass android -keypass android
androiddebugkey, Nov 26, 2010, PrivateKeyEntry,
Certificate fingerprint (MD5): FB:93:B3:1D:16:A8:DB:84:B3:1B:0F:5D:EA:51:FB:BA


Your key is:urkey



This key is good for all apps signed with your certificate whose fingerprint is:

FB:93:B3:1D:16:A8:DB:84:B3:1B:0F:5D:EA:51:FB:BA

Here is an example xml layout to get you started on your way to mapping glory:

              <com.google.android.maps.MapView
                 android:layout_width="fill_parent"
                 android:layout_height="fill_parent"
                 android:apiKey="urkey"
                 />


Important links


 Android Samples http://www.bogotobogo.com/android.html


1.Html Color Codes

2. JavaMail api documentation here

3.Developing Web applications with Tomcat and Eclipse here

4.Android Animation Tutorial here

5.How to make a exe file of Java Program ? here

6.Acces to the MMS part file content here

7.How to Read MMS Data in Android? here

8.Android and self-signed ssl certificates here

9.Sending Email in Android using JavaMail API here

10. Android Sample code projects HERE IMP.

11. Other language Samples HERE

12. File Uploading and downloading in android. HERE 

Wednesday, 28 September 2011

Android BroadcastReceiver for SMS

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.telephony.PhoneNumberUtils;
import android.telephony.SmsMessage;
import android.telephony.TelephonyManager;
import android.widget.Toast;


public class SMSReceiver extends BroadcastReceiver {

    private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
    private SharedPreferences myPrefs;
    @Override
    public void onReceive(Context context, Intent intent) {
        Toast.makeText(context, "SMS Received", Toast.LENGTH_LONG).show();
        myPrefs = context.getSharedPreferences("myPrefs",Context.MODE_PRIVATE);
            if (intent.getAction().equals(SMS_RECEIVED)) {
                //Toast.makeText(context, "SMS Received", Toast.LENGTH_LONG).show();
                Bundle bundle = intent.getExtras();
                if (bundle != null) {
                    Object[] pdus = (Object[])bundle.get("pdus");
                    final SmsMessage[] messages = new SmsMessage[pdus.length];
                    for (int i = 0; i < pdus.length; i++) {
                        messages[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
                    }
                    if (messages.length > -1) {
                        String number=messages[0].getOriginatingAddress();
                          if(PhoneNumberUtils.compare(number1, number)||(number.endsWith(number1))){
                                   Intent intent1=new Intent(context,AudioHandler.class);
                                   intent1.putExtra("filename", details.getFilename());
                                    intent1.putExtra("from",details.getFrom());
                                    intent1.putExtra("subject", details.getSubject());
                                    intent1.putExtra("content", details.getContent());
                                    intent1.putExtra("time", details.getTime());
                                    context.startService(intent1);
                                   
                               }
                        }
                    }
             }
    }




And also declare  the bellow permission in the android manifestfile

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

Query the Android Contacts

This code snippet queries all the contacts from the android device and sort those contacts

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.telephony.TelephonyManager;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class ContactActivity extends Activity {
    ArrayList<HashMap<String,String>> contactData=new ArrayList<HashMap<String,String>>();
    ListView nameList;
    private DBAdapter db;
    String contact="";
   
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setTitle("Wait....");
        setContentView(R.layout.deleteaccountlist);
        db=new DBAdapter(this);
        db.open();
        nameList=(ListView)findViewById(R.id.listView2);
        android.telephony.TelephonyManager mng=(TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
        new QueryContacts().execute();
        nameList.setOnItemClickListener(new OnItemClickListener(){
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position,long id) {
                HashMap map=contactData.get(position);
                db.insertSMSContact((String)map.get("name"),(String)map.get("number"));
                db.insertSpeechDetails((String)map.get("number"), 0);
                setResult(Activity.RESULT_OK);
                finish();
            }
        });
    }
   
    class QueryContacts extends AsyncTask<Void,Void,Void> {
        Dialog dialog;
         @Override
        protected void onPreExecute( ) {
            dialog=ProgressDialog.show(ContactActivity.this,"Please wait...", "Loading the contacts..",true, true);
            contactData.clear();
       }
       
         @Override
         protected void onPostExecute(Void result) {
            SimpleAdapter contactsAdapter=new SimpleAdapter(ContactActivity.this,contactData,R.layout.contactview,new String[]{"name","number"},new int[]{R.id.contactName,R.id.contactNumber});
            nameList.setAdapter(contactsAdapter);
            dialog.cancel();
            setTitle("Select Contact:");
         }
         protected void onProgressUpdate(Void... values) {
         }

         @SuppressWarnings("unchecked")
        @Override
         protected Void doInBackground(Void... arg0) {
             ContentResolver cr = getContentResolver();
             Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
             while (cursor.moveToNext()) {
                 try{
                 String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
                 String name=cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                 String hasPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
                 if (Integer.parseInt(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
                     Cursor phones = getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId, null, null);
                     while (phones.moveToNext()) {
                         String phoneNumber = phones.getString(phones.getColumnIndex( ContactsContract.CommonDataKinds.Phone.NUMBER));
                         HashMap<String,String> map=new HashMap<String,String>();
                         map.put("name", name);
                         map.put("number", phoneNumber);
                         contactData.add(map);
                     }
                     phones.close();
                 }
             }catch(Exception e){}
             }
           
           
             /*Cursor cur = cr.query(People.CONTENT_URI,null, null, null, null);
             while (cur.moveToNext()) {
                 try{
                 String id = cur.getString(cur.getColumnIndex(People._ID));
                 String name = cur.getString(cur.getColumnIndex(People.DISPLAY_NAME));
                // if (Integer.parseInt(cur.getString(cur.getColumnIndex(People.PRIMARY_PHONE_ID))) > 0) {
                     Cursor pCur = cr.query(Contacts.Phones.CONTENT_URI,    null,Contacts.Phones.PERSON_ID +" = ?",
                             new String[]{id}, null);
                     while (pCur.moveToNext()) {
                         HashMap<String,String> map=new HashMap<String,String>();
                         String phoneNumber=pCur.getString(pCur.getColumnIndex(Contacts.Phones.NUMBER));
                         map.put("name", name);
                         map.put("number", phoneNumber);
                         contactData.add(map);
                         contact=contact+":"+name;
                         contact=contact+":"+phoneNumber;
                     }
                 //}
                 }catch(Exception e){e.printStackTrace();}
             }
           
              /*
             while (cursor.moveToNext()) {
               
                   String name=cursor.getString(cursor.getColumnIndex(People.DISPLAY_NAME));
                   String phoneNumber = cursor.getString(cursor.getColumnIndex( People.NUMBER));
                   HashMap<String,String> map=new HashMap<String,String>();
                   map.put("name", name);
                   map.put("number", phoneNumber);
                  
                   if(phoneNumber!=null)
                       contactData.add(map);
                }*/
                Collections.sort(contactData, new Comparator(){
                    @Override
                    public int compare(Object o1, Object o2) {
                        HashMap map1=(HashMap)o1;
                        HashMap map2=(HashMap)o2;
                        String s1=(String)map1.get("name");
                        String s2=(String)map2.get("name");
                        return s1.compareTo(s2);
                    }
                });
           
             /*
             Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
                while (cursor.moveToNext()) {
                   String contactId = cursor.getString(cursor.getColumnIndex(
                   ContactsContract.Contacts._ID));
                   String name=cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                   String hasPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
                   if (Integer.parseInt(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
                       Cursor phones = getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId, null, null);
                       while (phones.moveToNext()) {
                           String phoneNumber = phones.getString(phones.getColumnIndex( ContactsContract.CommonDataKinds.Phone.NUMBER));
                           HashMap<String,String> map=new HashMap<String,String>();
                           map.put("name", name);
                           map.put("number", phoneNumber);
                           contactData.add(map);
                       }
                       phones.close();
                   }
                }
                Collections.sort(contactData, new Comparator(){
                    @Override
                    public int compare(Object o1, Object o2) {
                        HashMap map1=(HashMap)o1;
                        HashMap map2=(HashMap)o2;
                        String s1=(String)map1.get("name");
                        String s2=(String)map2.get("name");
                        return s1.compareTo(s2);
                    }
                });*/
            return null;
         }
    }
}



Also declare the permission in the android manifest file

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

Dynamically change the ListView height - Android

This post is used to change the ListView height. This is done depends on the childviews .
 This Utility.java class is like this


 import android.view.View;
import android.view.ViewGroup;
import android.view.View.MeasureSpec;
import android.widget.ListAdapter;
import android.widget.ListView;

public class Utility {
    public static void setListViewHeightBasedOnChildren(ListView listView) {
        ListAdapter listAdapter = listView.getAdapter();
        if (listAdapter == null) {
            // pre-condition
            return;
        }

        int totalHeight = 0;
        int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(), MeasureSpec.AT_MOST);
        for (int i = 0; i < listAdapter.getCount(); i++) {
            View listItem = listAdapter.getView(i, null, listView);
            listItem.measure(desiredWidth, MeasureSpec.UNSPECIFIED);
            totalHeight += listItem.getMeasuredHeight();
        }

        ViewGroup.LayoutParams params = listView.getLayoutParams();
        params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
        listView.setLayoutParams(params);
        listView.requestLayout();
    }
}



In the main Acticity use this Utility class to change the listview height.

 phraseListView=(ListView)findViewById(R.id.phrase_listview);
 phraseAdapter=new PhraseListAdapter(this);
phraseListView.setAdapter(phraseAdapter);
Utility.setListViewHeightBasedOnChildren(phraseListView);
       

Android Custom Tabs.

In this post I customized the android TabWidget color,background,border and many of the TabWidget properties .To do is myself I used the this tutorial.Based on that tutorial I done the modifications in my project.

The xml layout file for the Tabs as like this

        <TabHost
                android:id="@android:id/tabhost"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:visibility="visible">
                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent">
                    <TabWidget
                        android:id="@android:id/tabs"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:background="#000000"
                        android:padding="1dip"/>
                    <FrameLayout
                        android:id="@android:id/tabcontent"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content">
                        <ListView
                            android:id="@+id/email_listview"
                            android:layout_width="fill_parent"
                            android:layout_height="wrap_content"
                            android:dividerHeight="2dip"
                            android:layout_marginTop="2dip"
                            android:layout_marginBottom="2dip"
                            android:background="@drawable/my_border"
                            android:scrollbars="vertical"
                            android:cacheColorHint="#bebebe"
                            android:scrollbarSize="35dip"
                            android:scrollingCache="true"/>
                          <ListView
                            android:id="@+id/domain_listview"
                            android:layout_width="fill_parent"
                            android:layout_height="wrap_content"
                            android:dividerHeight="2dip"
                            android:layout_marginTop="2dip"
                            android:layout_marginBottom="2dip"
                            android:background="@drawable/my_border"
                            android:cacheColorHint="#bebebe"
                            android:scrollbars="vertical"
                            android:scrollbarSize="35dip"
                            android:scrollingCache="true"/>
                           <ListView
                            android:id="@+id/phrase_listview"
                            android:layout_width="fill_parent"
                            android:layout_height="wrap_content"
                            android:dividerHeight="2dip"
                            android:layout_marginTop="2dip"
                            android:layout_marginBottom="2dip"
                            android:background="@drawable/my_border"
                            android:cacheColorHint="#bebebe"
                            android:scrollbars="vertical"
                            android:scrollbarSize="35dip"
                            android:scrollingCache="true"/>
                         
                    </FrameLayout>
                </LinearLayout>
            </TabHost>



Define the my_border.xml drawable file under the drawable folder. This is used to define the custom drawables (here is for custom border for listview.


<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke android:width="2dp" android:color="#FFFF00" />
    <padding android:left="2dp" android:top="0dp"
            android:right="2dp" android:bottom="0dp" />
    <solid android:color="#bebebe" />
    <corners android:radius="4dp" />
</shape>



In the main Activity write java code like this.



private TabHost tabhost;
display = getWindowManager().getDefaultDisplay();
width = display.getWidth()/5+2;
height = display.getHeight();
tabhost=(TabHost)findViewById(android.R.id.tabhost);
tabhost.setup();

//This is the devider drawable between to widgets.
tabhost.getTabWidget().setDividerDrawable(R.drawable.devider);

TabHost.TabSpec spec;
       
        View view1 = getLayoutInflater().inflate(R.layout.tabs_bg,null);
        TextView tv1 = (TextView) view1.findViewById(R.id.tabsText);
        tv1.setText("Email");
        spec = tabhost.newTabSpec("email").setIndicator(tv1);
        spec.setContent(R.id.email_listview);
        tabhost.addTab(spec);
       
        View view = getLayoutInflater().inflate(R.layout.tabs_bg,null);
        TextView tv = (TextView) view.findViewById(R.id.tabsText);
        tv.setText("Domain");
        spec = tabhost.newTabSpec("domain").setIndicator(tv);
        spec.setContent(R.id.domain_listview);
        tabhost.addTab(spec);
       
        View view2 = getLayoutInflater().inflate(R.layout.tabs_bg,null);
        TextView tv2 = (TextView) view2.findViewById(R.id.tabsText);
        tv2.setText("Phrase");
        spec = tabhost.newTabSpec("phrase").setIndicator(tv2);
        spec.setContent(R.id.phrase_listview);
        tabhost.addTab(spec);
       
        tabhost.setCurrentTab(0);
        tabhost.getTabWidget().getChildAt(0).getLayoutParams().height = 60;
        tabhost.getTabWidget().getChildAt(1).getLayoutParams().height = 60;
        tabhost.getTabWidget().getChildAt(2).getLayoutParams().height = 60;
       

The devider.xml file is as follows res/drawable.devider.xml



<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient android:startColor="#000000" android:centerColor="#000000"
        android:endColor="#000000"    android:angle="-90" />
    <size android:width="1dip" />
</shape>



tabs_bg.xml layout file defines the layout for the tabwidget. res/layout/tabs_bg.xml



<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tabsText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="Title"
    android:background="@drawable/tab_bg_selector"
    android:textSize="15dip"
    android:textColor="@drawable/tab_text_selector"
    android:layout_margin="100dip"/>

   
The background and the textcolor selector files are defined like this under the res/drawable folder.





tab_bg_selector.xml


<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <!--  Active tab -->
    <item android:state_selected="true" android:state_focused="false"
        android:state_pressed="false" android:drawable="@drawable/tab_bg_selected" />
    <!--  Inactive tab -->
    <item android:state_selected="false" android:state_focused="false"
        android:state_pressed="false" android:drawable="@drawable/tab_bg_unselected" />
    <!--  Pressed tab -->
    <item android:state_pressed="true" android:drawable="@drawable/tab_bg_press" />
    <!--  Selected tab (using d-pad) -->
    <item android:state_focused="true" android:state_selected="true"
        android:state_pressed="false" android:drawable="@color/transparent" />
</selector>







tab_text_selector.xml


<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:color="@android:color/black" />
    <item android:state_focused="true" android:color="@android:color/white" />
    <item android:state_pressed="true" android:color="@android:color/white" />
    <item android:color="#f8f8f8" />
</selector>



tab_bg_seleced.xml under res/drawable folder


<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient android:startColor="#ffffff" android:centerColor="#f2f2f2"
        android:endColor="#d8d8d8" android:angle="-90" />
    <stroke android:width="0dip" android:color="#000000" />
</shape>





tab_bg_unseleted.xml under res/drawable folder


<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient android:startColor="#5C5C5C" android:centerColor="#424242"
        android:endColor="#222222"    android:angle="-90" />
    <stroke android:width="0dip" android:color="#000000" />
</shape>



tab_bg_press.xml under the res/drawable folder



<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" android:color="#D9D900">
    <gradient android:startColor="#D9D900" android:centerColor="#D9D900"
        android:endColor="#D9D900" android:angle="-90" />
    <stroke android:width="1dp" android:color="#000000" />
</shape>





colors.xml under the res/values folder is like this ..



<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="transparent">#045645</color>
</resources>

             

Get Files from SDcard

To do this we need to get the root directory of the external storage directory, i.e SDcard.

File f = new File("/sdcard");
private List<String> item = new ArrayList<String>();
private List<String> path = new ArrayList<String>();
getFiles(f);
The getFiles(..) method retrieves the all files from the sdcard and stores
    

private void getFiles(File f)
    {
        File[] files=f.listFiles();
        for (int i = 0; i < files.length; i++)
        {
            try{
                if (files[i].isDirectory()) {
                    getFiles(files[i]);
                }
                else
                {
                    if (files[i].isFile() ) {
                        if(files[i].getParent().equals("/sdcard/DCIM/.thumbnails"))
                            continue;
                        String test=files[i].getName().toLowerCase();
                        if(test.endsWith(".mp3")||test.endsWith(".mp4")||test.endsWith(".3gp")||test.endsWith(".wav")||test.endsWith("flac")||test.endsWith("xmf")||test.endsWith("ota"))
                        {
                            path.add(files[i].getPath());
                            item.add(files[i].getName());
                        }
                    }
                }
            }catch(Exception e){
                 e.getMessage();
            }
        }   
    }//get files

Android Video Playing from Url

This code snippet is used to demonstrate the video plying.

The MediaController  of the VideoView will call the hide method at every 3 sec to hide the controller bar.If you don't want to hide the controller then override the hide method.That's what i done in my example.

 The layout file is as follows video.xml

 <?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <VideoView android:id="@+id/videoView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </VideoView>
</LinearLayout>



 Also requires the permission to access the network

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

 And the java code is like this

 package com.video.tab;


import android.app.Activity;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;


public class VideoPlayActivity extends Activity {
   
    public void onCreate(Bundle bundle){
        super.onCreate(bundle);
        setContentView(R.layout.video);
        VideoView videoView = (VideoView)this.findViewById(R.id.videoView);
        final MediaController mc = new MediaController(this);
        videoView.setMediaController(new MediaController(this){
            /*public void hide()
            {
                mc.show();
            }*/
        });
       //videoView.setVideoURI(Uri.parse("http://www.androidbook.com/akc/filestorage/android/documentfiles/3389/movie.mp4"));
     videoView.setVideoPath("/sdcard/rabbit-and-snail.3gp");
       videoView.requestFocus();
       videoView.start();
       


    }


}

Tuesday, 27 September 2011

Android Custom Dialog without title

AlertDialog alertDialog;
AlertDialog.Builder builder = new AlertDialog.Builder(this);
LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.linkpopup,null);
CheckBox dontdisplay=(CheckBox)layout.findViewById(R.id.dontdisplay);
Button popupok=(Button)layout.findViewById(R.id.linkpopupok);
dontdisplay.setOnCheckedChangeListener(new OnCheckedChangeListener(){
      @Override
      public void onCheckedChanged(CompoundButton buttonView,    boolean isChecked) {
             if(isChecked)
                        db.updateDegfaultvalues("dontflag",1);
            else
                        db.updateDegfaultvalues("dontflag",0);
       }
});
popupok.setOnClickListener(new OnClickListener(){
    @Override
     public void onClick(View arg0) {
             alertDialog.cancel();
    }
});
       builder.setView(layout);
       alertDialog = builder.create();
       alertDialog.show();