SimpleImplicitIntentActivity.java
package com.example.ch02_simpleimplicitintent;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class SimpleImplicitIntentActivity extends Activity implements OnClickListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_simple_implicit_intent);
Button button1=(Button)findViewById(R.id.bt1);
button1.setOnClickListener(this );
}
public void onClick(View v)
{
switch (v.getId())
{
case R.id.bt1:
Uri myuri=Uri.parse("file:///sdcard0/hua.mp3");
Intent oneIntent=new Intent(Intent.ACTION_VIEW);
oneIntent.setDataAndType(myuri,"audio/mp3");
startActivity(oneIntent);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.simple_implicit_intent, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
activity_simple_implicit_intent.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.ch02_simpleimplicitintent.SimpleImplicitIntentActivity" >
<Button
android:id="@+id/bt1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/anniu"
android:textSize="20sp" />
</RelativeLayout>
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">SimpleImplicitIntent</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="anniu">选择</string>
</resources>
运行这程序后,为什么播放不了mp3?
但是我不用这个程序,就可以播放mp3
不知道代码哪里错了?请大神赐教