如何在对话框的子类内单击按钮时使用“创建选择器”

时间:2013-10-29 08:52:41

标签: java android android-intent

使用此代码通过创建选择器共享音频文件但不工作...

公共类ActionDialog扩展了Dialog {

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)

            }
        });
}

}

2 个答案:

答案 0 :(得分:0)

你的意图是意图不是ishare Uri是stringUri,但你提到ed为StringUri .. 你可以发布整个代码..看看错误,如果有的话

答案 1 :(得分:0)

看到这个 代码

@覆盖

protected void onCreate(Bundle savedInstanceState)

{

    // 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)
                }
            });

}
相关问题