1

Now, I want to make the device vibrate when device show result on screen

some parts of MainActivity.java

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); } 

How can I do this?

Thanks!

0

3 Answers 3

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

Note: Don't forget to include permission in AndroidManifest.xml file:

<uses-permission android:name="android.permission.VIBRATE"/> 
Sign up to request clarification or add additional context in comments.

Comments

2

Try this. Vibrate for 100 milliseconds

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

1 Comment

0

use this code when you receive results

Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(100); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.