WEB开发网
开发学院手机开发Android 开发 Android很有用的代码片段集锦 阅读

Android很有用的代码片段集锦

 2010-06-13 15:23:00 来源:WEB开发网   
核心提示:shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(fd));shareIntent.putExtra(Intent.EXTRA_SUBJECT, subject);shareIntent.putExtra(Intent.EXTRA_TEXT, body);8:

shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(fd));

shareIntent.putExtra(Intent.EXTRA_SUBJECT, subject);

shareIntent.putExtra(Intent.EXTRA_TEXT, body);

8:注册一个BroadcastReceiver

registerReceiver(mMasterResetReciever, new IntentFilter(”oms.action.MASTERRESET”));

private BroadcastReceiver mMasterResetReciever = new BroadcastReceiver() {

public void onReceive(Context context, Intent intent){

String action = intent.getAction();

if(”oms.action.MASTERRESET”.equals(action)){

RecoverDefaultConfig();

}

}

};

9:定义ContentObserver,监听某个数据表

private ContentObserver mDownloadsObserver = new DownloadsChangeObserver(Downloads.CONTENT_URI);

private class DownloadsChangeObserver extends ContentObserver {

public DownloadsChangeObserver(Uri uri) {

super(new Handler());

}

@Override

public void onChange(boolean selfChange) {}

}

10:获得 手机UA

public String getUserAgent()

{

String user_agent = ProductProperties.get(ProductProperties.USER_AGENT_KEY, null);

return user_agent;

}

11:清空手机上Cookie

CookieSyncManager.createInstance(getApplicationContext());

CookieManager.getInstance().removeAllCookie();

12:建立GPRS连接

//Dial the GPRS link.

private boolean openDataConnection() {

// Set up data connection.

DataConnection conn = DataConnection.getInstance();

if (connectMode == 0) {

ret = conn.openConnection(mContext, “cmwap”, “cmwap”, “cmwap”);

} else {

ret = conn.openConnection(mContext, “cmnet”, “”, “”);

}

}

13:PreferenceActivity 用法

public class Setting extends PreferenceActivity

Tags:Android 有用 代码

编辑录入:coldstar [复制链接] [打 印]
赞助商链接