Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

First App dev. help

OP natan.p

7th June 2014, 07:07 PM   |  #1  
OP Junior Member
Thanks Meter: 0
 
12 posts
Join Date:Joined: May 2014
Hello I'm Trying to learn my firsy app (Flash Lifght app) ..

I understand that i need to give app permissions etc.
Can some one expaine me how do i need to do that when im opening new project.
I what is code or the file i need to paste the code..

Sorry for bad english and thanks for helping!
7th June 2014, 07:53 PM   |  #2  
MasterAwesome's Avatar
Senior Member
Thanks Meter: 810
 
1,143 posts
Join Date:Joined: Jun 2013
More
Quote:
Originally Posted by natan.p

Hello I'm Trying to learn my firsy app (Flash Lifght app) ..

I understand that i need to give app permissions etc.
Can some one expaine me how do i need to do that when im opening new project.
I what is code or the file i need to paste the code..

Sorry for bad english and thanks for helping!

You need to set the permissions in the AndroidManifest.xml file add a uses permission and under that class an android:name= *camera*

Regards
MasterAwesome
7th June 2014, 08:05 PM   |  #3  
OP Junior Member
Thanks Meter: 0
 
12 posts
Join Date:Joined: May 2014
Quote:
Originally Posted by MasterAwesome

You need to set the permissions in the AndroidManifest.xml file add a uses permission and under that class an android:name= *camera*

Regards
MasterAwesome

I have an error i found tutorial how create flash light app i cop all codes ti manifest etc files but i have error with the java file........
the error: The public type FlashlightActivity must be defined in its own file.

the code: Press Control + F and search this line public class FlashlightActivity extends Activity {
PHP Code:
package com.natan.flashlight;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.util.Log;
import android.widget.ToggleButton;

/**
 * @author Prabu 
 * July 30 2013
 * @version 1.0
 * 
 */

public class FlashlightActivity extends Activity // <--------------------------------------- There are the error..
     
private Camera camera;
     private 
ToggleButton button;
     private final 
Context context this;

     
//@see android.app.Activity#onStop()
     
@Override
     
protected void onStop() {
      
super.onStop();
      if (
camera != null) {
       
camera.release();
      }
     }

     
/**
      * @see android.app.Activity#onCreate(android.os.Bundle)
      */
     
@Override
     
public void onCreate(Bundle savedInstanceState) {
      
super.onCreate(savedInstanceState);
      
//setContentView(R.layout.flashlight);
      
button = (ToggleButtonfindViewById(R.id.togglebutton);
      
      final 
PackageManager pm context.getPackageManager();
      if(!
isCameraSupported(pm)){
       
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
       
alertDialog.setTitle("No Camera");
          
alertDialog.setMessage("The device's doesn't support camera.");
          
alertDialog.setButton(RESULT_OK"OK", new DialogInterface.OnClickListener() {
              public 
void onClick(final DialogInterface dialog, final int which) { 
               
Log.e("err""The device's doesn't support camera.");
              }
           });
       
alertDialog.show();
      }
      
camera Camera.open();
     }
     public 
void onToggleClicked(View view) {
      
PackageManager pm=context.getPackageManager();
      final 
Parameters p camera.getParameters();
      if(
isFlashSupported(pm)){
       
boolean on = ((ToggleButtonview).isChecked();
       if (
on) {
        
Log.i("info""torch is turn on!");
        
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
        
camera.setParameters(p);
        
camera.startPreview();
       } else {
        
Log.i("info""torch is turn off!");
        
p.setFlashMode(Parameters.FLASH_MODE_OFF);
        
camera.setParameters(p);
        
camera.stopPreview();
       }
      }else{
       
button.setChecked(false);
       
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
       
alertDialog.setTitle("No Camera Flash");
          
alertDialog.setMessage("The device's camera doesn't support flash.");
          
alertDialog.setButton(RESULT_OK"OK", new DialogInterface.OnClickListener() {
              public 
void onClick(final DialogInterface dialog, final int which) { 
               
Log.e("err""The device's camera doesn't support flash.");
              }
           });
       
alertDialog.show();
      }
     }
     
/**
      * @param packageManager
      * @return true <b>if the device support camera flash</b><br/>
      * false <b>if the device doesn't support camera flash</b>
      */
     
private boolean isFlashSupported(PackageManager packageManager){ 
      
// if device support camera flash?
      
if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) {
       return 
true;
      } 
      return 
false;
     }

     
/**
      * @param packageManager
      * @return true <b>if the device support camera</b><br/>
      * false <b>if the device doesn't support camera</b>
      */
     
private boolean isCameraSupported(PackageManager packageManager){
      
// if device support camera?
      
if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
       return 
true;
      } 
      return 
false;
     }
    }

