Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Vibrator;

public class Main {
    public static void vibrate(Context context, int duration) {
        if (hasVibrationPermission(context)) {
            ((Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE)).vibrate(duration);
        }
    }

    public static boolean hasVibrationPermission(Context context) {
        // temporary workaround until https://github.com/robolectric/robolectric/pull/2047 is released
        try {
            return (context.getPackageManager().checkPermission(Manifest.permission.VIBRATE,
                    context.getPackageName()) == PackageManager.PERMISSION_GRANTED);
        } catch (NullPointerException e) {
            return false;
        }
    }
}