Skip to content

Instantly share code, notes, and snippets.

Matthias Käppler mttkay

Block or report user

Report or block mttkay

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View foo_activity.xml
<TextView android:id="@+id/my_text" ...>
mttkay / gist:3851440
Created Oct 8, 2012
Testing if an Android app is installed on the SD card
View gist:3851440
private boolean isAppInstalledToSDCard(Context context) {
PackageManager pm = context.getPackageManager();
try {
int extStorage = ApplicationInfo.FLAG_EXTERNAL_STORAGE;
String package = context.getPackageName();
ApplicationInfo appInfo = pm.getApplicationInfo(package, extStorage);
return extStorage == (extStorage & appInfo.flags);
} catch (NameNotFoundException e) {
return false;
mttkay / gist:2995057
Created Jun 26, 2012
Android obtainStyledAttributes
View gist:2995057
public MyWidget(Context context, AttributeSet attrs, int defStyle) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MyWidget, defStyle);
// read attribute values
boolean userBoolAttr = a.getBoolean(R.styleable.bool_attr, false);
int userIntAttr = a.getInteger(R.styleable.int_attr, 0);
// do something with these values
// ...
mttkay / gist:2994987
Created Jun 26, 2012
Android use custom attribute
View gist:2994987
int_attr="1" />
mttkay / gist:2994973
Created Jun 26, 2012
Android declare-styleable sample
View gist:2994973
<declare-styleable name="MyWidget">
<attr name="bool_attr" format="boolean" />
<attr name="int_attr" format="integer" />
View Ruby inheritance
class Base
def m
puts "Base::m"
module MixinA
def m
puts "MixinA::m"
mttkay / gist:1868951
Created Feb 20, 2012
Inserting a StreamItemPhoto
View gist:1868951
private void addStreamItemPhoto(String photoUrl, long streamItemId, String accountName) {
byte[] photoData = downloadPhoto(photoUrl);
ContentValues values = new ContentValues();
values.put(StreamItems.ACCOUNT_NAME, accountName);
values.put(StreamItems.ACCOUNT_TYPE, "com.yourapp.account");
values.put(StreamItemPhotos.STREAM_ITEM_ID, streamItemId);
values.put(StreamItemPhotos.PHOTO, photoData);
resolver.insert(StreamItems.CONTENT_PHOTO_URI, values);
mttkay / gist:1868888
Created Feb 20, 2012
Android social stream view item Activity
View gist:1868888
<activity android:name=".social.ViewStreamItemActivity">
<action android:name="android.intent.action.VIEW"/>
<data android:host="" android:scheme="content" android:pathPattern="/stream_items/*"/>
mttkay / gist:1393552
Created Nov 25, 2011
IgnitedAsyncTask sample
View gist:1393552
import com.github.ignition.core.tasks.IgnitedAsyncTask;
public class IgnitedAsyncTaskActivity extends Activity {
private SampleTask task;
public void onCreate(Bundle savedInstanceState) {
mttkay / gist:1105281
Created Jul 25, 2011
Workaround for Android issue 9656
View gist:1105281
public class MyLibrary {
public static final String XMLNS = ""
// in widget class
public class MyWidget {
public MyWidget(Context context, AttributeSet attrs) {
// don't use obtainStyledAttributes, but getAttributeResourceValue:
int myAttr = attrs.getAttributeResourceValue(MyLibrary.XMLNS, "myAttr", -1);
You can’t perform that action at this time.