mt6735 音乐播放器歌曲列表,长按任何一首歌曲,增加“Share”菜单来分...
时间:10-02
整理:3721RD
点击:
[Audio App]音乐播放器歌曲列表,长按任何一首歌曲,增加“Share”菜单来分享歌曲
[DESCRIPTION]
音乐播放器歌曲列表,长按任何一首歌曲,弹出的选项菜单增加“Share”菜单来分享歌曲
[SOLUTION]
请修改TrackBrowserActivity.java
添加:
import android.media.MediaFile;
import android.util.Log;
import java.io.File;
在class TrackBrowserActivity中添加:
private static final int SHARE_AS = CHILD_MENU_BASE + 8;
private void share() {
Intent intent;
boolean forbidden = false;
mTrackCursor.moveToPosition(mSelectedPosition);
int id_idx ;
try {
id_idx = mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.PlaylistsColumns.DATA);
Log.d(TAG,"ffhh Share id_idx1=" + id_idx);
// id_idx =
mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members.AUDIO_ID);
} catch (IllegalArgumentException ex) {
id_idx = mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Media._ID);
Log.d(TAG,"ffhh Share id_idx2=" + id_idx);
}
String filename=mTrackCursor.getString(id_idx);
Log.d(TAG,"ffhh Share file name=" + filename);
// send single file
Log.d(TAG, "ffhh Share a single file");
String mimeType = MediaFile.getMimeTypeBySuffix(filename);
Log.d(TAG,"ffhh Share file name=" + filename + " **minType="+ mimeType);
// if (!forbidden)
{
intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType(mimeType);
Uri uri = Uri.fROMFile(new File(filename));
intent.putExtra(Intent.EXTRA_STREAM, uri);
Log.d(TAG, "ffhh Share Uri file: " + uri);
Log.d(TAG, "ffhh Share file mimetype: " + mimeType);
try {
startActivity(Intent.createChooser(intent, "share file?"));
} catch (android.content.ActivityNotFoundException e) {
Log.e(TAG, "Cannot find any activity", e);
// TODO add a toast to notify user
}
}
}
修改 public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo
menuInfoIn) {
在
if (isMusic(mTrackCursor)) {
menu.add(0, SEARCH, 0, R.string.search_title);
}
之后添加:
menu.add(0, SHARE_AS, 0, "Share as..");
修改 public boolean onContextItEMSelected(MenuItem item) {
添加:
case SHARE_AS:{
share();
return true;
}
[DESCRIPTION]
音乐播放器歌曲列表,长按任何一首歌曲,弹出的选项菜单增加“Share”菜单来分享歌曲
[SOLUTION]
请修改TrackBrowserActivity.java
添加:
import android.media.MediaFile;
import android.util.Log;
import java.io.File;
在class TrackBrowserActivity中添加:
private static final int SHARE_AS = CHILD_MENU_BASE + 8;
private void share() {
Intent intent;
boolean forbidden = false;
mTrackCursor.moveToPosition(mSelectedPosition);
int id_idx ;
try {
id_idx = mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.PlaylistsColumns.DATA);
Log.d(TAG,"ffhh Share id_idx1=" + id_idx);
// id_idx =
mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members.AUDIO_ID);
} catch (IllegalArgumentException ex) {
id_idx = mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Media._ID);
Log.d(TAG,"ffhh Share id_idx2=" + id_idx);
}
String filename=mTrackCursor.getString(id_idx);
Log.d(TAG,"ffhh Share file name=" + filename);
// send single file
Log.d(TAG, "ffhh Share a single file");
String mimeType = MediaFile.getMimeTypeBySuffix(filename);
Log.d(TAG,"ffhh Share file name=" + filename + " **minType="+ mimeType);
// if (!forbidden)
{
intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType(mimeType);
Uri uri = Uri.fROMFile(new File(filename));
intent.putExtra(Intent.EXTRA_STREAM, uri);
Log.d(TAG, "ffhh Share Uri file: " + uri);
Log.d(TAG, "ffhh Share file mimetype: " + mimeType);
try {
startActivity(Intent.createChooser(intent, "share file?"));
} catch (android.content.ActivityNotFoundException e) {
Log.e(TAG, "Cannot find any activity", e);
// TODO add a toast to notify user
}
}
}
修改 public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo
menuInfoIn) {
在
if (isMusic(mTrackCursor)) {
menu.add(0, SEARCH, 0, R.string.search_title);
}
之后添加:
menu.add(0, SHARE_AS, 0, "Share as..");
修改 public boolean onContextItEMSelected(MenuItem item) {
添加:
case SHARE_AS:{
share();
return true;
}