Skip to content

Instantly share code, notes, and snippets.

@granoeste
granoeste / gist:1026660
Created June 15, 2011 07:48
[Android][Bluetooth]Bluetooth Discovery
// Create a BroadcastReceiver for ACTION_FOUND and ACTION_DISCOVERY_FINISHED
private final BroadcastReceiver mDeviceDiscoverReceiver = new BroadcastReceiver() {
int cnt = 0;
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
// When discovery finds a device
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// Get the BluetoothDevice object from the Intent
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
@granoeste
granoeste / gist:1033085
Created June 18, 2011 13:15
[Android]Using the Handler and Lopper with HandlerThread
// With reference to the android.app.IntentService of the Android framework
// Member variable
private volatile Looper mServiceLooper;
private volatile ServiceHandler mServiceHandler;
// Handler Class
private final class ServiceHandler extends Handler {
public ServiceHandler(Looper looper) {
super(looper);
@granoeste
granoeste / To start the repeatedly running.java
Created June 23, 2011 07:08
[Android]Repeatedly running the Service in the Alarm Manager
Intent serviceIntent = new Intent(this, MyService.class);
PendingIntent pendingIntent
= PendingIntent.getService(this, 0, serviceIntent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.setInexactRepeating (
AlarmManager.RTC,
System.currentTimeMillis(),
//AlarmManager.INTERVAL_HOUR,
AlarmManager.INTERVAL_FIFTEEN_MINUTES,
pendingIntent);
@granoeste
granoeste / AccountList.java
Created August 25, 2011 05:54
[Android]Authenticate Google Acount
public class AccountList extends ListActivity {
protected AccountManager accountManager;
protected Intent intent;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
accountManager = AccountManager.get(getApplicationContext());
Account[] accounts = accountManager.getAccountsByType("com.google");
@granoeste
granoeste / AndroidManifest_auto.xml
Created September 19, 2011 09:00
[Android] Definition of InstallLocation in AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.granoeste.creador.InternalOnlyAppWidget"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="auto"
>
</manifest>
@granoeste
granoeste / GoogleServiceAuthExampleActivity.java
Created September 28, 2011 12:53
[Android] Google Service Authenticate
public class GoogleServiceAuthExampleActivity extends ListActivity {
private static final String TAG = GoogleServiceAuthExampleActivity.class.getName();
GoogleServiceAuthenticator authenticator;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
authenticator = new GoogleServiceAuthenticator(this);
Account[] accounts = authenticator.getGoogleAccounts();
@granoeste
granoeste / list_row.xml
Created October 6, 2011 04:12
[Android] ListView Layout
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/list_row_background"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
@granoeste
granoeste / MyCustomView.java
Created November 30, 2011 07:58
[Android] onMeasure()で幅や高さの実際値を取得する
@Override
protected void onMeasure(int widthMeasureSpec,int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
}
@granoeste
granoeste / gist:1716840
Created February 1, 2012 12:40
[Android] Is this application system? Or whether the system is not.
final PackageManager pm = getPackageManager();
final List<ApplicationInfo> appInfos = pm.getInstalledApplications(Context.BIND_AUTO_CREATE);
for (final ApplicationInfo appInfo : appInfos) {
// Determination of the bit flag.
if( (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
Log.d("ApplicationInfo[SYSTEM]",appInfo.toString());
} else {
Log.d("ApplicationInfo[NOT SYSTEM]",appInfo.toString());
@granoeste
granoeste / gist:1842596
Created February 16, 2012 06:15
[Android]IOException: No space left on device when commit in SharedPreferences
Exception occurs when lack of capacity when you commit in SharedPreferences
---
02-16 15:10:15.378: W/ApplicationContext(2289): writeToFile: Got exception:
02-16 15:10:15.378: W/ApplicationContext(2289): java.io.IOException: No space left on device
02-16 15:10:15.378: W/ApplicationContext(2289): at org.apache.harmony.luni.platform.OSFileSystem.write(Native Method)
02-16 15:10:15.378: W/ApplicationContext(2289): at dalvik.system.BlockGuard$WrappedFileSystem.write(BlockGuard.java:171)
02-16 15:10:15.378: W/ApplicationContext(2289): at java.io.FileOutputStream.write(FileOutputStream.java:300)
02-16 15:10:15.378: W/ApplicationContext(2289): at com.android.internal.util.FastXmlSerializer.flushBytes(FastXmlSerializer.java:212)
02-16 15:10:15.378: W/ApplicationContext(2289): at com.android.internal.util.FastXmlSerializer.flush(FastXmlSerializer.java:233)
02-16 15:10:15.378: W/ApplicationContext(2289): at com.android.internal.util.FastXmlSerializer.endDocument(FastXmlSerializer.java:183)