置顶随笔 #
2011年8月21日 #
Android 快捷方式是桌面最基本的组件。它用于直接启动某一应用程序的某个组件。
一般情况下,可以在Launcher的应用程序列表上,通过长按某一个应用程序的图标在左面上创建改该应用程序的快捷方式。另外,还可以通过两种方式在桌面上添加快捷方式:
一:在应用程序中创建一个Intent,然后以Broadcast的形式通知Launcher创建一个快捷方式。
二:为应用程序的组件注册某一个符合特定条件的IntentFilter,然后可以直接在Launcher的桌面添加启动该组件的快捷方式。
下面模拟在应用程序中添加快捷方式
main.xml布局文件
java代码:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Button android:id="@+id/createShortcut" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:textSize="20px" android:text="创建快捷键"/> <Button android:id="@+id/exit" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:textSize="20px" android:text="退出"/> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="eoe.demo" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".ShortCutAction" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-sdk android:minSdkVersion="7" /> <!-- 添加快捷键权限 --> <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" /> </manifest>
ShortCutAction类
java代码
package apkbus.demo;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
/**
* 通过应用程序创建快捷方式
*
* @author jiqinlin
*
*/
public class ShortCutAction extends Activity implements OnClickListener{
private Button createShortcut=null; //创建快捷键按钮
private Button exit=null;//退出系统
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
createShortcut=(Button)findViewById(R.id.createShortcut);
exit=(Button)findViewById(R.id.exit);
createShortcut.setOnClickListener(this);
exit.setOnClickListener(this);
}
public void onClick(View v) {
//Button btn=(Button)v;
switch (v.getId()) {
case R.id.createShortcut:
//String title=getResources().getString(R.string.title);
Intent addIntent=new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
Parcelable icon=Intent.ShortcutIconResource.fromContext(this, R.drawable.png);
//获取快捷键的图标
Intent myIntent=new Intent(this, ShortCutAction.class);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "快捷方式");//快捷方式的标题
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);//快捷方式的图标
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, myIntent);//快捷方式的动作
sendBroadcast(addIntent);//发送广播
break;
case R.id.exit:
System.exit(0);
break;
}
}
}
本文转载自:安卓巴士 http://www.apkbus.com/forum.php?mod=viewthread&tid=12930&extra=
原理概述:
手机电池电量的获取在应用程序的开发中也很常用,Android系统中手机电池电量发生变化的消息是通过Intent广播来实现的,常用的Intent的Action有 Intent.ACTION_BATTERY_CHANGED(电池电量发生改变时)、Intent.ACTION_BATTERY_LOW(电池电量达到下限时)、和Intent.ACTION_BATTERY_OKAY(电池电量从低恢复到高时)。
当需要在程序中获取电池电量的信息时,需要为应用程序注册BroadcastReceiver组件,当特定的Action事件发生时,系统将会发出相应的广播,应用程序就可以通过BroadcastReceiver来接受广播,并进行相应的处理。
main.xml布局文件
java代码:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ToggleButton android:id="@+id/tb" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textOn="停止获取电量信息" android:textOff="获取电量信息" /> <TextView android:id="@+id/tv" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>
BatteryActivity类
java代码:
package eoe.demo;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.ToggleButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
public class BatteryActivity extends Activity {
private ToggleButton tb=null;
private TextView tv=null;
private BatteryReceiver receiver=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
receiver=new BatteryReceiver();
tv=(TextView)findViewById(R.id.tv);
tb=(ToggleButton)findViewById(R.id.tb);
tb.setOnCheckedChangeListener(new OnCheckedChangeListener(){
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
//获取电池电量
if(isChecked){
IntentFilter filter=new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
registerReceiver(receiver, filter);//注册BroadcastReceiver
}else {
//停止获取电池电量
unregisterReceiver(receiver);
tv.setText(null);
}
}
});
}
private class BatteryReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
int current=intent.getExtras().getInt("level");//获得当前电量
int total=intent.getExtras().getInt("scale");//获得总电量
int percent=current*100/total;
tv.setText("现在的电量是"+percent+"%。");
}
}
}
本文转载自:安卓巴士 http://www.apkbus.com/forum.php?mod=viewthread&tid=12927
2011年8月7日 #
安卓巴士开发1群105776293(未满)
安卓巴士开发2群84048564(未满)
安卓巴士开发3群160767382(未满)
机器人团队官方群152082960(未满)
安卓巴士网高校群2 ]146537495(未满)
安卓巴士(给力Android) 75061372(未满)
由于论坛建的十几个群已经满了,以上是安卓巴士的巴友建的群,大家可以加进去哈
www.apkbus.com 安卓巴士-android开发交流论坛
由于论坛群有限,只能加一个群,谢谢各位巴友,希望大家体谅
2011年6月21日 #
------文本框(TextView)
------列表(ListView)
------提示(Toast)
------编辑框(EditText)
------下拉列表(Spinner)
------自动提示(AutoCompleteTextView、MultiAutoCompleteTextView)
------日期和时间(DatePicker、TimePicker)
------按钮(Button)
------菜单(Menu,SubMenu,MenuItem)
------对话框(Dialog)
------图片视图(ImageView)
------带图标的按钮(ImageButton)
------拖动效果(Gallery)
------切换图片(ImageSwitcher)
------网格视图(GridView)
------文卷轴视图(ScrollView)
------进度条(ProgressBar)
------拖动条(SeekBar)
------状态栏提示(Notification、NotificationManager)
------对话框中的进度条(ProgressDialog)
------单项选择(RadioGroup、RadioButton)
2011年6月16日 #
|
很多网友转型Android开发或准备做一个Android开发者,到底做哪方面的好呢? 下面是安卓巴士给大家的一些建议:
1. 过去是J2EE、J2SE的开发者,这类传统的Java开发者可以考虑继续做Android应用开发,如果会SSH,可以做更好的服务性客户端等等。
2. 过去时J2ME的开发者,大部分可能都是做游戏出身的,考虑Android游戏开发相对比较理想。
3. 过去是C\C++程序员或有些基础,可以考虑Android应用开发,熟悉后可以做一些更深入的应用通过NDK,Android NDKr5还对STL部分特性做了支持,比较实用。
4. 过去是WinCE、Maemo或硬件相关的,可以考虑ROM定制,移植方面的,对于Android Framework层的学习是主要的。
5. 过去搞硬件的、单片机的可以试试Android ADK,有关ADK是什么Android开发网在以前的文章中介绍过,可以做出一些硬件配件来。
到底是做应用薪水高还是底层呢? 这里安卓巴士就形势而言应用挂广告,尤其是游戏效果会远比做底层和内核的好,国内较著名的愤怒的小鸟就是一个比较典型的例子,相对而言用户看到的是应 用,做底层的只能比较低调了,但做一款内核级的应用还是不错的。 |
2011年6月12日 #
2011年6月6日 #
2011年6月2日 #
2011年5月14日 #