网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

android快捷方式,android快捷指令

android的桌面快捷方式如今还需不需要创建

Android在桌面上生成快捷方式有两种情况,一种是直接在桌面直接生成;一种是长按桌面,在弹出的快捷菜单中生成。

我们提供的服务有:做网站、成都网站建设、微信公众号开发、网站优化、网站认证、富宁ssl等。为成百上千家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的富宁网站制作公司

第一个是通过广播(Broadcast)的形式向Luncher发送请求生成快捷方式的。在网上找到关于这方面的注册信息。

!--   

Code highlighting produced by Actipro CodeHighlighter (freeware)   

--!--设置wallpapaer的activity --  

!-- Intent received used to install shortcuts from other applications --          

receiver              

android:name="com.android.launcher2.InstallShortcutReceiver"              

android:permission="com.android.launcher.permission.INSTALL_SHORTCUT"              

intent-filter                  

action android:name="com.android.launcher.action.INSTALL_SHORTCUT" /              

/intent-filter          

/receiver 

可以看出,要在桌面上创建快捷方式就需要权限了:

android:permission="com.android.launcher.permission.INSTALL_SHORTCUT。

所以在我们的manifest.xml文件中,我们需要加入下面这段话:

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

下面就是代码层的实现:

假如我在一个activity中创建一个创建快捷方式的方法:createShortCut();

public void createShortCut(){   

//创建快捷方式的Intent                   

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

//不允许重复创建                   

shortcutintent.putExtra("duplicate", false);                   

//需要现实的名称                   

shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.shortcutname));   

//快捷图片                  

Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.icon);   

shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);   

//点击快捷图片,运行的程序主入口                   

shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(getApplicationContext() , EnterActivity.class));                   

//发送广播。OK                   

sendBroadcast(shortcutintent);   

}

二、长按桌面弹出的桌面快捷方式创建

如何在添加到一个SHORTCUTS列表中,就是你长按桌面弹出来的那个东东。

首先在注册activity时,需要添加一个action为android.intent.action.CREATE_SHOERTCUT的intentFilter.如下所示:

activity android:name="ShortCutTest"              

intent-filter                  

action android:name="android.intent.action.CREATE_SHORTCUT"/              

/intent-filter          

/activity 

接下来就是就是设置快捷方式的图标、名称、事件等属性。这里图表的生成,android里提供了专门的方法来生成。

public class ShortCutTest extends Activity{       

@Override      

protected void onCreate(Bundle savedInstanceState) {           

// TODO Auto-generated method stub           

super.onCreate(savedInstanceState);       

createShortCut();

}   

public void createShortCut(){           

Intent addShortCut;   

//判断是否需要添加快捷方式           

if(getIntent().getAction().equals(Intent.ACTION_CREATE_SHORTCUT)){               

addShortCut = new Intent();               

//快捷方式的名称               

addShortCut.putExtra(Intent.EXTRA_SHORTCUT_NAME , "我的快捷方式");               

//显示的图片              

Parcelable icon = ShortcutIconResource.fromContext(this, R.drawable.icon);               

addShortCut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);   

//快捷方式激活的activity,需要执行的intent,自己定义               

addShortCut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent());               

//OK,生成               

setResult(RESULT_OK, addShortCut);   

}else{               

 //取消               

setResult(RESULT_CANCELED);   

}   

}   

}

Android创建桌面快捷方式(兼容Android 8.0)

在Android O原生桌面上,按照传统创建快捷方式的形式,是不会产生快捷方式的。

传统方式如下:

从Android 7.1(API 25)开始,新增了ShortcutManager,可以对桌面久按应用图标弹出的快捷方式进行管理。

但是,Android 7.1上直接往桌面上添加快捷方式依然是使用上面说到的这种旧方式,但是Android O上,Google应该是想通过比较统一的接口来管理桌面快捷方式了,所以摒弃了这种形式,转而使用ShortcutManager进行管理。所以API 26上,ShortcutManager进行管理。所以API 26上,ShortcutManager新增了对Pinned Shortcuts(固定快捷方式)的管理。

官文:

Apps can pin an existing shortcut (either static or dynamic) or an entirely new shortcut to a supported launcher programatically using requestPinShortcut(ShortcutInfo, IntentSender). You pass two arguments into this method:

A ShortcutInfo object – If the shortcut already exists, this object should contain only the shortcut’s ID. Otherwise, the new ShortcutInfo object must contain an ID, an intent, and a short label for the new shortcut.

A PendingIntent object – This intent represents the callback that your app receives if the shortcut is successfully pinned to the device’s launcher.

Note: If the user doesn’t allow the shortcut to be pinned to the launcher, the pinning process fails, and the Intent object that is passed into this PendingIntent object isn’t executed.

Note: Due to background execution limits introduced in Android O, it’s best to use a manifest-declared receiver to receive a callback.

Also, to prevent other apps from invoking the receiver, add the attribute assignment android:exported=”false” to the receiver’s manifest entry.

