【发布时间】:2016-11-18 16:28:09
【问题描述】:
我想从其他应用分享 URL 并将其添加到 EditText 字段中
清单:
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
活动:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et1=(EditText)findViewById(R.id.et1);
Bundle extras = getIntent().getExtras();
String value1 = extras.getString(Intent.EXTRA_TEXT);
et1.setText(value1);
但是当我尝试关闭它运行应用程序时,我做错了什么?我在共享列表中看到我的应用,所以清单还不错
添加:字符串通道的 LogCat 错误
【问题讨论】:
-
使用 LogCat 检查与您的应用关联的 Java 堆栈跟踪:stackoverflow.com/questions/23353173/…
-
您的 Activity 的
onCreate()中可能存在严重错误,我们不知道,因为代码不在问题中。有合适的setContentView()电话吗?是否有(成功的)findViewById()呼叫EditText?setText()是在这些之后而不是之前等等。您应该分享更多代码。 (当然,按照建议从 LogCat 中检查并分享崩溃日志。) -
我编辑并添加了完整代码,但我认为一切正常,编辑 logcat 警告
标签: java android parameter-passing intentfilter