My flashlight app works with the S2 S3 and several other android phones no where close to as advanced as the S1 but for some reason can't turn on the S1s flash also this problem has been reported on the droid X and several other droids anyone familiar with making these compatible. Code is below
public class FlashLightActivity extends Activity {
private Camera mCamera;
private Boolean mFlashlight = false;
private Boolean sound = true;
private ImageButton button;
private static MediaPlayer mediaPlayer;
boolean flashInstalled = true;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_flashlight);
AdView ad = (AdView) findViewById(R.id.adView);
ad.loadAd(new AdRequest());
button = (ImageButton) findViewById(R.id.onoff);
mediaPlayer = new MediaPlayer();
Context context = this;
PackageManager pm = context.getPackageManager();
// if device support camera?
if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
Log.e("err", "Device has no camera!");
Toast.makeText(this, "Your device does not have FlashLight",
Toast.LENGTH_LONG).show();
return;
}
try {
// Checking if flashplayer is available
ApplicationInfo ai = pm.getApplicationInfo("com.adobe.flashplayer",
0);
if (ai != null)
flashInstalled = true;
} catch (NameNotFoundException e) {
flashInstalled = false;
}
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (mCamera != null) {
Parameters params = mCamera.getParameters();
if (mFlashlight) {
params.setFlashMode(Parameters.FLASH_MODE_OFF);
button.setImageResource(R.drawable.off_icon);
mFlashlight = false;
} else {
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
button.setImageResource(R.drawable.on_icon);
mediaPlayer = MediaPlayer.create(
FlashLightActivity.this, R.raw.boom);
if (mediaPlayer != null && mediaPlayer.isPlaying()) {
mediaPlayer.stop();
}
if (sound) {
mediaPlayer.stop();
mediaPlayer = null;
} else {
mediaPlayer.start();
}
v.setKeepScreenOn(true);
mFlashlight = true;
}
mCamera.setParameters(params);
}
}
});
}
@Override
public void onResume() {
super.onResume();
SharedPreferences preferences = getSharedPreferences("pref",
MODE_PRIVATE);
sound = preferences.getBoolean("sound", false);
if (mFlashlight) {
button.setImageResource(R.drawable.on_icon);
} else {
button.setImageResource(R.drawable.off_icon);
}
try {
this.mCamera = Camera.open();
} catch (Exception e) {
}
}
@Override
public void onPause() {
super.onPause();
if (this.mCamera != null) {
this.mCamera.release();
this.mCamera = null;
}
this.mFlashlight = false;
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_tabs, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_settings:
Intent menuIntent = new Intent(this, MenuActivity.class);
startActivity(menuIntent);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}