爱玺玺

爱玺玺的生活日记本。wx:lb87626

android创建快捷方式

需要权限,注意这个权限自带的没有,手动复制粘贴过去。

<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>


代码:

package com.example.createlaunchico;


import android.support.v7.app.ActionBarActivity;

import android.content.Intent;

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

import android.net.Uri;

import android.os.Bundle;

import android.view.Menu;

import android.view.MenuItem;

import android.view.View;



public class MainActivity extends ActionBarActivity {


    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

    }


    public void addshortcut(View v){

    //给创建图标的广播站发送广播

    Intent intent=new Intent("com.android.launcher.action.INSTALL_SHORTCUT");

    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "拨打110");

    //需要发送需要创建的图片属性

    Bitmap value=BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);

   intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, value);

    //发送需要执行的操作

    Intent intent2=new Intent();

    intent2.setAction(Intent.ACTION_CALL);

    intent2.setData(Uri.parse("tel:"+110));

    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent2);

    sendBroadcast(intent);

    }

}


样式:

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="com.example.createlaunchico"

    android:versionCode="1"

    android:versionName="1.0" >

    

    <uses-sdk

        android:minSdkVersion="8"

        android:targetSdkVersion="21" />

    <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>


    <application

        android:allowBackup="true"

        android:icon="@drawable/ic_launcher"

        android:label="@string/app_name"

        android:theme="@style/AppTheme" >

        <activity

            android:name=".MainActivity"

            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>


</manifest>


发表评论:

Powered By Z-BlogPHP 1.4 Deeplue Build 150101

Copyright Your WebSite.Some Rights Reserved.

蜀ICP备11021721号-5