Note: As you add logic in your app to make requests to pin shortcuts, keep in mind that not all launchers support pinning of shortcuts. To determine whether your app can complete this process on a particular device, check the return value of isRequestPinShortcutSupported(). Based on this return value, you might decide to hide the option in your app that allows users to pin a shortcut.

Note: See also the support library APIs isRequestPinShortcutSupported(Context) and requestPinShortcut(Context, ShortcutInfoCompat, IntentSender), which works on Android versions lower than O by falling back to the deprecated private intent com.android.launcher.action.INSTALL_SHORTCUT.

译:

应用程序可以使用requestPinShortcut(ShortcutInfo,IntentSender)将现有的快捷方式(静态或动态)或全新的快捷方式固定到支持的启动器。你通过这个方法的两个参数:

ShortcutInfo对象 - 如果快捷方式已存在,则该对象应仅包含快捷方式的ID。否则,新的ShortcutInfo对象必须包含新快捷方式的ID,意图和短标签。

PendingIntent对象 - 此意图表示如果快捷方式成功固定到设备的启动器,您的应用程序将收到回调。

注意:如果用户不允许将快捷方式固定在启动器上,则固定进程将失败,并且未执行传入此PendingIntent对象的Intent对象。

注意:由于Android O中引入的后台执行限制,最好使用清单声明的接收器来接收回调。

另外,为了防止其他应用程序调用接收器,将属性赋值android:exported =“false”添加到接收者的清单条目中。

注意:当您在应用程序中添加逻辑以引导快捷方式时,请记住,并非所有启动器都支持固定快捷方式。 要确定您的应用程序是否可以在特定设备上完成此过程,请检查isRequestPinShortcutSupported()的返回值。 根据此返回值,您可以决定隐藏您应用程序中允许用户固定快捷方式的选项。

注意:另请参见支持库API isRequestPinShortcutSupported(Context)和requestPinShortcut(Context,ShortcutInfoCompat,IntentSender),它可以在低于O的Android版本上运行,因为它们回落到不推荐使用的私有意图com.android.launcher.action.INSTALL_SHORTCUT。

ShortcutManager类在API level 26上,增加了对isRequestPinShortcutSupported、requestPinShortcut、createShortcutResultIntent三个方法。说明如下:

1.isRequestPinShortcutSupported

官文:

Return TRUE if the app is running on a device whose default launcher supports requestPinShortcut(ShortcutInfo, IntentSender).

The return value may change in subsequent calls if the user changes the default launcher app.

Note: See also the support library counterpart isRequestPinShortcutSupported(Context), which supports Android versions lower than O using the legacy private intent com.android.launcher.action.INSTALL_SHORTCUT.

译:

如果默认桌面支持requestPinShortcut(ShortcutInfo,IntentSender)方法,则返回TRUE。

如果用户更改默认启动程序应用程序,返回值可能会在后续调用中更改。

注意:另请参见支持库对应的isRequestPinShortcutSupported(Context),在低于O的Android版本,它支持使用旧的私有意图com.android.launcher.action.INSTALL_SHORTCUT。

2.requestPinShortcut

官文:

Request to create a pinned shortcut. The default launcher will receive this request and ask the user for approval. If the user approves it, the shortcut will be created, and resultIntent will be sent. If a request is denied by the user, however, no response will be sent to the caller.

Only apps with a foreground activity or a foreground service can call this method. Otherwise, it’ll throw IllegalStateException.

It’s up to the launcher to decide how to handle previous pending requests when the same package calls this API multiple times in a row. One possible strategy is to ignore any previous requests.

Note: See also the support library counterpart requestPinShortcut(Context, ShortcutInfoCompat, IntentSender), which supports Android versions lower than O using the legacy private intent com.android.launcher.action.INSTALL_SHORTCUT.

译:

请求创建固定的快捷方式。默认启动器将收到该请求,并要求用户批准。如果用户批准,将创建快捷方式,并且将发送resultIntent。但是,如果请求被用户拒绝,则不会向呼叫者发送任何响应。

只有具有前台活动或前台服务的应用程序才能调用此方法。否则,它将抛出IllegalStateException。

当同一个软件包连续多次调用该API时,由开发人员决定如何处理以前的待处理请求。一个可能的策略是忽略任何先前的请求。

注意:另请参见支持库对应件requestPinShortcut(Context,ShortcutInfoCompat,IntentSender),在低于O的Android版本,它支持使用旧的私有意图com.android.launcher.action.INSTALL_SHORTCUT。

3.createShortcutResultIntent

官文:

Returns an Intent which can be used by the default launcher to pin a shortcut containing the given ShortcutInfo. This method should be used by an Activity to set a result in response to ACTION_CREATE_SHORTCUT.

译:

返回默认启动器可以使用的Intent来固定包含给定的ShortcutInfo的快捷方式。 Activity应该使用此方法来设置响应ACTION_CREATE_SHORTCUT的结果。

根据弹窗提示可以看出,可以通过拖动这个图标往桌面上添加快捷方式,可以通过点击自动添加按键,系统给你在桌面的默认位置上添加。

添加后,桌面上会出现如图所示的图标:

