android 音乐播放器添加音乐分享功能

1.文件alps\packages\apps\Music\src\com\android\music\TrackBrowserActivity.java添加:

//cbk.music
    private void share() {
    
	MusicLogUtils.d(TAG, "share() ");

	String [] cols = new String [] { MediaStore.Audio.Media._ID,MediaStore.Audio.Media.DATA, MediaStore.Audio.Media.ALBUM_ID };
	StringBuilder where = new StringBuilder();

	long file_index =mSelectedId;
	MusicLogUtils.d(TAG, "share() file_index =" +file_index);	
	
	where.append(MediaStore.Audio.Media._ID + " IN (");
	where.append(file_index);
	where.append(")");

	Cursor c = MusicUtils.query(this, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, cols,
	        where.toString(), null, null);
	c.moveToFirst();

	String filename = c.getString(1);
	File file = new File(filename);

	c.close();	

	MusicLogUtils.d(TAG, "share() filename =" +filename);
	MusicLogUtils.d(TAG, "share() file =" +file);

	Uri uri = Uri.fromFile(file);
	String mimeType = MediaFile.getMimeTypeForFile(filename);

	MusicLogUtils.d(TAG, "share() mimeType =" +mimeType);

	//String name = "/storage/sdcard0/cbk/Starmobiletone3.mp3";
	//File f = new File(name);	

	Intent intent=new Intent(Intent.ACTION_SEND);
	//intent.setType("audio/mpeg");//("audio/3gpp");//reference to MIMETYPE_3GPP_AUDIO in FileInfo.java 
	intent.setType(mimeType);
	intent.putExtra(Intent.EXTRA_SUBJECT, "Send audio file");
	intent.putExtra(Intent.EXTRA_STREAM, uri);

	try {
	    startActivity(Intent.createChooser(intent, "Send audio file"));
	} catch (android.content.ActivityNotFoundException e) {
	    MusicLogUtils.d(TAG, "Cannot find any activity", e);
	}		
    }


你可能感兴趣的:(android 音乐播放器添加音乐分享功能)