2016-10-26 9 views
1

지금, 나는이 장치가 진동을 할 때 화면에 장치 쇼 결과 나는이 작업을 수행 할 수있는 방법 MainActivity.java기기가 화면에 표시 될 때 Android 기기를 진동시키는 방법은 무엇인가요?

public void onResult(String result) { 
    String tres = "\n"; 
    try { 
     JSONObject j = new JSONObject(result); 
     JSONObject j1 = j.getJSONObject("status"); 
     int j2 = j1.getInt("code"); 
     if(j2 == 0){ 
      JSONObject metadata = j.getJSONObject("metadata"); 
      if (metadata.has("custom_files")) { 
       JSONArray musics = metadata.getJSONArray("custom_files"); 
       for(int i=0; i<musics.length(); i++) { 
        JSONObject tt = (JSONObject) musics.get(i); 
        String title = tt.getString("title"); 
        tres = tres + (i+1) + ". Title: " + title + "\n"; 
       } 
      } 
     }else{ 
      tres = result; 
     } 
    } catch (JSONException e) { 
     tres = result; 
     e.printStackTrace(); 
    } 

    mResult.setText(tres); 
} 

일부?

감사합니다.

답변

6
Vibrator v = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); 
// Vibrate for 1 seconds 
v.vibrate(1000); 

참고 :

<uses-permission android:name="android.permission.VIBRATE"/> 
:
가의 AndroidManifest.xml 파일에 권한을 포함하는 것을 잊지 마세요
2

시도해보십시오. 100 밀리 초

Vibrator v = (Vibrator) this.mContext.getSystemService(Context.VIBRATOR_SERVICE); 
v.vibrate(100); 
+0

http://stackoverflow.com/a/13950364/1979882 – Vyacheslav

0

사용하면 결과

Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); 
      vibrator.vibrate(100); 
를받을이 코드를 진동