Android
Project: Android_Vibration:
Android
Project: Android_Vibration
Activity_main
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:onClick="vibrateButton"
android:layout_alignParentTop="true"
android:layout_marginLeft="106dp"
android:layout_marginTop="168dp"
android:text="Vibrate" />
</RelativeLayout>
Main.java
package
com.sattar.vibreate;
import
android.app.Activity;
import android.content.Context;
import
android.os.Bundle;
import
android.os.Vibrator;
import
android.view.Menu;
import
android.view.View;
public class
MainActivity extends Activity {
// String vibratorService =
Context.VIBRATOR_SERVICE;
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void vibrateButton(View
view) {
String
vibratorService = Context.VIBRATOR_SERVICE;
Vibrator
vibrator = (Vibrator) getSystemService(vibratorService);
long[] pattern =
{ 1000, 2000, 4000, 8000, 16000 };
vibrator.vibrate(pattern,
0); // Execute vibration pattern.
vibrator.vibrate(1000);
// Vibrate for 1 second.
vibrator.cancel();
}
@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;
}
}
Manifest.xml
<?xml version="1.0"
encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sattar.vibreate"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.VIBRATE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.sattar.vibreate.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>
</manifest>
If You Face
any problem Comment here, I will try to solution, thanks
No comments:
Post a Comment