An warware: yadda ake jijjiga android

Ana iya yin rawar jiki ta na'urar Android da tsari ta hanyar Android SDK. Ana iya amfani da wannan fasalin ta hanyoyi da yawa kamar samar da ra'ayi mai ma'ana don ayyukan mai amfani, faษ—akar da mai amfani da hankali game da sabuntawa, ko ma baiwa 'yan wasan ฦ™warewa ฦ™warewa mai zurfi. Yana da kayan aiki mai mahimmanci kuma mai amfani don ฦ™irฦ™irar ฦ™arin ฦ™warewar mai amfani.

Babban aikin da ke cikin wannan aiki shine sabis na tsarin Android da ake kira Vibrator, wanda ke sarrafa injin girgiza na'urar. Dole ne a ba da wasu izini a cikin bayanan aikace-aikacen don amfani da wannan aikin, kuma kayan aikin na'urar dole ne su goyi bayansa.

Kafin mu ci gaba, bari mu nutse cikin mahimman batutuwa.

Sabis na Vibrator

Sabis ษ—in tsarin Android, Vibrator, yana taimaka mana mu yi amfani da aikin jijjiga a cikin na'urorin Android ta hanyar shirye-shirye a cikin aikace-aikacen mu. Don kiran wannan hanyar, muna buฦ™atar jefa sabis ษ—in tsarin zuwa abu mai Vibrator ta amfani da getSystemService().

// Get instance of Vibrator from current Context
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

Abun Vibrator yana ba da ฦดan hanyoyi don sarrafa ayyukan girgiza, gami da girgiza() da soke().

Izinin Android

Kafin mu iya amfani da sabis na vibrator, muna buฦ™atar ayyana izinin VIBRATE a cikin bayanan aikace-aikacen mu. Wannan yana sanar da masu amfani cewa aikace-aikacen na iya sarrafa injin girgiza yayin aiki.

<manifest ...>
    <uses-permission android_name="android.permission.VIBRATE"/>
    ...
</manifest>

Ana aiwatar da Vibration

Bayan saita izini masu dacewa, zamu iya amfani da hanyar vibrate() da muka ambata a baya don sanya na'urar ta girgiza.

// Start without a delay
// Vibrate for 100 milliseconds
// Sleep for 1000 milliseconds

long[] pattern = {0, 100, 1000};

// The '0' here means to repeat indefinitely
// '-1' would play the vibration once
v.vibrate(pattern, 0);

Wannan lambar tana sa na'urar ta yi rawar jiki har na miliyon 100 sannan ta tsaya tsayin miliyon 1000, tana maimaita wannan tsari har abada.

Idan kuna son dakatar da jijjiga, zaku iya yin hakan ta hanyar kiran hanyar soke ().

v.cancel();

Waษ—annan su ne mahimman matakai don aiwatar da rawar jiki a cikin tsarin Android. Haษ—a waษ—annan abubuwan haษ—in gwiwa na iya taimakawa haษ“aka ฦ™warewar mai amfani da ku, ฦ™irฦ™irar ฦ™arin aikace-aikacen hulษ—a.

Ka tuna cewa ba duk na'urori ne ke goyan bayan wannan aikin ba, kuma ya kamata mu yi la'akari da yanayi inda girgiza ya kamata ya zama na zaษ“i, samar da saiti ga masu amfani waษ—anda suka fi son kashe ra'ayin haptic.

A ฦ™arshe, Android tana ba da aiki don samun dama da sarrafa kayan aikin na'urar kamar injin girgiza. A matsayin masu haษ“akawa, za mu iya amfani da waษ—annan ayyukan don haษ“aka hulษ—ar mai amfani na aikace-aikacen mu. Koyaya, yana da mahimmanci a yi amfani da waษ—annan albarkatu cikin hikima, kiyaye abubuwan da mai amfani ke so a tsakiya.

Shafi posts:

Leave a Comment