找回密码
 FreeOZ用户注册
查看: 1395|回复: 2
打印 上一主题 下一主题

[学习深造] How to install and run an apk file in android?

[复制链接]
跳转到指定楼层
1#
发表于 28-6-2013 08:54:20 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?FreeOZ用户注册

x
Good morning,

I am implementing auto update my application in Android using xamarin C#. I can install the application from sd card fine using this code.

        Intent intent = new Intent(Intent.ActionView);
        intent.SetDataAndType(Uri.FromFile(new Java.IO.File(localFileName)), "application/vnd.android.package-archive");
        HomeContext.StartActivity(intent);

But I can not do like google play store once install and allow the end user to run the installed application. How can I do it? Another question is how to add a shortcut to desktop by code?

TIA
回复  

使用道具 举报

2#
 楼主| 发表于 28-6-2013 09:47:08 | 只看该作者
I managed to get open application to run button shown after install. Here is the code.

        Intent intent = new Intent(Intent.ActionView);
        intent.SetDataAndType(Uri.FromFile(new Java.IO.File(localFileName)), "application/vnd.android.package-archive");
        intent.SetFlags(ActivityFlags.NewTask);
        HomeContext.StartActivity(intent);

评分

参与人数 1威望 +20 收起 理由
cais + 20 谢谢分享!

查看全部评分

回复  

使用道具 举报

3#
 楼主| 发表于 28-6-2013 11:58:01 | 只看该作者
本帖最后由 DDD888 于 28-6-2013 12:15 编辑

I found a method to install the shortcut on desktop.

Add this line into AndroidManifest.xml file.
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"></uses-permission>

Here is the code.

        var shortcutIntent = new Intent();
        shortcutIntent.SetComponent(new ComponentName(this, Java.Lang.Class.FromType(typeof(ActivityHomeScreen))));

        shortcutIntent.AddFlags(ActivityFlags.NewTask);
        shortcutIntent.AddFlags(ActivityFlags.ClearTop);

        Intent putShortCutIntent = new Intent();
        putShortCutIntent.PutExtra(Intent.ExtraShortcutIntent, shortcutIntent);

        // Sets the custom shortcut's title
        putShortCutIntent.PutExtra(Intent.ExtraShortcutName,  "test");
        putShortCutIntent.PutExtra("duplicate", false);
        putShortCutIntent.PutExtra(Intent.ExtraShortcutIconResource, Intent.ShortcutIconResource.FromContext(this, Resource.Drawable.Icon));
        putShortCutIntent.SetAction("com.android.launcher.action.INSTALL_SHORTCUT");
        SendBroadcast(putShortCutIntent);

评分

参与人数 1威望 +20 收起 理由
cais + 20 谢谢分享!

查看全部评分

回复  

使用道具 举报

您需要登录后才可以回帖 登录 | FreeOZ用户注册

本版积分规则

小黑屋|手机版|Archiver|FreeOZ论坛

GMT+10, 12-9-2026 21:23 , Processed in 0.012333 second(s), 19 queries , Gzip On, Redis On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表