中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

Android應(yīng)用創(chuàng)建手機(jī)桌面快捷方式

2018-07-20    來源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬Linux鏡像隨意使用
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
android:orientation="vertical">
    <Button 
        android:id="@+id/shortCut_btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
    android:text="快捷方式"
        />
    <Button
        android:id="@+id/exit_btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="退出應(yīng)用" />
</LinearLayout>
---------------------------------------------------------------------------
public class MainActivity extends Activity {
private Button shortCutBtn;
private Button exitBtn;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
shortCutBtn = (Button) findViewById(R.id.shortCut_btn);
exitBtn = (Button) findViewById(R.id.exit_btn);
/**創(chuàng)建 快捷方式*/
shortCutBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
/**創(chuàng)建或刪除ShortCut的Intent中設(shè)置Action為:com.android.launcher.action.INSTALL_SHORTCUT
* 另外刪除快捷方式為:com.android.launcher.action.UNINSTALL_SHORTCUT
*/
Intent addIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
/**Android專門提供了Intent.ShortcutIconResource.fromContext來創(chuàng)建快捷方式的圖標(biāo),最后通過setResult來返回*/
Parcelable icon = Intent.ShortcutIconResource.fromContext(MainActivity.this, R.drawable.ic_launcher);
Intent myIntent = new Intent(MainActivity.this, MainActivity.class);
/**應(yīng)用名稱*/
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "應(yīng)用名稱");
/**應(yīng)用圖片*/
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
/**應(yīng)用啟動(dòng)Intent*/
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, myIntent);
sendBroadcast(addIntent);
}
});
/**退出應(yīng)用*/
exitBtn.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
System.exit(0);
}
});
}


}

標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:一個(gè)封裝好的CSV文件操作C#類代碼

下一篇:C#轉(zhuǎn)換漢字為漢語拼音全拼