Top Menu

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Tuesday 23 September 2014

Android key hash for Facebook App

Official Documentation on facebook developer site:

Its pretty confusing to get a Key hash value for creating Facebook Apps for Android.
Here are the detailed steps for doing that-
1. We need to download openssl from Google code (64 bit users must downloadopenssl-0.9.8e X64, not the latest version) 

2. Extract it. 
create a folder- OpenSSL in C:/ and copy the extracted code here. 

3. Detect debug.keystore file path. 
If we can't find one, then lets do a search in C:/ and we will use the Path in the command in next step. 

4. Detect keytool.exe path and go to that dir/ in command prompt and run this command in 1 line-
> keytool -exportcert -alias androiddebugkey -keystore "C:\Documents and Settings\Administrator\.android\debug.keystore" | "C:\OpenSSL\bin\openssl" sha1 -binary |"C:\OpenSSL\bin\openssl" base64

Now, it will ask for password, put android 
That's all. It will return a key-hash.

There is another way to get the key-hash by using these simple lines of code:
try {
    PackageInfo info = getPackageManager().getPackageInfo(
                           "your.package.name",
                           PackageManager.GET_SIGNATURES);
    for (Signature signature : info.signatures) {
        MessageDigest md = MessageDigest.getInstance("SHA");
        md.update(signature.toByteArray());
        Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
    }
}
catch (NameNotFoundException e) {

}
catch (NoSuchAlgorithmException e) {

}
Attention: When running an unsigned version you will get the wrong hash key. The version must be signed. Then you can find your key when filtering by tag name: "KeyHash:".
Read more...

Thursday 18 September 2014

How to write text in bold, normal, small format and in next line


What if we would like to read the the Html text from string.xml resource and thus make it easy to localize. CDATA make this possible:

<string name="my_text">

  <![CDATA[

    <b>Autor:</b> Mr Nice Guy<br/>

    <b>Contact:</b> myemail@grail.com<br/>

    <i>Copyright © 2011-2012 Intergalactic Spacebar Confederation </i>

  ]]>

</string>

From our Java code we could now utilize it like this:

TextView tv = (TextView) findViewById(R.id.myTextView);

tv.setText(Html.fromHtml(getString(R.string.my_text)));

Hope it's useful to some of you!

If you use many HTML tags a CDATA section is better. For the sample above it looks like this:

<string name="htmlFormattedText">
      <![CDATA[

 

      <p>Text with markup for <strong>bold</strong>
      and <em>italic</em> text.</p>

 

      <p>There is also support for a
      <tt>teletype-style</tt> font.

 

      But no use for the <code>code</code>
      tag!</p>

 

      ]]></string>

Even if you can add a lot of HTML tags, you are better off using only minor styling as mixing too much styles makes your text look uneasy instead of being more striking.

The following snippet shows how to use this string from within your Java code:

TextView view = (TextView)findViewById(R.id.sampleText);
String formattedText = getString(R.string.htmlFormattedText);

 

Spanned result = Html.fromHtml(formattedText);
view.setText(result);

 

Link for reference:


Read more...

xml parsing in android


Here i have added coding for parsing data from the rss feed using xmlpullparser.

Here i ,parsing the data from the xml tag and set it into the listview.

First,

 

You have the pass the URL as a String

 

String url=”EnterURL”;

 

Then,use the following code to parse the data.

 

Parsing.Java

 

import java.io.IOException;

import java.io.InputStream;

import java.net.MalformedURLException;

import java.net.URL;

import java.util.ArrayList;

import java.util.List;

import org.xmlpull.v1.XmlPullParser;

import org.xmlpull.v1.XmlPullParserException;

import org.xmlpull.v1.XmlPullParserFactory;


import com.example.headlines.R;


import android.app.ListActivity;

import android.content.Intent;

import android.net.Uri;

import android.os.Bundle;

import android.view.View;

import android.widget.ArrayAdapter;

import android.widget.ListView;

import android.widget.TextView;

public class Parsing extends ListActivity

