读书人

圆桌面快捷方式

发布时间: 2012-06-27 14:20:09 作者: rapoo

桌面快捷方式

自己做了一个简单的邮件发送示例,手机可以正常发送

其中Intent.EXTRA_SHORTCUT_NAME对应快捷方式的名字;

Intent.EXTRA_SHORTCUT_ICON_RESOURCE对应快捷方式执行的图标;

Intent.EXTRA_SHORTCUT_INTENT对应快捷方式的事件

android专门提供了Intent.ShortcutResource.fromcontent来创建快捷方式的图标,

最后通过setREsult来返回,构建一个快捷方式

?

public class ShortCutsActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);// 要添加的快捷方式的IntentIntent addShortcut;if (getIntent().getAction().equals(Intent.ACTION_CREATE_SHORTCUT)) {addShortcut = new Intent();addShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "发送邮件");// 构建快捷方式中专门的图标Parcelable icon = Intent.ShortcutIconResource.fromContext(this,R.drawable.ic_launcher);// 添加快捷方式图标addShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);// 构建快捷方式执行的IntentIntent mailto = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:591449193@qq.com"));// 添加快捷方式IntentaddShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, mailto);// 正常setResult(RESULT_OK, addShortcut);} else {// 取消setResult(RESULT_CANCELED);}finish();}}

?

然后在mainfest.xml中引用

    <application        android:icon="@drawable/ic_launcher"        android:label="@string/app_name" >        <activity            android:label="@string/app_name"            android:name=".ShortCutsActivity" >            <intent-filter >                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />                <action android:name="android.intent.action.CREATE_SHORTCUT" />            </intent-filter>        </activity>    </application>

?

读书人网 >移动开发

热点推荐