充气报警故障

时间:2013-11-09 07:32:44

标签: android alarm android-inflate

我正试图让一个充气的布局在收到警报时出现。到目前为止,父视图正在出现,但膨胀的布局不是?你能告诉我哪里出错了吗?我的设置就像我的时间充气器一样,但它不适合我。

我的代码:

import java.io.IOException;    
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

public class AlarmReceiver extends Activity {
    private MediaPlayer mPlayer;
    private WakeLock mWakeLock;

    @SuppressWarnings("deprecation")
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "my wakelock");
        mWakeLock.acquire();
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(
                WindowManager.LayoutParams.FLAG_FULLSCREEN
                        | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                        | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON,
                WindowManager.LayoutParams.FLAG_FULLSCREEN
                        | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                        | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

        setContentView(R.layout.sundayopen);
        final Dialog stoplaydialog = new Dialog(this);
        final RelativeLayout stoplay = (RelativeLayout) getLayoutInflater()
                .inflate(R.layout.stoplay, null);


stoplaydialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

stoplaydialog.setContentView(stoplay);

stoplaydialog.show();
        ImageButton stopalarm = (ImageButton) stoplay
                .findViewById(R.id.stopalarm);
        stopalarm.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                mPlayer.stop();
                finish();
                stoplaydialog.dismiss();
                return;

            }
        });
        PlaySound(this, getAlarmUri());
    }

    private void PlaySound(Context context, Uri alert) {
        mPlayer = new MediaPlayer();
        try {
            mPlayer.setDataSource(context, alert);
            final AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
            if (am.getStreamVolume(AudioManager.STREAM_ALARM) != 0)
                ;
            {
                mPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
                mPlayer.prepare();
                mPlayer.start();
            }

        } catch (IOException e) {
            Log.i("AlaramReciever", "no audio file");
        }
    }

    // Get an alarm sound. If none set, try notification, Otherwise, ringtone.
    private Uri getAlarmUri() {
        Uri alert = RingtoneManager
                .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        if (alert == null) {
            alert = RingtoneManager
                    .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            if (alert == null) {
                alert = RingtoneManager
                        .getDefaultUri(RingtoneManager.TYPE_RINGTONE);
            }
        }
        return alert;
    }

    protected void onStop() {
        super.onStop();
        mWakeLock.release();

    }
}

谢谢。

0 个答案:

没有答案