Archive

Posts Tagged ‘handle’

Check whether droid can handle PDF file


A cool snippet for today:

    public boolean canReadPdf(Context c) {
    	PackageManager pm = c.getPackageManager();
    	Intent data = new Intent(Intent.ACTION_VIEW);
    	// set MIME type
    	data.setType("application/pdf");
    	// if any package being able to handle PDF file
    	if(pm.queryIntentActivities(data, PackageManager.MATCH_DEFAULT_ONLY).size() > 0) {
    		return true;
    	}
    	// not found any
    	return false;
    }

Hope you like it!

Cheers,
Pete Houston

Advertisements
Categories: Tricks & Tips Tags: , , , , , ,

Handle hard-key MENU long press event

July 6, 2011 6 comments

Quick snippet:

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
	    if (keyCode == KeyEvent.KEYCODE_MENU) {
	        event.startTracking();
	        return true;
	    }
	    return super.onKeyDown(keyCode, event);
	}

	@Override
	public boolean onKeyLongPress(int keyCode, KeyEvent event) {
	    if (keyCode == KeyEvent.KEYCODE_MENU) {
	        return true;
	    }
	    return super.onKeyDown(keyCode, event);
	}

Cheers,
Pete Houston