Android: install .apk programmatically (without user prompt)

This note we need to create Android Application that has auto update feature for our android application. We do that for PandaBoard and other device that rooted.

1. Install BusyBox (for PandaBoard you can copy binary from BusyBox and paste to /system/bin/busybox) (for general device you can install BusyBox from Android Market)

2. set permission /data/app to 777 (some time you need to set 777 permission for /system/bin/busybox)

3. Make your own application that contained this code


Process install;

try {

install = Runtime.getRuntime().exec("/system/bin/busybox install " + Environment.getExternalStorageDirectory() + "/Download/" + "XXX.apk /data/app/XXX.apk");

int iSuccess = install.waitFor();

Log.e("TEST", ""+iSuccess);

} catch (IOException e) {

} catch (InterruptedException e) {

}

4. Run and Enjoy it!!

Posted in Developer, Uncategorized | Tagged , , , , | Leave a comment

Open Facebook Official App with Intent [Android]

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);

uri can be:

fb://feed/{userID}
fb://profile/{#user_id}/wall
fb://profile/{#user_id}/info
fb://profile/{#user_id}/photos
fb://profile/{#user_id}/mutualfriends
fb://profile/{#user_id}/friends
fb://profile/{#user_id}/fans
fb://messaging/{#user_id}
fb://album/{%s}?owner={#%s}

The green color lines are the Uri that I tested and it;s work.

Thank you fosonic

Posted in Developer, Uncategorized | Tagged , , , , | Leave a comment

FQL COUNT Operator

NO WAY!

There is not COUNT Operator for FQL.

But we can optimize query for count some thing.

Example:

SELECT ” FROM like WHERE post_id=”xxxxxxx”

This query return the smallest array, the number of json array is the number of post likes.

Posted in Developer, Uncategorized | Tagged , | Leave a comment

FQL Multiple Query & Android SDK Example

  • this example show how to use fql.multiquery in Android SDK
  • this example query your friend check-in for some time duration

Example Code:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date = sdf.parse("2011-12-31");
long utc = date.getTime()/1000;

Bundle params = new Bundle();
JSONObject jsonFQL = new JSONObject();

//#Query 1
jsonFQL.put("query1", "SELECT author_uid, page_id FROM checkin WHERE timestamp>"+utc+" AND author_uid IN(SELECT uid2 FROM friend WHERE uid1 = me())");

//#Query 2, use author_uid from #Query1
jsonFQL.put("query2", "SELECT name, uid, pic_square FROM user WHERE uid IN (SELECT author_uid FROM #query1)");

params.putString("method", "fql.multiquery");
params.putString("queries", jsonFQL.toString());
String response = facebook.request(params);
Log.d("RESULT", response);

JSON Results:
[json]
[{"name":"query1","fql_result_set":[{"author_uid":5830xxx76,"page_id":129971377062559},{"author_uid":5830xxx76,"page_id":175576459119412},........]},{“name”:”query2″,”fql_result_set”:[{"name":"XXXX","uid":5830xxx76,"pic_square":"http:\/\/profile.ak.fbcdn.net\/hprofile-ak-snc4\/xxxxxxx_q.jpg"},{"name":"YYYYY","uid":5919yyy97,"pic_square":"http:\/\/profile.ak.fbcdn.net\/hprofile-ak-snc4\/yyyyyy_q.jpg"},....]}]
[/json]

Posted in Developer, Uncategorized | Tagged , , , , | Leave a comment

Android AndEngine Live Wallpaper & onOffsetsChanged

Problem : AndEngine Live Wallpaper Extension cannot detect the home screen virtual page is changed (offset change)

Solved : Modify code of BaseWallpaperGLEngine in BaseLiveWallpaperService.java

  • Duplicate BaseLiveWallpaperService and change class name (I change to MyBaseLiveWallpaperService), change inner class BaseWallpaperGLEngine to MyBaseWallpaperGLEngine
  • Override method onOffsetsChanged in MyBaseWallpaperGLEngine
