`
龙哥IT
  • 浏览: 237421 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
文章分类
社区版块
存档分类
最新评论

桌面快捷方式

 
阅读更多

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

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

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

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

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

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

 

public class ShortCutsActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// 要添加的快捷方式的Intent
		Intent 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);
			// 构建快捷方式执行的Intent
			Intent mailto = new Intent(Intent.ACTION_SENDTO, Uri
					.parse("mailto:591449193@qq.com"));
			// 添加快捷方式Intent
			addShortcut.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>

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics