Android的创造主屏幕上的快捷方式 [英] Android create shortcuts on the home screen

查看:160
本文介绍了Android的创造主屏幕上的快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我的心是搞砸了............我想要做的是:

Hi my mind is messed up............What I want to do is:

1)我是一个活动里面,有2个按钮。如果我点击第一个快捷方式在我的主屏幕上创建的。该快捷方式打开 HTML 页面,该页面已被previously下载的,所以我想它使用默认的浏览器,但我不希望使用互联网,因为我已经有该页面。

1) I'm inside an activity, there are 2 buttons. If I click the first one a shortcut is created in my home screen. The shortcut open an html page that has been previously downloaded, so I want it to use the default browser but I don't want to use internet cause I already have the page.

2)第二个按钮创建一个启动活动的另一捷径。我想传递给活动的一些额外的参数(如例如字符串)...........

2)The second button create another shortcut that starts an activity. And i want to pass to the activity some extra arguments (As strings for example)...........

是那些东西可能吗?我发现了一些环节,一些类似的问题,像<一个href="http://stackoverflow.com/questions/5676090/android-is-there-a-programming-way-to-create-a-web-shortcut-on-home-screen">Android:有没有一种编程方式来创建在主屏幕上网页快捷方式

Are those things possible? I found some link and some similar questions like Android: Is there a programming way to create a web shortcut on home screen

他们似乎是在回答我的问题,但有人告诉我,这code不是在所有设备上会的工作,那就是pcated德$ P $,而我想做的事情是不可能的... ......

They seem to be the answer to my question but someone told me that this code is not gonna work on all devices and that is deprecated and that what i want to do is not possible.......

这个技术是不推荐的。这是一个内部实现,Android SDK的一部分。它不会在所有的主屏幕上实现。它可能无法工作在Android上的所有过去的版本。它可能不会在Android的未来版本的工作,因为谷歌没有义务维护内部未公开的接口。请不要使用该

This technique is not recommended. This is an internal implementation, not part of the Android SDK. It will not work on all home screen implementations. It may not work on all past versions of Android. It may not work in future versions of Android, as Google is not obligated to maintain internal undocumented interfaces. Please do not use this

这意味着内部实现?那是code可信与否......帮我请.....

What means internal implementation? Is that code trustable or not.....help me pls.....

推荐答案

这个例子code使用无证接口(许可和意图)设置的快捷方式。作为人告诉你,这可能不会对所有的手机合作,并在未来的Andr​​oid版本可能会断裂。不这样做。

The example code uses undocumented interfaces (permission and intent) to install a shortcut. As "someone" told you, this may not work on all phones, and may break in future Android releases. Don't do it.

正确的方法是倾听来自家庭screen--的快捷方式的要求,意图过滤器,像这样在你的清单:

The correct way is to listen for a shortcut request from the home screen-- with an intent filter like so in your manifest:

<activity android:name=".ShortCutActivity" android:label="@string/shortcut_label">
  <intent-filter>
    <action android:name="android.intent.action.CREATE_SHORTCUT" />
    <category android:name="android.intent.category.DEFAULT" />
  </intent-filter>
</activity>

然后在接收意向的活动中,创建​​一个意图为您的快捷方式,并将其返回作为活动的结果。

Then in the activity that receives the intent, you create an intent for your shortcut and return it as the activity result.

// create shortcut if requested
ShortcutIconResource icon =
    Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);

Intent intent = new Intent();

Intent launchIntent = new Intent(this,ActivityToLaunch.class);

intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, someNickname());
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);

setResult(RESULT_OK, intent);

这篇关于Android的创造主屏幕上的快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