Archive for the ‘Google’ Category

01
Mar

It is considered as unreliable because it can sometimes be null. The documentation states that it “can change upon factory reset”. This string can also be altered on a rooted phone.

String androidID = Secure.getString(getContentResolver(), Secure.ANDROID_ID);

29
Feb

Create Scrolling TextView in android.

<ScrollView
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:fillViewport=”true”>
<LinearLayout
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”>
<TextView android:text=”sample text ”
android:id=”@+id/tv”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”>
</TextView>
</LinearLayout>
</ScrollView>

29
Feb
private class DownloadWebPageTask extends AsyncTask {
		@Override
		protected String doInBackground(String... urls) {
			String response = "";
			for (String url : urls) {
				DefaultHttpClient client = new DefaultHttpClient();
				HttpGet httpGet = new HttpGet(url);
				try {
					HttpResponse execute = client.execute(httpGet);
					InputStream content = execute.getEntity().getContent();

					BufferedReader buffer = new BufferedReader(
							new InputStreamReader(content));
					String s = "";
					while ((s = buffer.readLine()) != null) {
						response += s;
					}

				} catch (Exception e) {
					Toast.makeText(getApplicationContext(),"Some Error Occurred! " + e.getMessage(), Toast.LENGTH_LONG).show();
				}
			}
			return response;
		}

		@Override
		protected void onPostExecute(String result) {
			textView.setText(result);
			Toast.makeText(getApplicationContext(),"Loading WebPage Complete", Toast.LENGTH_LONG).show();
		}
	}

	public void readWebpage(View view) {
		DownloadWebPageTask task = new DownloadWebPageTask();
		task.execute(new String[] { "http://www.google.com" });

	}

29
Feb
public void showAlert(){
		CCDirector.sharedDirector().getActivity().runOnUiThread(new Runnable() {
		    public void run() {
		    	AlertDialog.Builder builder = new AlertDialog.Builder(CCDirector.sharedDirector().getActivity());
		    	builder.setMessage("Are you sure you want to exit?")
		    	       .setCancelable(false)
		    	       .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
		    	           public void onClick(DialogInterface dialog, int id) {
		    	        	   CCDirector.sharedDirector().getActivity().finish();
		    	           }
		    	       })
		    	       .setNegativeButton("No", new DialogInterface.OnClickListener() {
		    	           public void onClick(DialogInterface dialog, int id) {
		    	                dialog.cancel();
		    	           }
		    	       });
		    	AlertDialog alert = builder.create();
		    	alert.show();
		    }
		});
	}

29
Feb

For implementing a custom gridview we have to create a custom adapter.

 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        GridView gridview = (GridView) findViewById(R.id.gridview);
        gridview.setAdapter(new MyAdapter(this));
        gridview.setNumColumns(4);
    }

  public class MyAdapter extends BaseAdapter {

    	private Context mContext;

		public MyAdapter(Context c) {
			mContext = c;
		}

		@Override
		public int getCount() {
			return mThumbIds.length;
		}

		@Override
		public Object getItem(int arg0) {
			return mThumbIds[arg0];
		}

		@Override
		public long getItemId(int arg0) {
			return arg0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) { 

			View grid;

			if(convertView==null){
				grid = new View(mContext);
				LayoutInflater inflater=getLayoutInflater();
				grid=inflater.inflate(R.layout.mygrid_layout, parent, false);
			}else{
				grid = (View)convertView;
			}

			ImageView imageView = (ImageView)grid.findViewById(R.id.image);
			imageView.setImageResource(mThumbIds[position]);

			return grid;
		}

	}

17
Feb

In the onCreate() you have to add following code:

GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));

gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(dashboard.this, "" + position, Toast.LENGTH_SHORT).show();
}
});

Next is to include ImageAdapter class:

 

class ImageAdapter extends BaseAdapter {

private Context mContext;

public ImageAdapter(Context c) {
mContext = c;
}

public int getCount() {
return mThumbIds.length;
}

public Object getItem(int position) {
return null;
}

public long getItemId(int position) {
return 0;
}

// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {  // if it’s not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}

imageView.setImageResource(mThumbIds[position]);
return imageView;
}

// references to our images
private Integer[] mThumbIds = { R.drawable.img1, R.drawable.img2   };
}

** You have to copy img1.png and img2.png in the drawable folder **

15
Feb

Create a fonts folder in assets folder and put  TTF fonts in it. After that you have to add following two line to include that fonts:

TextView tv=(TextView)findViewById(R.id.custom);
Typeface face=Typeface.createFromAsset(getAssets(), "fonts/HandmadeTypewriter.ttf");
tv.setTypeface(face);

That’s it!

14
Feb

The WLAN MAC Address string, is a unique identifier that you can use as a device id. Before you read it, you will need to make sure that your project has the android.permission.ACCESS_WIFI_STATE permission or the WLAN MAC Address will come up as null.

 WifiManager wm = (WifiManager)getSystemService(Context.WIFI_SERVICE);
String WLANMAC = wm.getConnectionInfo().getMacAddress();

14
Feb

it is possible to find two devices with the same Pseudo-Unique ID, but the chances in real world applications are negligible

String pseudoUniqueID =
        	Build.BOARD.length()%10+ Build.BRAND.length()%10 +
        	Build.CPU_ABI.length()%10 + Build.DEVICE.length()%10 +
        	Build.DISPLAY.length()%10 + Build.HOST.length()%10 +
        	Build.ID.length()%10 + Build.MANUFACTURER.length()%10 +
        	Build.MODEL.length()%10 + Build.PRODUCT.length()%10 +
        	Build.TAGS.length()%10 + Build.TYPE.length()%10 +
        	Build.USER.length()%10 ; //13 digits

14
Feb

The IMEI: only for Android devices with Phone use:

TelephonyManager TelephonyMgr = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
String szImei = TelephonyMgr.getDeviceId(); // Requires READ_PHONE_STATE

This requires adding a permission in AndroidManifest.xml, and users will be notified upon installing your software: android.permission.READ_PHONE_STATE. The IMEI is unique for your phone and it looks like this: 114985038630335 (unless you have a pre-production device with an invalid IMEI like 0000000000000).