Posted in Developer, Uncategorized | Tagged , , , | Leave a comment

Google Analytic & Host Gator

What is this?

Posted in Developer, Tools/Utilities, Uncategorized | Tagged | Leave a comment

Android onTouch only ACTION_DOWN called problem

Problem occurs when setOnTouchListener to some View, but only ACTION_DOWN is called. The other event is not occur (such as ACTION_MOVE, ACTION_UP.

To resolve this problem, set clickable = true to the View that you want to handle onTouch event.

Posted in Developer, Uncategorized | Tagged , , | 4 Comments

CodeIgniter and Facebook PHP SDK Integration

In this tutorial base on CodeIgniter 2.1 and Facebook PHP SDK 3.1.1

  1. Put facebook_base.php and facebook.php to application/libraries
  2. Create facebook config file (facebook.php) in application/config
    if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    $config['appId']  = 'APP_ID';
    $config['secret'] = 'SECRET';
    
  3. In controller file, you can initial your facebook library
    $this->load->library(‘facebook’);
  4.  Example API call
    $this->facebook->getAccessToken();

Resource: http://jondavidjohn.com/blog/2011/07/using-the-facebook-api-with-codeigniter

Posted in Developer, Uncategorized | Tagged , , , | Leave a comment

Facebook FQL “Like” Operator

FQL ไม่มี “Like” Operator เหมือนใน SQL แต่สามารถใช้ STRPOS แทนได้ ดังตัวอย่าง

SELECT name from place WHERE strpos(lower(name),lower(‘สยาม’)) >=0

จากตัวอย่างจะเทียบได้กับ SQL

SELECT name from place WHERE name LIKE ‘%สยาม%’

Posted in Developer, Uncategorized | Tagged | Leave a comment

Facebook Nearby Place Example (Android & FQL)

ตัวอย่างโค้ด การเรียกดูข้อมูล Facebook Place ในบริเวณใกล้เคียง โดยเรียกผ่าน FQL ตัวอย่างนี้เป็นตัวอย่างโค้ดที่พัฒนาสำหรับ Android

public static ArrayList<PlaceModel> getPlaceList(Facebook facebook, Location location, int distance, int offset, int limit) {
		double lat = location.getLatitude();
		double lon = location.getLongitude();
		Bundle params = new Bundle();
		params.putString("method", "fql.query");
		params.putString("query", "SELECT page_id, name, description, latitude, longitude, checkin_count, distance(latitude, longitude, '" + lat + "', '" + lon
				+ "') FROM place WHERE distance(latitude, longitude, '" + lat + "', '" + lon + "') < "+ distance +"  LIMIT " + limit + " OFFSET " + offset);

		ArrayList<PlaceModel> placeList = new ArrayList<PlaceModel>();
		String response = null;
		try {
			response = facebook.request(params);
			JSONArray jsonArr = new JSONArray(response);
			for(int i=0; i<jsonArr.length(); i++) {
				JSONObject jsonObj = jsonArr.getJSONObject(i);
				PlaceModel place = new PlaceModel();
				place.pageId = jsonObj.getString("page_id");
				place.name = jsonObj.getString("name");
				place.description = jsonObj.getString("description");
				place.latitude = jsonObj.getDouble("latitude");
				place.longitude = jsonObj.getDouble("longitude");
				place.checkInCount = jsonObj.getInt("checkin_count");
				place.distance = jsonObj.getDouble("distance_meters");
				placeList.add(place);
			}
			return placeList;
		} catch (MalformedURLException e) {
			Log.e("Example", "ERROR", e);
			return placeList;
		} catch (IOException e) {
			Log.e("Example", "ERROR", e);
			return placeList;
		} catch (Exception e) {
			Log.e("Example", "ERROR", e);
			return placeList;
		}
	}

 

Posted in Developer, Uncategorized | Tagged , , , , | Leave a comment