我正在尝试为Android创建一个应用程序,我希望允许用户使用我的应用程序共享文本。
我的代码如下。请帮我找错。
我没有logcat消息,因为每当我在模拟器中运行sharer应用程序并点击分享按钮时它就会直接打开股票消息应用程序,尽管我的其他应用程序已安装在模拟器中,所以我不得不测试在我的手机上申请。
我为共享而创建的应用程序代码
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));
主要申请
明确声明
<activity
android:name="com.example.app.MainActivity"
android:label="@string/title_activity_main"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
MAINACTIVITY.JAVA的代码
Intent myintent = getIntent();
String action = myintent.getAction();
String type = myintent.getType();
if(Intent.ACTION_SEND.equals(action) && type !=null) {
if("text/plain".equals(type)) {
handleSendText(myintent);
}
}
void handleSendText(Intent intent) {
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText != null) {
editText.setText(sharedText);
}
}
请帮我找到错误,为什么我的应用程序和股票消息应用程序没有出现Intent Chooser。
答案 0 :(得分:0)
尝试在模拟器中运行它并使用调试器查找应用程序崩溃的位置然后在此处写入尝试使用捕获异常