有图标的主屏幕快捷方式 [英] Homescreen shortcuts with icons

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

问题描述

我试图在Android编程方式创建主屏幕快捷方式。到目前为止,我已经能够添加快捷方式本身具有以下code:

Am trying to create a homescreen shortcut programmatically on android. So far I've been able to add the shortcut itself with the following code:

Intent shortcutIntent = new Intent();
    shortcutIntent.setClassName(mContext, mContext.getClass().getName());
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
shortcutIntent.putExtra("someParameter", "HelloWorld 123");
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Shortcut Name 123");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, R.drawable.icon);
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
mContext.sendBroadcast(addIntent);

不过,该快捷方式利用我的资源默认的图标安装。不过,我想从我的网站,并添加图标,快捷方式获取的图标。 首先,我需要下载这个快捷方式。在我有这个做了,并且图标在SD卡为例假设,我一直无法设置一个可绘制图标。

But, the shortcut is installed using the default icon in my resources. However, I would like to fetch icons from my website and adding an icon to the shortcut. First, I need to download this shortcut. Under the assumption that I have this done, and the icon is on the sdcard for example, I have been unable to set an drawable icon.

下面code:

try {
        Uri contentURI = Uri.parse("http://mnt/sdcard/mytest/test.png");        
            ContentResolver cr = mContext.getContentResolver();
            InputStream in;

    in = cr.openInputStream(contentURI);
    BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize=8;
        Bitmap thumb = BitmapFactory.decodeStream(in,null,options);
        Intent shortcutIntent = new Intent();
    shortcutIntent.setClassName(mContext, mContext.getClass().getName());
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    shortcutIntent.putExtra("someParameter", "HelloWorld 123");
    Intent addIntent = new Intent();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Shortcut Name 123");
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, thumb);
    addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    mContext.sendBroadcast(addIntent);

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

该文件确实存在,我已经验证了利用亚行外壳......这片code显示了以下错误:

The file definitely exist and I've verified that using adb shell... This piece of code shows the following error:

10-13 16:11:31.184: WARN/System.err(23273): java.io.FileNotFoundException: No content provider: /mnt/sdcard/mytest/test.png

我是什么做错了吗?

What am I doing wrong?

感谢

推荐答案

正在试图让位来自本地资源(通过使用内容提供商)。

You are trying to get bitmap from local resources (by using content provider).

从服务器上下载的位图,你应该遵循这样的:

To download Bitmap from server you should follow this:

<一个href="http://stackoverflow.com/questions/6463673/why-is-this-image-bitmap-not-downloading-in-android/6463727#6463727">Why这是位图图像没有下载在Android中?

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

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