{

List headlines;

List links;

TextView txt1;

Intent intent1;

String siteName=””;

public void onCreate(Bundle savedInstanceState) 

{

super.onCreate(savedInstanceState);

setContentView(R.layout.parsing);

txt1=(TextView)findViewById(R.id.textView1);

siteName=getIntent().getStringExtra(“siteName”);

txt1.setText(“From: “+siteName);

headlines = new ArrayList();

links = new ArrayList();

try 

{

URL url = new URL(getIntent().getDataString());

XmlPullParserFactory factory = XmlPullParserFactory.newInstance();

factory.setNamespaceAware(false);

XmlPullParser xpp = factory.newPullParser();

xpp.setInput(getInputStream(url), “UTF_8″);

boolean insideItem = false;

int eventType = xpp.getEventType();


//check the tag upto the end tag

while (eventType != XmlPullParser.END_DOCUMENT) 

{

if (eventType == XmlPullParser.START_TAG) 

{


//check the tag and parsing the data and set it into the String Array.


if (xpp.getName().equalsIgnoreCase(“item”)) 

{

insideItem = true;


else if (xpp.getName().equalsIgnoreCase(“title”)) 

{

if (insideItem)

headlines.add(xpp.nextText()); //extract the headline


else if (xpp.getName().equalsIgnoreCase(“link”)) 

{

if (insideItem)

links.add(xpp.nextText());

}

}

else if(eventType==XmlPullParser.END_TAG && xpp.getName().equalsIgnoreCase(“item”))

{

insideItem=false;

}

eventType = xpp.next(); 

}



catch (MalformedURLException e) 

{

e.printStackTrace();


catch (XmlPullParserException e) 

{

e.printStackTrace();

}

catch (IOException e) 

{

e.printStackTrace();

}


//set the data to the listview


ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1, headlines);

setListAdapter(adapter);

}

public InputStream getInputStream(URL url) 

{

try 

{

return url.openConnection().getInputStream();


catch (IOException e) 

{

return null;

}

}

}
Read more...

GalleryView in Android


GalleryView in Android is the coding for,how to set the images in the galleryview.

The images in the galleryview can be scrollable and easily able to switch another picture,

 

First,The xml file for the galleryview.

MainActivity.xml  

//Here you have to set the view for image and gallery.

<?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” >
<TextView
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”Images” />
<Gallery
android:id=”@+id/gallery1″
android:layout_width=”fill_parent”
android:layout_height=”wrap_content” />
<ImageView
android:id=”@+id/image1″
android:layout_width=”320px”
android:layout_height=”250px”
android:scaleType=”fitXY” />
</LinearLayout>

//Then you have to set the style for the galleryView.

res/values/img.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<resources>
<declare-styleable name=”Gallery1″>
<attr name=”android:galleryItemBackground”/>
</declare-styleable>
</resources>

//finally have to add class for the galleryview..

MainActivity.java

import android.app.Activity;

import android.content.Context;

import android.content.res.TypedArray;

import android.os.Bundle;

import android.view.View;

import android.view.ViewGroup;

import android.widget.AdapterView;

import android.widget.AdapterView.OnItemClickListener;

import android.widget.BaseAdapter;

import android.widget.Gallery;

import android.widget.ImageView;

import android.widget.Toast;

 

public class MainActivity extends Activity {

    

    //—the images to display—

    Integer[] imageIDs = {

    R.drawable.apps,

    R.drawable.camera,

    R.drawable.computer,

    R.drawable.gaming,

    R.drawable.mobile,

    R.drawable.social,

        };

    ImageView img_view;

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState)

    {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        Gallery gallery = (Gallery) findViewById(R.id.gallery1);

        img_view=(ImageView)findViewById(R.id.image1);

 

//set the images in the galleryView.

 

        gallery.setAdapter(new ImageAdapter(this));

        gallery.setOnItemClickListener(new OnItemClickListener()

        {

        public void onItemClick(AdapterView<?> parent, View v,

        int position, long id)

        {

        img_view.setBackgroundResource(imageIDs[position]);

        Toast.makeText(getBaseContext(),

        “pic” + (position + 1) + “selected”,

        Toast.LENGTH_SHORT).show();

        }

        });

    }

    

    public class ImageAdapter extends BaseAdapter

    {

      private Context context;

      private int itemBackground;

       public ImageAdapter(Context c)

       {

          context = c;

         

    //—setting the style—

          TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);

          itemBackground = a.getResourceId(

          R.styleable.Gallery1_android_galleryItemBackground, 0);

          a.recycle();

       }

 

       //—returns the number of images—

       public int getCount() 

       {

           return imageIDs.length;

       }

           //—returns the ID of an item—

       public Object getItem(int position)

       {

           return position;

       }

       //—returns the ID of an item—

       public long getItemId(int position)

       {

           return position;

       }

       //—returns an ImageView view—

    public View getView(int position, View convertView, ViewGroup parent)

    {

    ImageView imageView = new ImageView(context);

    imageView.setImageResource(imageIDs[position]);

    imageView.setScaleType(ImageView.ScaleType.FIT_XY);

    imageView.setLayoutParams(new Gallery.LayoutParams(150, 120));

    imageView.setBackgroundResource(itemBackground);

    return imageView;

    }

    }  

}
Read more...