1

它被分配给一个按钮,该按钮在短按时播放声音并在长按时共享音频。该程序没有错误并且运行良好..但是当我共享音频时..它以可识别的格式通过电子邮件发送,名称为2130968577,我无法与whats app共享。原始音频为 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;
}

}
4

0 回答 0