android发送桌面快捷方式
来源:互联网 发布:老虎机h5源码 编辑:程序博客网 时间:2024/05/16 11:10
1、权限的设置
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
2、简单的布局
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/kj" android:text="测试快捷方式"/>
3、主要的Java代码
public class MainActivity extends AppCompatActivity { Button kj; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); kj = (Button)findViewById(R.id.kj); kj.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); String title = "标题"; Intent.ShortcutIconResource icon = Intent.ShortcutIconResource.fromContext(MainActivity.this,R.mipmap.ic_launcher_round); Intent shortcutIntent = new Intent(); shortcutIntent.setComponent(new ComponentName(getPackageName(),"com.example.dyw.testdesktop.MainActivity")); shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,title); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,icon); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,shortcutIntent); sendBroadcast(intent); } }); }}不废话,直接上代码,有错误,请多指教!!
阅读全文
1 0
- android发送桌面快捷方式
- android桌面添加快捷方式
- Android桌面快捷方式
- Android桌面快捷方式
- Android 桌面快捷方式操作
- android 桌面快捷方式
- Android桌面快捷方式
- android 创建桌面快捷方式
- Android添加桌面快捷方式
- Android 创建桌面快捷方式
- android创建桌面快捷方式
- Android 创建桌面快捷方式
- android 创建桌面快捷方式
- Android 创建桌面快捷方式
- Android创建桌面快捷方式
- android 创建桌面快捷方式
- Android 创建桌面快捷方式
- Android 创建桌面快捷方式
- caffe学习笔记11:图像数据转换为db(leveldb/lmdb)文件
- HTTP报文
- 欢迎使用CSDN-markdown编辑器
- 6.13
- mybatis的逆向工程
- android发送桌面快捷方式
- 线程池ThreadPoolExecutor的原理
- cocos_creator之Flabby Bird
- URI、URL、URN
- Git_init
- SSH整合之利用JSTL自定义标签制作DWR分页功能
- JSTL下载与配置
- 理解 node.js 的事件循环
- C语言中利用setjmp和longjmp做异常处理