Java 如何在对话框的子类中使用按钮单击时创建选择器
使用此代码通过创建选择器共享音频文件,但不工作 公共类ActionDialog扩展对话框{Java 如何在对话框的子类中使用按钮单击时创建选择器,java,android,android-intent,Java,Android,Android Intent,使用此代码通过创建选择器共享音频文件,但不工作 公共类ActionDialog扩展对话框{ static String sSongTitle=""; static String sSongPath = ""; static File fSongFile ; public ActionDialog(final Context context, Message response) { super(context); // Inflate our UI from its XML l
static String sSongTitle="";
static String sSongPath = "";
static File fSongFile ;
public ActionDialog(final Context context, Message response) {
super(context);
// Inflate our UI from its XML layout description.
setContentView(R.layout.after_save_action);
setTitle(R.string.alert_title_success);
((Button)findViewById(R.id.button_share))
.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Uri StringUri = Uri.fromFile(new File(sSongPath));
Intent intent = new Intent(android.content.Intent.ACTION_SEND, StringUri);
Intent in = new Intent(android.content.Intent.ACTION_SEND, StringUri, context, null);
intent.setType("audio/*");
startActivity(Intent.createChooser(in, "select any from the list:"));//getting error here as create method startActivity(Intent)
}
});
}
}你的意图是意图而不是我的意图 Uri是stringUri,但您提到ed是stringUri。。 你能发布完整的代码吗。。若要查看任何错误,请参见此 代码 @凌驾
protected void onCreate(Bundle savedInstanceState)
{
你面临的问题是什么?你能把子类的完整代码放进去吗Dailog@Brontok:我在创建方法StartActivityContent时收到错误。您在何处声明iShare变量?它可以为null。像这样的代码段在上下文之外很难调试。您的确切异常是什么?您应该检查该异常的其余部分,会有提示w为什么活动无法启动。@Alex:很抱歉,它的目的是。setTypeaudio/*这段代码也给出了相同的错误。我得到了解决方案。我将创建一个扩展活动的类,在manisfest中,我将主题设置为dialog,并使我的内容正常工作。感谢您的支持
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
((Button) findViewById(R.id.button_share))
.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Uri stringUri = Uri.fromFile(new File(""));
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);// intent for sharing
sendIntent.putExtra(Intent.EXTRA_TEXT, stringurl);
sendIntent.setType("audio/*");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, StringTitle);
startActivity(sendIntent);// getting error
// as create
// method
// startActivity(Intent)
}
});
}