我正在尝试获取片段中 mp3 文件的资源 ID,但我不知道如何执行此操作。以下代码为资源 ID 返回零。是的,该文件在原始目录中。(我正在使用 ActionBarSherlock,但我不确定这是否重要。)
public class NavigationFragment extends SherlockFragment {
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
View nav =inflater.inflate(R.layout.navigation, container, false);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
try {
int resourceID = getResources().getIdentifier("bell01", "raw", "com.webnation.yogatest");
Log.d("We're Here", "resourceID =" + resourceID);
bell = MediaPlayer.create(getActivity(), resourceID);
} catch (Exception e) {
// TODO Auto-generated catch block
Log.d("Exception", e.toString());
}
} //onActivityCreated
}
清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.webnation.yogatest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="15" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Sherlock" >
<activity
android:name="com.webnation.yogatest.YogaTestActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".EulaActivity"
android:label="@string/title_eula_activity" >
</activity>
</application>
</manifest>