我的应用程序强制关闭我不知道为什么。它应该做的就是在前台振动时振动,如果不是则停止,但是当我在手机上启动它时,它会强制关闭。我手动在清单中添加了有关振动器使用的行。也许这就是问题所在。我必须对它进行任何其他操作才能对应用程序有效?
我的清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.kevinboonemidi"
android:versionCode="1"
android:versionName="1.0" >
<permission android:name="android.permission.VIBRATE" ></permission>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.haptic.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
我的代码:
package com.example.haptic_sof;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import com.example.kevinboonemidi.R;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Vibrator;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
public class MainActivity extends Activity
{
protected Vibrator v = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
long pwmCycles[];
pwmCycles = new long[4];
v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
long[] pattern = { 0, 200, 10 };
v.vibrate(pattern, 0);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
protected void onPause(){
super.onPause();
v.cancel();
}
protected void onStop()
{
super.onStop();
v.cancel();
}
}