0

我正在尝试制作一个只有一个按钮的应用程序。当你按下它会播放声音,当你长按它时,它会给你分享的选项。该应用程序正常运行,没有任何错误..但共享选项无法打开。当你长按它时,按钮什么也不做。

  package com.example.buttonclicksound;

  import com.example.buttonclicksound.MainActivity;

  import android.graphics.drawable.AnimationDrawable;
  import android.media.MediaPlayer;
  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.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 OnLongClickListener() {
            public boolean onLongClick(View v) {

                shareIt();
                return true;
            }

            private void shareIt() {
                //sharing implementation here
                Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
                sharingIntent.setType("audio/mPlayer");
                }
        });



}

@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;
}

}

它非常令人沮丧..一直在努力工作..而Daam的事情就是行不通。

经过进一步的工作..我现在被困在这个..发送通过框打开..我选择电子邮件..但我得到的只是一封空白电子邮件

  private void shareIt(MediaPlayer mPlayer) {
                //sharing implementation here
     Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("audio/mp3");
sharingIntent.putExtra(Intent.EXTRA_SUBJECT,"Ringtone      File:"+getResources().getResourceEntryName(mPlayer)+".mp3");
sharingIntent.putExtra(Intent.EXTRA_TEXT,"Ringtone File : "+getResources().getResourceEntryName(mPlayer)+".mp3");
                sharingIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse("android.resource://com.my.android.soundfiles/"+mPlayer));
sharingIntent.putExtra("sms_body","Ringtone File : "+getResources().getResourceEntryName(mPlayer)+".mp3");
                startActivity(Intent.createChooser(sharingIntent, "Share Sound File"));

                }
        });
4

1 回答 1

0

您没有对您的sharingIntent 做任何事情,只是创建它。

于 2013-05-11T18:34:51.150 回答