将音频分享给Whats应用

时间:2013-05-11 21:17:59

标签: android audio whatsapp

它被分配到一个按钮,该按钮在短按时播放声音并在长按时共享音频。该程序没有错误,运行正常..但当我分享音频..它以可识别的格式通过电子邮件发送,其名称为2130968577号,我无法与最新的应用分享。原始音频采用mp3格式。

并且不要将我引导到像这样的其他帖子......那个问题没有得到解决

Intent.ACTION_SEND Whatsapp

 button1.setOnLongClickListener(new View.OnLongClickListener() {

 @Override
 public boolean onLongClick(View arg0) {
 Intent share = new Intent(Intent.ACTION_SEND);
 share.setType("audio/mp3");
 Uri uri = Uri.parse("android.resource://" + getPackageName()+ "/raw/" +R.raw.splash);
 share.putExtra(Intent.EXTRA_STREAM, uri);
 startActivity(Intent.createChooser(share, "Share Sound File"));
 return true;
 }
 });
 }

整个代码:

package com.example.buttonclicksound;

import com.example.buttonclicksound.MainActivity;

import android.graphics.drawable.AnimationDrawable;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends Activity {
protected static final String TAG = "MainActivity";
Button button1;
MediaPlayer mPlayer;
AnimationDrawable lightsAnimation;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // No title bar is set for the activity
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    // Full screen is set for the Window
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main);
    ImageView lights = (ImageView) findViewById(R.id.imageView1);
    lightsAnimation = (AnimationDrawable) lights.getDrawable();

    button1 = (Button) findViewById(R.id.button1);
    mPlayer = MediaPlayer.create(MainActivity.this, R.raw.splash);

    button1.setLongClickable(true);
    button1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            try {

                mPlayer.start();
                mPlayer.setLooping(false);

            } catch (Exception e) {
                Log.e("ButtonListenerActivity", "error: " +   e.getMessage(),
                        e);
            }

        }

    });

    button1.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View arg0) {
            Intent share = new Intent(Intent.ACTION_SEND);
            share.setType("audio/mp3");

            Uri uri = Uri.parse("android.resource://" + getPackageName()
                    + "/raw/" + R.raw.splash);
            share.putExtra(Intent.EXTRA_STREAM, uri);
            startActivity(Intent.createChooser(share, "Share Sound File"));

            return true;
        }

    });
}

@Override
public void onWindowFocusChanged(boolean hasFocus) {

    super.onWindowFocusChanged(hasFocus);

    lightsAnimation.start();

}

protected void onDestroy() {
    super.onDestroy();
    // TODO Auto-generated method stub
    if (mPlayer != null) {
        mPlayer.release();
        mPlayer = null;
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

}

0 个答案:

没有答案