Domanda

I have given permissions for VIBRATE in the manifest. In my app I have the following code

    @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_parent_control);

    vibe = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE) ;
    vibe.vibrate(100);}

But nothing happens. Any ideas why? This is probably something really stupid. I did check to see if my phone was vibrating and it was in a different app.

Galaxy s3 ICS-4.0.4

Here is the Manifest

import android.os.Vibrator;...


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="Jino.parentcontrol"
android:versionCode="1"
android:versionName="1.0" >




<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="15" />

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

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <uses-library android:name="com.google.android.maps" />
    <activity
        android:name=".ParentControl"
        android:screenOrientation="portrait"
        android:label="@string/title_activity_parent_control" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

and here is my full onCreate function.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_parent_control);

    vibe = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE) ;
    vibe.vibrate(100);
    Connection_Status=0;

    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    // If the adapter is null, then Bluetooth is not supported
    if (mBluetoothAdapter == null) {
        Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
        finish();
        return;
    }





    mapview = new MapView(ParentControl.this, getString(R.string.debug_mapview_apikey));
    mapview.setClickable(true);
    mapview.setBuiltInZoomControls(true);
    mapview.setSatellite(true);

    mapcontrol = mapview.getController();
    mapcontrol.setZoom(19);

    myLocationManager = (LocationManager) getSystemService( Context.LOCATION_SERVICE );

    me=new MyCustomLocationOverlay(this, mapview);
    mapview.getOverlays().add(me);


    me.enableMyLocation();
    me.enableCompass();

    CenterMap();

    RelativeLayout layout= (RelativeLayout) findViewById(R.id.my_layout);
    layout.addView(mapview);

    probar=(ProgressBar) findViewById(R.id.progressBar);

    probar.setMax(100);
    probar.setBackgroundColor(Color.BLACK);
    probar.setProgress(100);

}
È stato utile?

Soluzione

Needed to turn up Haptic feedback in the Sound -> Vibration Intensity menu.

Altri suggerimenti

I tested your code. Works perfect without any issues.

I have following:

In manifest:

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

In mainactivity

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Vibrator vibe = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE) ;
    vibe.vibrate(100);
}

Try to increase the vibrate time perhaps?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top