回调用到的Receiver:

打印log发现,onReceive如图官方文档所说,点击弹框自动添加按键后,会得到回调。但实践发现,如果桌面上已经添加了图标,当再次调用requestPinShortcut进行添加时,onReceive会在调用requestPinShortcut的时候,直接被回调,而且弹框也会弹出来。

在以上三个方法官方介绍中,官方提示我们,可以使用Android support库的ShortcutManagerCompat进行快捷方式的版本适配。于是,在build.gradle中添加依赖进行尝试:

android安装后快捷键移动或删除

android安装后快捷键移动或删除如下

1, 创建/*** 为程序创建桌面快捷方式*/private void addShortcut(){undefined// 给桌面发送一个广播Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");// 设置属性//快捷方式的名称shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));shortcut.putExtra("duplicate", false);

//不允许重复创建//快捷方式的图标ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);

// 设置快捷方式执行的操作//指定当前的Activity为快捷方式启动的对象: 如 com.everest.video.VideoPlayer//注意: ComponentName的第二个参数必须加上点号(.),否则快捷方式无法启动相应程序ComponentName comp = new ComponentName(this.getPackageName(), "."+this.getLocalClassName());shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp))。

android中怎么在桌面创建其他应用快捷方式

Activity里添加这样的一个方法:

/**

* 创建快捷方式

*/

public void createDeskShortCut() {

Log.i("coder", "------createShortCut--------");

// 创建快捷方式的Intent

Intent shortcutIntent = new Intent(

"com.android.launcher.action.INSTALL_SHORTCUT");

// 不允许重复创建

shortcutIntent.putExtra("duplicate", false);

// 需要现实的名称

shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME,

getString(R.string.app_name));

// 快捷图片

Parcelable icon = Intent.ShortcutIconResource.fromContext(

getApplicationContext(), R.drawable.ic_launcher);

shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);

Intent intent = new Intent(getApplicationContext(),

AndroidLayoutActivity.class);

// 点击快捷图片,运行的程序主入口

shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);

// 发送广播。OK

sendBroadcast(shortcutIntent);

}

如果只是添加这些代码,当卸装应用程序的时候又会发现存在一个问题就是应用程序虽然卸载了,可是桌面上的快捷方式并未卸载。呵呵,其实只要设置对应启动进入的那个Intent加上这么下面的两个属性就是表明与应用绑定了。

// 下面两个属性是为了当应用程序卸载时桌面上的快捷方式会删除

intent.setAction("android.intent.action.MAIN");

intent.addCategory("android.intent.category.LAUNCHER");

给上完整的代码:

package com.jiahui.layout;

import android.app.Activity;

import android.content.Context;

import android.content.Intent;

import android.content.SharedPreferences;

import android.os.Bundle;

import android.os.Parcelable;

import android.util.Log;

public class AndroidLayoutActivity extendsActivity {

/**Called when the activity is first created. */

@Override

publicvoid onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.view_personal_info);

SharedPreferencespreferences = getSharedPreferences("first",

Context.MODE_PRIVATE);

booleanisFirst = preferences.getBoolean("isfrist", true);

if(isFirst) {

createDeskShortCut();

}

SharedPreferences.Editoreditor = preferences.edit();

editor.putBoolean("isfrist",false);

editor.commit();

}

/**

* 创建快捷方式

*/

publicvoid createDeskShortCut() {

Log.i("coder","------createShortCut--------");

//创建快捷方式的Intent

IntentshortcutIntent = new Intent(

"com.android.launcher.action.INSTALL_SHORTCUT");

//不允许重复创建

shortcutIntent.putExtra("duplicate",false);

//需要现实的名称

shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME,

getString(R.string.app_name));

//快捷图片

Parcelableicon = Intent.ShortcutIconResource.fromContext(

getApplicationContext(),R.drawable.ic_launcher);

shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,icon);

Intentintent = new Intent(getApplicationContext(),

AndroidLayoutActivity.class);

//下面两个属性是为了当应用程序卸载时桌面 上的快捷方式会删除

intent.setAction("android.intent.action.MAIN");

intent.addCategory("android.intent.category.LAUNCHER");

//点击快捷图片,运行的程序主入口

shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,intent);

//发送广播。OK

sendBroadcast(shortcutIntent);

}

}

4

千万别忘记在AndroidManifest.xml加上下面的这个权限:

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

Android 手机主界面最下面的那一栏又快捷方式的叫什么栏啊?怎么设置啊?

是托盘,操作方法如下:

1、首先唤醒手机,打开手机【设置】,如下图所示。

2、在设置中找到【显示】并进入,如下图所示。

3、在显示页面中,找到【导航条】进入,如下图所示。

4、然后在打开的页面中,可以看到如下图所示,部分安卓手机是可以通过开启/关闭按钮隐藏/显示导航栏的。

5、点击按钮顺序,可以按照个人习惯调整导航栏按钮方向,如下图所示就完成了。


网页题目:android快捷方式,android快捷指令
本文网址:http://bjjierui.cn/article/dscisoo.html

其他资讯