Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,806,279 Members 52,881 Now Online
XDA Developers Android and Mobile Development Forum

First App dev. help

Tip us?
 
natan.p
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 6
Join Date: May 2014
Default First App dev. help

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!
 
MasterAwesome
Old
#2  
MasterAwesome's Avatar
Senior Member
Thanks Meter 773
Posts: 1,126
Join Date: Jun 2013
Quote:
Originally Posted by natan.p View Post
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
“Be yourself; everyone else is already taken.”― Oscar Wilde
 
natan.p
Old
#3  
Junior Member - OP
Thanks Meter 0
Posts: 6
Join Date: May 2014
Quote:
Originally Posted by MasterAwesome View Post
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;
        }
    }


 
MasterAwesome
Old
#4  
MasterAwesome's Avatar
Senior Member
Thanks Meter 773
Posts: 1,126
Join Date: Jun 2013
Quote:
Originally Posted by natan.p View Post
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
“Be yourself; everyone else is already taken.”― Oscar Wilde
 
natan.p
Old
#5  
Junior Member - OP
Thanks Meter 0
Posts: 6
Join Date: May 2014
Quote:
Originally Posted by MasterAwesome View Post
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
 
MasterAwesome
Old
#6  
MasterAwesome's Avatar
Senior Member
Thanks Meter 773
Posts: 1,126
Join Date: Jun 2013
Quote:
Originally Posted by natan.p View Post
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
“Be yourself; everyone else is already taken.”― Oscar Wilde
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes