0
android:我想讓手機響鈴並顯示聯繫人信息(就像真正的電話一樣)。當用戶點擊音量提高鍵3次,並保持在第三次點擊。我希望即使在鎖定屏幕的情況下也是如此。這可能嗎?Android:手機在點擊音量鍵模式後響鈴
謝謝!
我做了這個改變,我試圖在我的星系s6上運行,並且應用程序崩潰。它會運行,但只要它打開它崩潰。 這裏是代碼
package example.org.getaway;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
public class MainActivity extends AppCompatActivity {
static int number_of_times_volume_button_pressed = 0;
final MediaPlayer iphonering = MediaPlayer.create(this, R.raw.iphone);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
final MediaPlayer iphonering = MediaPlayer.create(this, R.raw.iphone);
if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)){
if(number_of_times_volume_button_pressed==3)
{
iphonering.start();
number_of_times_volume_button_pressed=0;
}else
{
number_of_times_volume_button_pressed++;
}
}
return true;
}
}
你可以請張貼在運行應用程序,你所得到的錯誤。 –