andorid 琐碎日记五

本文介绍了Android开发中的一些实用技巧,包括资源数组转换、Intent过滤器设置、获取后台运行程序列表、实现分享功能、注册BroadcastReceiver及从CalendarProvider获取数据等。
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)
内容概要:本文介绍了一个基于冠豪猪优化算法(CPO)的无人机三维路径规划项目,利用Python实现了在复杂三维环境中为无人机规划安全、高效、低能耗飞行路径的完整解决方案。项目涵盖空间环境建模、无人机动力学约束、路径编码、多目标代价函数设计以及CPO算法的核心实现。通过体素网格建模、动态障碍物处理、路径平滑技术和多约束融合机制,系统能够在高维、密集障碍环境下快速搜索出满足飞行可行性、安全性与能效最优的路径,并支持在线重规划以适应动态环境变化。文中还提供了关键模块的代码示例,包括环境建模、路径评估和CPO优化流程。; 适合人群:具备一定Python编程基础和优化算法基础知识,从事无人机、智能机器人、路径规划或智能优化算法研究的相关科研人员与工程技术人员,尤其适合研究生及有一定工作经验的研发工程师。; 使用场景及目标:①应用于复杂三维环境下的无人机自主导航与避障;②研究智能优化算法(如CPO)在路径规划中的实际部署与性能优化;③实现多目标(路径最短、能耗最低、安全性最高)耦合条件下的工程化路径求解;④构建可扩展的智能无人系统决策框架。; 阅读建议:建议结合文中模型架构与代码示例进行实践运行,重点关注目标函数设计、CPO算法改进策略与约束处理机制,宜在仿真环境中测试不同场景以深入理解算法行为与系统鲁棒性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值