如何在html按钮点击发送图像网址到Android应用程序?

时间:2016-03-29 09:09:09

标签: android html android-studio

您好,我想在我的网站上点击图片(可能是图片周围的链接),将该图片加载到我的Android应用中:

我已经通过以下链接打开我的应用程序:

<a href="allplayer://site.com">Test link</a>

这在我的manfest文件中:

<activity
    android:name=".MainActivity"
    android:label="@string/title_activity_main" 
    android:exported="false">
    <intent-filter>

        <data  android:scheme="allplayer" />

        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

但我想要更改图片,以便我的应用可以加载不同的图片,具体取决于您点击的图片。

以某种方式将图片网址从我的网页传递到我的Android应用

图片链接可能是这样的:

<a href="www.example.com" rel="image001"><img src="http://www.example.com/image001.jpg"  /></a>

单击时: 它应该打开我的应用程序并加载图像。

这是我用来从网络成功加载任何图像的代码:

    ImageView bindImage = (ImageView)findViewById(R.id.ImageView01);
    String pathToFile = "http://www.example.com//image.jpg";
    DownloadImageWithURLTask downloadTask = new DownloadImageWithURLTask(bindImage);
    downloadTask.execute(pathToFile);

    // load image from url #2
private class DownloadImageWithURLTask extends AsyncTask<String, Void, Bitmap> {
        ImageView bmImage;
        public DownloadImageWithURLTask(ImageView bmImage) {
            this.bmImage = bmImage;
        }

提前致谢!

2 个答案:

答案 0 :(得分:1)

尝试以下

ImageView bindImage = (ImageView)findViewById(R.id.ImageView01);

    Intent intent = getIntent();
    String pathToFile = intent.getDataString().toString();
    DownloadImageWithURLTask downloadTask = new DownloadImageWithURLTask(bindImage);
    downloadTask.execute(pathToFile);

    // load image from url #2
private class DownloadImageWithURLTask extends AsyncTask<String, Void, Bitmap> {
        ImageView bmImage;
        public DownloadImageWithURLTask(ImageView bmImage) {
            this.bmImage = bmImage;
        }

答案 1 :(得分:0)

onCreate of receiver activity

if (Intent.ACTION_VIEW.equals(intent.getAction())) {
            Uri uri = intent.getData();
            Set names = uri.getQueryParameterNames();               
            if (names.contains("image")) {
                String path= uri.getQueryParameter("image");
                ....                    
            }
        }