听取意图ACTION_VIEW的活动

时间:2014-11-19 09:11:43

标签: android android-intent

我想在下面的setMovementMethod中打开自定义活动。

TextView tx = (TextView)findViewById(R.id.txtHelp);
tx.setText(Html.fromHtml(getString(R.string.help)));
tx.setMovementMethod(LinkMovementMethod.getInstance());

我的html定义了链接,当点击/按下时,我希望我的活动打开显示图像(取决于点击的链接)

我查看了这个帖子handle textview link click in my android app并尝试按照使用的答案。 这里我在manifest中的活动被定义为监听intent action.View。

<activity android:name="com.example.metermanager.ImagesActivity"                    
    android:screenOrientation="portrait">
    <intent-filter>
        <category android:name="android.intent.category.DEFAULT" />
        <action android:name="android.intent.action.VIEW" />
        <data android:scheme="com.example.metermanager" />  
    </intent-filter>

这是活动代码。

package com.example.metermanager;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class ImagesActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.images);

        String text= getIntent().getDataString();
        Log.e("link", text);

    }
}

但是单击该链接会导致下面的错误,但定义了intent的活动。

 11-19 03:17:04.827: E/InputEventReceiver(1409): Exception dispatching input event.
 11-19 03:17:04.827: E/MessageQueue-JNI(1409): Exception in MessageQueue callback: handleReceiveCallback
 11-19 03:17:04.867: E/MessageQueue-JNI(1409): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=here (has extras) }
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1632)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.app.Activity.startActivityForResult(Activity.java:3424)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.app.Activity.startActivityForResult(Activity.java:3385)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.app.Activity.startActivity(Activity.java:3627)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.app.Activity.startActivity(Activity.java:3595)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.text.style.URLSpan.onClick(URLSpan.java:62)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.text.method.LinkMovementMethod.onTouchEvent(LinkMovementMethod.java:217)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.widget.TextView.onTouchEvent(TextView.java:7713)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.View.dispatchTouchEvent(View.java:7706)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2068)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1515)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.app.Activity.dispatchTouchEvent(Activity.java:2458)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2016)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.View.dispatchPointerEvent(View.java:7886)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3954)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3833)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3449)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3418)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3525)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3426)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3582)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3449)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3418)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3426)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5602)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5582)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5553)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5682)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.os.MessageQueue.nativePollOnce(Native Method)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.os.MessageQueue.next(MessageQueue.java:138)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.os.Looper.loop(Looper.java:123)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at android.app.ActivityThread.main(ActivityThread.java:5017)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at java.lang.reflect.Method.invokeNative(Native Method)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at java.lang.reflect.Method.invoke(Method.java:515)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
 11-19 03:17:04.867: E/MessageQueue-JNI(1409):  at dalvik.system.NativeStart.main(Native Method)
 11-19 03:17:04.867:

为什么它不能正常工作?

罗纳德

2 个答案:

答案 0 :(得分:2)

您链接到活动的网址是什么。

您的数据架构声明似乎有误。

尝试

<data android:scheme="content" android:host="com.example.metermanager" />

而不是

<data android:scheme="com.example.metermanager" />

此外,您的链接不应该是

<a href="here">

<a href="content://com.example.metermanager/some_specific_data">

答案 1 :(得分:0)

帮助文本必须如下所示,它与ImagesActivity intent filter的匹配:

<string name="help">&lt;a href="com.example.metermanager://ImagesActivity">Start ImagesActivity&lt;/a></string>