How to add vibration and ringtone when launching the application home page

I want to add vibration, and the music to play on my application’s home page means that when my application vibrates it and plays the ringtone until I press the button to go to another action, it means that it stops the vibration and sound after as I go to another activity ... my manifest file is below.

 <?xml version="1.0" encoding="utf-8"?>
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.androidpeople.tab"
   android:versionCode="1"
   android:versionName="1.0">
     <uses-permission android:name="android.permission.INTERNET" />


      <application android:icon="@drawable/icon" android:label="@string/app_name"
                        android:debuggable= "true">
            <uses-library android:name="com.google.android.maps" />
            <activity android:name=".SplashScreen"
              android:label="@string/app_name">
            <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            </activity>
             <activity android:name="currentlocmap"/>
             <activity android:name="filter"/>
             <activity android:name="keywordsearch"/>
             <activity android:name="keywordxmlparsing" />
             <activity android:name="Artistspacedetailview" />
             <activity android:name="loadingimage"/>
             <activity android:name="keywordpagetabs"/>
             <activity android:name="filterpagetabs"/>
             <activity android:name="artistspacedetailviewTab"/>


              </application>
              <supports-screens android:anyDensity="true"
                android:largeScreens="true"
                android:normalScreens="true"
                android:smallScreens="true" />

+3
source share
2 answers

So first put your ringtone / sound clip in the raw folder under res / raw. In this example, I will call it sound_clip.

import android.media.MediaPlayer;
import android.os.Vibrator;

private Vibrator vib;
private MediaPlayer mp;
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mp = MediaPlayer.create(this, R.raw.sound_clip);
    vib = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    vib.vibrate(500);
    mp.start();
    Button button = (Button) findViewById(R.id.button);
    button.setOnClickListener(this);
}

public void onClick(View v){
    mp.stop();
    vib.cancel();
}
+10
source
Vibrator myVib = (Vibrator) this.getSystemService(VIBRATOR_SERVICE);
myVib.vibrate(Long milliseconds);

use this program for users

<uses-permission android:name="android.permission.VIBRATE"/>

http://davanum.wordpress.com/2007/12/29/android-videomusic-player-sample-from-local-disk-as-well-as-remote-urls/

+5

All Articles