andorid 琐碎日记五

1.从resources 里面的数组转化成代码:
int indicesInt[] = context.getResources().getIntArray(R.array.indices);
short indices[] = new short[indicesInt.length];
for (int i = 0; i < indicesInt.length; i++) { indices[i] = (short)indicesInt[i];}
2.intent-filter的用法,得到特定的网址后 自动响应intent
<intent-filter>
<action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>
<data android:host="www.youtube.com" android:scheme="http"></data>
</intent-filter>

<uses-permission android:name="android.permission.INTERNET" />
<activity android:name=".activity.ExeReceiver">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:host=".*" />
<data android:mimeType="*/*"/>
</intent-filter>
</activity>
3. 得到后台运行的程序
ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> l = am.getRunningAppProcesses();

4.为程序添加一个“分享”发送到某个地方,只能在主xml实现目前,而不能用代码实现:
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter >
然后就可以启动代码了
Intent intent = new Intent(Intent.ACTION_SEND);
startActivity(Intent.createChooser(intent , "Send options"));
http://groups.google.com/group/android-developers/browse_thread/thread/62a514363c751464/feecc033d0265606?lnk=gst&q=intentfilter+share#feecc033d0265606

5.在代码中注册一个registerReceiver的方法:
public class MyActivity extends Activity {


private static final String TAG = "MyActivity";


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);


IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_SEND);
intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
try {
intentFilter.addDataType("image/*");
} catch (MalformedMimeTypeException e) {
Log.e(TAG, e.toString());
}


Intent x = registerReceiver(new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "Received intent "+intent);
intent.setComponent(new ComponentName(context,
Uploader.class));
startActivity(intent);
}
}, intentFilter);


if (x==null)
Log.i(TAG, "failed to regist a receiver");
else
Log.i(TAG, "registed a receiver successfully");
// ...


http://groups.google.com/group/android-developers/browse_thread/thread/ca183e0cbe0e1aec/34fa612bafd4c22f?lnk=gst&q=gallery#34fa612bafd4c22f
6.从CalendarProvider得到数据的方法:
ContentResolver contentResolver = context.getContentResolver();
Cursor cursor = contentResolver.query(Uri.parse("content://calendar/events"), null, null, null, null);
while(cursor.moveToNext()) {
String eventTitle = cursor.getString(cursor.getColumnIndex("title"));
Date eventStart = new Date(cursor.getLong(cursor.getColumnIndex("dtstart"))); // etc.}

让手机打不出电话解决办法
1) Create a BroadcastReceiver with a priority of 0. 2) In the BC intercept the ACTION_NEW_OUTGOING_CALL intent in its OnReceive method 3) call setResultData(null) in the same method

添加 an image icon in在expandable list view ,取代默认的图片
setGroupIndicator(Drawable)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值