下面列出了android.content.Intent#getFloatArrayExtra ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) switch (requestCode) {
case CODE_FOR_CROP: {
float[] points = data.getFloatArrayExtra(Constant.CLIP_POINTS);
String name = data.getStringExtra(Constant.PROFILE_NAME);
insertDataToDB(new ProfileEntity(1, name, points[0], points[1], points[2], points[3]));
new SweetAlertDialog(ProfileActivity.this, SweetAlertDialog.SUCCESS_TYPE).setTitleText("Image Cropped").setConfirmText("Ok").show();
profiles.add(new Profile(name, points[0], points[1], points[2], points[3]));
mProfileAdapter.notifyDataSetChanged();
break;
}
case Constant.CODE_FOR_SCREEN_CAPTURE: {
MediaProjectionHelper.setMediaProjectionManager(mMediaProjectionManager);
MediaProjectionHelper.setScreenshotPermission(data);
startService(mScreenshotIntent);
finish();
break;
}
}
}
/**
* updates sensors data
* @param intent the update intent from Service
*/
private void updateSensorsData(Intent intent){
float accelerometerMatrix[] = intent.getFloatArrayExtra(ACCELEROMETER_KEY);
Log.d(TAG,"Accelerometer x = "+accelerometerMatrix[0]+" y = "+accelerometerMatrix[1]+" z = "+accelerometerMatrix[2]);
accelerometerValues.add(accelerometerMatrix);
float gyroscopeMatrix[] = intent.getFloatArrayExtra(GYROSCOPE_KEY);
Log.d(TAG,"Gyroscope x = "+gyroscopeMatrix[0]+" y = "+gyroscopeMatrix[1]+" z = "+gyroscopeMatrix[2]);
gyroscopeValues.add(gyroscopeMatrix);
}
protected void onActivityResult(int requestCode,
int resultCode, Intent data) {
if (requestCode == TTS_DATA_CHECK) {
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
tts = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
ttsIsInit = true;
if (tts.isLanguageAvailable(Locale.UK) >= 0)
tts.setLanguage(Locale.UK);
tts.setPitch(0.8f);
tts.setSpeechRate(1.1f);
speak();
}
}
});
} else {
Intent installVoice = new Intent(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installVoice);
}
}
// Listing 14-3: Finding the results of a speech recognition request
if (requestCode == VOICE_RECOGNITION && resultCode == RESULT_OK) {
ArrayList<String> results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
float[] confidence = data.getFloatArrayExtra(RecognizerIntent.EXTRA_CONFIDENCE_SCORES);
// TODO Do something with the recognized voice strings
}
}
/**
* Utility to get the position extras from an intent.
*
* @param intent the intent.
* @return the position as accuracy, speed, bearing.
*/
public static float[] getPositionExtras(Intent intent) {
if (intent == null) {
return null;
}
float[] positionExtras = intent.getFloatArrayExtra(GPS_SERVICE_POSITION_EXTRAS);
return positionExtras;
}
public static float[] getFloatArrayExtra(Intent intent, String name) {
if (!hasIntent(intent) || !hasExtra(intent, name)) return null;
return intent.getFloatArrayExtra(name);
}