public class 
MainActivity extends ActionBarActivity {

    @
Override
    
protected void onCreate(Bundle savedInstanceState) {
        
super.onCreate(savedInstanceState);
        
setContentView(R.layout.activity_main);

        if (
savedInstanceState == null) {
            
getSupportFragmentManager().beginTransaction()
                    .
add(R.id.container, new PlaceholderFragment())
                    .
commit();
        }
    }


    @
Override
    
public boolean onCreateOptionsMenu(Menu menu) {
        
        
// Inflate the menu; this adds items to the action bar if it is present.
        
getMenuInflater().inflate(R.menu.mainmenu);
        return 
true;
    }

    @
Override
    
public boolean onOptionsItemSelected(MenuItem item) {
        
// Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        
int id item.getItemId();
        if (
id == R.id.action_settings) {
            return 
true;
        }
        return 
super.onOptionsItemSelected(item);
    }

    
/**
     * A placeholder fragment containing a simple view.
     */
    
public static class PlaceholderFragment extends Fragment {

        public 
PlaceholderFragment() {
        }

        @
Override
        
public View onCreateView(LayoutInflater inflaterViewGroup container,
                
Bundle savedInstanceState) {
            
View rootView inflater.inflate(R.layout.fragment_maincontainerfalse);
            return 
rootView;
        }
    }


7th June 2014, 08:06 PM   |  #4  
MasterAwesome's Avatar
Senior Member
Thanks Meter: 810
 
1,143 posts
Join Date:Joined: Jun 2013
More
Quote:
Originally Posted by natan.p

I have an error i found tutorial how create flash light app i cop all codes ti manifest etc files but i have error with the java file........
the error: The public type FlashlightActivity must be defined in its own file.

the code: Press Control + F and search this line public class FlashlightActivity extends Activity {

PHP Code:
package com.natan.flashlight;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.util.Log;
import android.widget.ToggleButton;

/**
 * @author Prabu 
 * July 30 2013
 * @version 1.0
 * 
 */

public class FlashlightActivity extends Activity // <--------------------------------------- There are the error..
 
private Camera camera;
 private 
ToggleButton button;
 private final 
Context context this;

     
//@see android.app.Activity#onStop()
 
@Override
 
protected void onStop() {
  
super.onStop();
  if (
camera != null) {
   
camera.release();
  }
 }

 
/**
  * @see android.app.Activity#onCreate(android.os.Bundle)
  */
 
@Override
 
public void onCreate(Bundle savedInstanceState) {
  
super.onCreate(savedInstanceState);
  
//setContentView(R.layout.flashlight);
  
button = (ToggleButtonfindViewById(R.id.togglebutton);
  
  final 
PackageManager pm context.getPackageManager();
  if(!
isCameraSupported(pm)){
   
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
   
alertDialog.setTitle("No Camera");
      
alertDialog.setMessage("The device's doesn't support camera.");
      
alertDialog.setButton(RESULT_OK"OK", new DialogInterface.OnClickListener() {
          public 
void onClick(final DialogInterface dialog, final int which) { 
           
Log.e("err""The device's doesn't support camera.");
          }
       });
   
alertDialog.show();
  }
  
camera Camera.open();
 }
 public 
void onToggleClicked(View view) {
  
PackageManager pm=context.getPackageManager();
  final 
Parameters p camera.getParameters();
  if(
isFlashSupported(pm)){
   
boolean on = ((ToggleButtonview).isChecked();
   if (
on) {
    
Log.i("info""torch is turn on!");
    
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
    
camera.setParameters(p);
    
camera.startPreview();
   } else {
    
Log.i("info""torch is turn off!");
    
p.setFlashMode(Parameters.FLASH_MODE_OFF);
    
camera.setParameters(p);
    
camera.stopPreview();
   }
  }else{
   
button.setChecked(false);
   
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
   
alertDialog.setTitle("No Camera Flash");
      
alertDialog.setMessage("The device's camera doesn't support flash.");
      
alertDialog.setButton(RESULT_OK"OK", new DialogInterface.OnClickListener() {
          public 
void onClick(final DialogInterface dialog, final int which) { 
           
Log.e("err""The device's camera doesn't support flash.");
          }
       });
   
alertDialog.show();
  }
 }
 
/**
  * @param packageManager
  * @return true <b>if the device support camera flash</b><br/>
  * false <b>if the device doesn't support camera flash</b>
  */
 
private boolean isFlashSupported(PackageManager packageManager){ 
  
// if device support camera flash?
  
if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) {
   return 
true;
  } 
  return 
false;
 }

 
/**
  * @param packageManager
  * @return true <b>if the device support camera</b><br/>
  * false <b>if the device doesn't support camera</b>
  */
 
private boolean isCameraSupported(PackageManager packageManager){
  
// if device support camera?
  
if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
   return 
true;
  } 
  return 
false;
 }
}

public class 
MainActivity extends ActionBarActivity {

    @
Override
    
protected void onCreate(Bundle savedInstanceState) {
        
super.onCreate(savedInstanceState);
        
setContentView(R.layout.activity_main);

        if (
savedInstanceState == null) {
            
getSupportFragmentManager().beginTransaction()
                    .
add(R.id.container, new PlaceholderFragment())
                    .
commit();
        }
    }


    @
Override
    
public boolean onCreateOptionsMenu(Menu menu) {
        
        
// Inflate the menu; this adds items to the action bar if it is present.
        
getMenuInflater().inflate(R.menu.mainmenu);
        return 
true;
    }

    @
Override
    
public boolean onOptionsItemSelected(MenuItem item) {
        
// Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        
int id item.getItemId();
        if (
id == R.id.action_settings) {
            return 
true;
        }
        return 
super.onOptionsItemSelected(item);
    }

    
/**
     * A placeholder fragment containing a simple view.
     */
    
public static class PlaceholderFragment extends Fragment {

        public 
PlaceholderFragment() {
        }

        @
Override
        
public View onCreateView(LayoutInflater inflaterViewGroup container,
                
Bundle savedInstanceState) {
            
View rootView inflater.inflate(R.layout.fragment_maincontainerfalse);
            return 
rootView;
        }
    }


You can't have 2 public class in the same file.. Create a new class

Regards
MasterAwesome
8th June 2014, 12:23 AM   |  #5  
OP Junior Member
Thanks Meter: 0
 
12 posts
Join Date:Joined: May 2014
Quote:
Originally Posted by MasterAwesome

You can't have 2 public class in the same file.. Create a new class

Regards
MasterAwesome

What you mean two public classes?

Sent from my Nexus 5 using Tapatalk
8th June 2014, 06:43 AM   |  #6  
MasterAwesome's Avatar
Senior Member
Thanks Meter: 810
 
1,143 posts
Join Date:Joined: Jun 2013
More
Quote:
Originally Posted by natan.p

What you mean two public classes?

Sent from my Nexus 5 using Tapatalk

Main activity and flashlight.. Just remove the public for flashlight

Regards
MasterAwesome
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes