注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

沉默蜂B4A安卓编程

国内资料最全的B4A资料库

 
 
 

日志

 
 

快捷方式添加到你的Android应用程序  

2015-08-30 12:43:14|  分类: B4A例程 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

Android allows the user to add desktop shortcuts to any application.
Pressing on such a shortcut is exactly the same as starting your application from the applications list.

However it is also possible to create custom shortcuts which will have a custom behavior. For example start a different activity or start your application in a different mode.
In order to add a custom shortcut you should create a dedicated "shortcut Activity". This activity will be started when the user adds your shortcut from the shortcuts list. The activity should return an intent as the result which will later start the application.
The following screenshots demonstrate the shortcut behavior on a Honeycomb device. It should be similar to regular devices:

Shortcuts list:
[?IMG]

Desktop:
[?IMG]

Our application launched from the shortcut:
[?IMG]

You should edit the manifest file and set an intent filter to the shortcut activity. This tells the OS that your application includes a custom activity.
Please read the section about manual modification of the manifest file here.

This is the shortcut activity declaration in the manifest file of the example program:
Code:
<activity android:windowSoftInputMode="stateHidden" android:launchMode="singleTop" android:name="shortcutactivity" 
            android:
label="Add Shortcut" android:screenOrientation="unspecified">
         <
intent-filter>
                <action android:name=
"android.intent.action.CREATE_SHORTCUT"/>
                <category android:name=
"android.intent.category.DEFAULT"/>
            </
intent-filter>
      </
activity>
android:name is the lower cased name of the shortcut activity.
android:label is the title that will appear in the shortcuts list.

The code of the shortcut activity is:
Code:
Sub Activity_Create(FirstTime As Boolean)
 
Dim shortcutIntent As Intent
 shortcutIntent.Initialize(
"""")
 shortcutIntent.SetComponent(
"anywheresoftware.b4a.samples.test/.main"'<--- change to match your package name / and target activity.
 shortcutIntent.PutExtra("from_shortcut"True)
 
Dim in As Intent
 
in.Initialize("""")
 
in.PutExtra("android.intent.extra.shortcut.INTENT", shortcutIntent)
 
in.PutExtra("android.intent.extra.shortcut.NAME""Shortcut Test")
 
in.PutExtra("android.intent.extra.shortcut.ICON"LoadBitmap(File.DirAssets, "small_logo.png"))
   
 
Activity.SetActivityResult(-1in)
 
Activity.Finish
End Sub
You should change the line with the comment to match your package name and target activity. Note that the syntax is: package_name/.activity and activity should be lower cased.

The last step that should be done is to check in our main activity whether our program was launched from the shortcut:
Code:
Sub Activity_Resume
   
Dim in As Intent
   
in = Activity.GetStartingIntent
   
Log(in)
   
If in.HasExtra("from_shortcut"AND in.GetExtra("from_shortcut") = True Then
      
Msgbox("Launched from shortcut""")
   
End If
End Sub
  评论这张
 
阅读(115)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017