I updated several of my files but they do not appear as id #s in R.java. I tried updating my imports, I tried closing then opening Eclipse, saving, and closing/opening the Emulator, but it is not working to get R.Java to recognize the updates in the files. Of the items that are missing from R.java are 2 buttons (with 2 services) which would activate a toast when pressed, I will list the files below, each one. I run the emulator (Virtual, Nexus API 17) and it shows an old version of my app that has no buttons, only text that says "Hello World". Thanks in advance.
UPDATE: I tried to clean my project (thinking that if the R.java got regenerated, then it might update itself), but it just made the R.java disappear, and created an error in the main folder, HelloWorld in the Package Explorer. Oddly enough, there were no other errors in the entire series of files that I edited. No yellow warnings, nothing. Plus I never edited the R.java file (I know it's a no-no). So then after I tried to run my project anyway, this error posted in the LogCat below.
I found this in the LogCat:
01-03 06:54:13.977: E/ThrottleService(300): problem during
onPollAlarm: java.lang.IllegalStateException: problem parsing stats:
java.io.FileNotFoundException: /proc/net/xt_qtaguid/iface_stat_all:
open failed: ENOENT (No such file or directory)
Here are my files:
MainActivity.java
package com.example.helloworld;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
// Method to start the service
public void startService(View view) {
startService(new Intent(getBaseContext(), MyService.class));
}
// Method to stop the service
public void stopService(View view) {
stopService(new Intent(getBaseContext(), MyService.class));
}
}
MyService.java
package com.example.helloworld;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.widget.Toast;
public class MyService extends Service {
#Override
public IBinder onBind(Intent arg0) {
return null;
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
// Let it continue running until it is stopped.
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
return START_STICKY;
}
#Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show();
}
}
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button android:id="#+id/btnStartService"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/start_service"
android:onClick="startService"/>
<Button android:id="#+id/btnStopService"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/stop_service"
android:onClick="stopService" />
</LinearLayout>
strings.xml
<resources>
<string name="app_name">HelloWorld</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">MainActivity</string>
<string name="start_service">Start Service</string>
<string name="stop_service">Stop Service</string>
</resources>
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloworld"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<service android:name=".MyService" />
</application>
</manifest>
and finally, the R.java (which ignores many strings and other names)
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package com.example.helloworld;
public final class R {
public static final class attr {
}
public static final class dimen {
/** Default screen margins, per the Android Design guidelines.
Customize dimensions originally defined in res/values/dimens.xml (such as
screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
*/
public static final int activity_horizontal_margin=0x7f040000;
public static final int activity_vertical_margin=0x7f040001;
}
public static final class drawable {
public static final int ic_launcher=0x7f020000;
}
public static final class id {
public static final int action_settings=0x7f080000;
}
public static final class layout {
public static final int activity_main=0x7f030000;
}
public static final class menu {
public static final int main=0x7f070000;
}
public static final class string {
public static final int action_settings=0x7f050001;
public static final int app_name=0x7f050000;
public static final int hello_world=0x7f050002;
}
public static final class style {
/**
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
API 11 theme customizations can go here.
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
API 14 theme customizations can go here.
*/
public static final int AppBaseTheme=0x7f060000;
/** Application theme.
All customizations that are NOT specific to a particular API-level can go here.
*/
public static final int AppTheme=0x7f060001;
}
}
You code is perfectly fine.I think you might have damaged R.java and put something by your self.I have compiled your code it works fine.You can even download from this link.
After great help from everyone, the final solution was to begin a new project, then copy/paste each important file back into it, including updating the AndroidManifest.xml file. However, the order of operations was very important. The rebuild did not work if I copy and pasted the MainActivity.java file first, rebuilding that way gave me that odd HelloWorld folder error with no other errors in all my other files. So I thought maybe rebuilding in a certain order would work, and it did.
I had to do the rebuild in this order:
strings.xml
activity_main.xml
MyService.java
update the AndroidManifest.xml (with the addition of the MyService.java in <service> tags)
then finally the MainActivity.java
I then updated all imports and saved everything, and low and behold, R.java was updated with the right ids for all of my strings and other name ids.
So while I still don't understand why I had a red error on my HelloWorld project folder in Package Explorer (that did not show a single error or warning anywhere else in any of my edited files), it looks like rebuilding the file by cutting and pasting in a new project, in a careful order, ended up updating the R.java so that I could run successfully in the emulator.
Special thanks to #TalhaQ for suggesting my files were okay and to reuse the code. Although I know I did not edit the R.java file at all, it's still a mystery why it never updated like it should have. Might have had something to do with the order of operations in the original file, since the order of operations mattered a lot in the rebuild.
As you have stated in your question it shows an old version of my app that has no buttons, only text that says "Hello World".
Just try to uninstall the old application from your emulator and try to run the project.
Go to Settings>ApplicationManager> select your application> Uninstall
Related
I try to build Retrieving a List of Contacts from android website,
https://android-doc.github.io/training/contacts-provider/retrieve-names.html#Permissions
and I try to configure this to 31 target api.
I got this error
E/AndroidRuntime: FATAL EXCEPTION: ModernAsyncTask #1
Process: com.example.contactlistandroid, PID: 15844
java.lang.RuntimeException: An error occurred while executing doInBackground()
Caused by: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord{b4e47ee 15844:com.example.contactlistandroid/u0a160} (pid=15844, uid=10160) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS
here is my main activity
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.contactlistandroid.ui;
import android.app.SearchManager;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import androidx.fragment.app.FragmentActivity;
import com.example.contactlistandroid.BuildConfig;
import com.example.contactlistandroid.R;
import com.example.contactlistandroid.util.Utils;
/**
* FragmentActivity to hold the main {#link ContactsListFragment}. On larger screen devices which
* can fit two panes also load {#link ContactDetailFragment}.
*/
public class ContactsListActivity extends FragmentActivity implements
ContactsListFragment.OnContactsInteractionListener {
// Defines a tag for identifying log entries
private static final String TAG = "ContactsListActivity";
private ContactDetailFragment mContactDetailFragment;
// If true, this is a larger screen device which fits two panes
private boolean isTwoPaneLayout;
// True if this activity instance is a search result view (used on pre-HC devices that load
// search results in a separate instance of the activity rather than loading results in-line
// as the query is typed.
private boolean isSearchResultView = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
if (BuildConfig.DEBUG) {
Utils.enableStrictMode();
}
super.onCreate(savedInstanceState);
// Set main content view. On smaller screen devices this is a single pane view with one
// fragment. One larger screen devices this is a two pane view with two fragments.
setContentView(R.layout.activity_main);
// Check if two pane bool is set based on resource directories
isTwoPaneLayout = getResources().getBoolean(R.bool.has_two_panes);
// Check if this activity instance has been triggered as a result of a search query. This
// will only happen on pre-HC OS versions as from HC onward search is carried out using
// an ActionBar SearchView which carries out the search in-line without loading a new
// Activity.
if (Intent.ACTION_SEARCH.equals(getIntent().getAction())) {
// Fetch query from intent and notify the fragment that it should display search
// results instead of all contacts.
String searchQuery = getIntent().getStringExtra(SearchManager.QUERY);
ContactsListFragment mContactsListFragment = (ContactsListFragment)
getSupportFragmentManager().findFragmentById(R.id.contact_list);
// This flag notes that the Activity is doing a search, and so the result will be
// search results rather than all contacts. This prevents the Activity and Fragment
// from trying to a search on search results.
isSearchResultView = true;
mContactsListFragment.setSearchQuery(searchQuery);
// Set special title for search results
String title = getString(R.string.contacts_list_search_results_title, searchQuery);
setTitle(title);
}
if (isTwoPaneLayout) {
// If two pane layout, locate the contact detail fragment
mContactDetailFragment = (ContactDetailFragment)
getSupportFragmentManager().findFragmentById(R.id.contact_detail);
}
}
/**
* This interface callback lets the main contacts list fragment notify
* this activity that a contact has been selected.
*
* #param contactUri The contact Uri to the selected contact.
*/
#Override
public void onContactSelected(Uri contactUri) {
if (isTwoPaneLayout && mContactDetailFragment != null) {
// If two pane layout then update the detail fragment to show the selected contact
mContactDetailFragment.setContact(contactUri);
} else {
// Otherwise single pane layout, start a new ContactDetailActivity with
// the contact Uri
Intent intent = new Intent(this, ContactDetailActivity.class);
intent.setData(contactUri);
startActivity(intent);
}
}
/**
* This interface callback lets the main contacts list fragment notify
* this activity that a contact is no longer selected.
*/
#Override
public void onSelectionCleared() {
if (isTwoPaneLayout && mContactDetailFragment != null) {
mContactDetailFragment.setContact(null);
}
}
#Override
public boolean onSearchRequested() {
// Don't allow another search if this activity instance is already showing
// search results. Only used pre-HC.
return !isSearchResultView && super.onSearchRequested();
}
}
mainfest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.contactlistandroid">
<!--
<uses-permission android:name="android.permission.READ_CONTACTS" />
-->
<application
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.ContactListAndroid"
tools:targetApi="31">
<activity
android:name=".ui.ContactsListActivity"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- Add intent-filter for search intent action and specify searchable configuration
via meta-data tag. This allows this activity to receive search intents via the
system hooks. In this sample this is only used on older OS versions (pre-Honeycomb)
via the activity search dialog. See the Search API guide for more information:
http://developer.android.com/guide/topics/search/search-dialog.html -->
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable_contacts" />
</activity>
<activity
android:name=".ui.ContactDetailActivity"
android:label="#string/activity_contact_detail"
android:parentActivityName=".ui.ContactsListActivity">
<!-- Define hierarchical parent of this activity, both via the system
parentActivityName attribute (added in API Level 16) and via meta-data annotation.
This allows use of the support library NavUtils class in a way that works over
all Android versions. See the "Tasks and Back Stack" guide for more information:
http://developer.android.com/guide/components/tasks-and-back-stack.html
-->
<meta-data android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.ContactsListActivity" />
</activity>
</application>
</manifest>
Thanks for the assistance
You need to request the permission and verify if it was allowed with a broadcast listnener I think
I'm basically attempting to accomplish this, using the first answer provided. The question has answers around the web and SO, but I'm having trouble getting it to work. Is there something I need to enable, add to my manifest, ect.? I want to react to a beacon coming within range of the phone. I'm working in Android Studio, targeting Android 4.3 and working with the Android Beacon Library. Based on their documentation, all I need is to implement BootstrapNotifier, set a Region, and then anytime it scans a beacon, it will automatically call didEnterRegion. My Region is Region region = new Region("all-beacons-region", null, null, null);.
I have also built a very simple app which scans for and finds beacons in the foreground. So no problems there, I am definitely able to pick up my beacons and pull basic info from them.
My main activity looks like this:
package com.example.justin.backgroundscantest;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
And my class looks like this:
import android.app.Application;
import android.content.Intent;
import android.util.Log;
import com.example.justin.backgroundscantest.MainActivity;
import org.altbeacon.beacon.startup.BootstrapNotifier;
import org.altbeacon.beacon.startup.RegionBootstrap;
import org.altbeacon.beacon.BeaconManager;
import org.altbeacon.beacon.BeaconParser;
import org.altbeacon.beacon.Region;
public class TestApp extends Application implements BootstrapNotifier {
private static final String TAG = ".TestApp";
private RegionBootstrap regionBootstrap;
#Override
public void onCreate() {
super.onCreate();
Log.d(TAG, "App started up");
BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);
beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("s:0-1=feaa,m:2-2=00,p:3-3:-41,i:4-13,i:14-19"));
// wake up the app when any beacon is seen (you can specify specific id filers in the parameters below)
Region region = new Region("com.example.myapp.boostrapRegion", null, null, null);
regionBootstrap = new RegionBootstrap(this, region);
}
#Override
public void didEnterRegion(Region arg0) {
Log.d(TAG, "Got a didEnterRegion call");
// This call to disable will make it so the activity below only gets launched the first time a beacon is seen (until the next time the app is launched)
// if you want the Activity to launch every single time beacons come into view, remove this call.
regionBootstrap.disable();
Intent intent = new Intent(this, MainActivity.class);
// IMPORTANT: in the AndroidManifest.xml definition of this activity, you must set android:launchMode="singleInstance" or you will get two instances
// created when a user launches the activity manually and it gets launched from here.
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent);
}
}
(Edit)
Finally, AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.justin.backgroundscantest">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
It all feels pretty straightforward, which is I'm curious if I'm missing something simple or silly. I've found this example in several places around the web, but no mention of anything that I might have missed. I have a pretty solid coding background but am new to Android and very new to Eddystone/BLE technology. And just to clarify the actual problem: there is no reaction from my app when I move the phone within range of the beacon. My expectation is that it will "wake up" and begin MainActivity. I am definitely in range of the beacon, the beacon is definitely on, and again, I am able to scan it in the foreground. It just won't wake up my app. Thanks!
When creating a custom Android Application class like TestApp, you must declare it in your manifest with a name attribute. Like this:
<application
android:name="TestApp"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
If you don't do that, Android won't use your custom TestApp class, and will instead default to its built-in base Application class, causing none of the TestApp code to get executed.
I have been following the instructions for the Android Bootcamp youtube series (3. Hello World) as closely as possible, but I have run into a whole slough of issues:
Problem 1: AVD Manager
Eclipse won't recognize my phone (Samsung Galaxy S5) for debugging/running apps. It doesn't show up in the AVD at all.
I have downloaded the driver required for my comp to communicate with the phone
I have enabled Developer's Mode on my phone
I have enabled debugging over USB
I have restarted Eclipse AND my phone
The phone is new, undamaged and runs just fine
My computer recognizes my phone and attributes the correct name, can extract files, etc
Problem 2: Running Apps
I attempted to circumvent the AVD Manager by clicking "Run" to simply select my phone. However, after electing to run as an "Android Application," I got an error:
Errors occurred during the build.
Errors running builder 'Android Pre Compiler' on project 'XXX'
I resolved this error by installing new software from (Help > Install new Software > http://download.eclipse.org/releases/luna > 'Collaboration' > 'Subversive SVN JDT Ignore Extensions' and 'Subversive SVN Team Provider') via the recommendation made on this thread. This made the error disappear.
Unfortunately, while the error no longer appears, the application still refuses to run. There are errors now in:
HelloWorld1 (ERRORS)
src (ERRORS)
com.example.helloworld1 (ERRORS)
HelloWorldActivity.java (ERRORS)
and
rec (ERRORS)
values (ERRORS)
values-v11 (ERRORS)
values-vw820dp (ERRORS)
Sadly, I don't know when the errors appeared, but I do know that they are preventing me from running anything.
I have attempted cleaning the project, but it fails every time and does not return a warning or message.
The only file I have touched since creating the project is the xml fragment. I click-and-dragged a couple elements in the Graphical Layout, then removed them. I have not touched any code, except the hex color code used to change the font color for "Hellow World" in the HelloWorldActivity. the hex color code is correct and works just fine.
Code for XML frag:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.helloworld1.HelloWorldActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="102dp"
android:text="#string/hello_world" />
</RelativeLayout>
Code for HelloWorldActivity.java:
package com.example.helloworld1;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class HelloWorldActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hello_world);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.hello_world, menu);
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);
}
}
I have been dealing with nothing but errors for 4 days. I haven't gotten to do any actual work yet. I'm at wit's end.
Any and all help is deeply, deeply appreciated.
looks like a problem from your configuration
compare Project->Properties between your buggy project and the new one you created
There are lots of Resources$NotFoundException questions on Stack Overflow and I've reviewed them and tried the various suggestions to no avail.
I had a perfectly working layout to display some graphics with some buttons underneath and I modified some of the buttons and started to get this error. I couldn't see anything wrong with my changes but just to narrow it down I deleted ALL the buttons, so now I just have a LinearLayout with an ImageView and I'm still getting the error. My Java:
try {
setContentView(R.layout.graphics);
}
catch (Exception e) {
Log.d("DGraphActivity", "setContentView crash");
}
My XML:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="#+id/image2"
android:layout_width="0px"
android:layout_weight="2"
android:layout_height="match_parent"
android:scaleType="fitCenter">
</ImageView>
</LinearLayout>
The error says android.content.res.Resources$NotFoundException: Resource ID #0x7f030005.
In the R.java file that resource is identified with the graphics . . .
public static final class layout {
public static final int addcomment=0x7f030000;
public static final int areyousure=0x7f030001;
public static final int downarrow=0x7f030002;
public static final int downleftarrow=0x7f030003;
public static final int downrightarrow=0x7f030004;
public static final int graphics=0x7f030005;
public static final int infofromoperator=0x7f030006;
I deleted the gen folder and did a clean the project with no improvement. I also rebooted my PC and did an explicit close of the project. There's nothing obviously wrong with the graphics.xml file - it exists in the same folder with all my other XML files; it's not write-protected or hidden. Eclipse doesn't flag any errors or warnings for it.
Thanks in advance.
I got the answer to this on the android-developers Google groups, where I also posted this question. The insightful programmer was "Bob Smith", just to give credit credit where it's due.
My bug was that the resource it was seeking was not in the correct res folder. My app runs in landscape mode on a tablet. In the manifest everything is constrained to run that way (in fact in the code it's constrained to run on one particular tablet that the company ships with their product). All the resource and layout files live in layout-land. Bob didn't know any of this but he asked the key question: were my resource files really in the right res folder?
You can do : Project > Clean and REFRESH
Im a bit new to Java and Android. Im developing a program to android that one of the needed features is to be able to take a picture with the correct name.
my main class is AmplaCoordenadasActivity
so i made the following code inside it:
public void tirarFoto(String arquivo)
{
Intent camera = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
Uri uriSavedImage=Uri.fromFile(new File(arquivo));
camera.putExtra("output", uriSavedImage);
startActivityForResult(camera, 1);
}
and it works fine.
But when i try to put it in another class and call it , it throws many exceptions.
The class:
package ampla.giesta.coordenadas;
import java.io.File;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
public class Photo extends Activity{
public void tirarFoto(String arquivo){
Intent camera = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
Uri uriSavedImage=Uri.fromFile(new File(arquivo));
camera.putExtra("output", uriSavedImage);
startActivityForResult(camera, 1);
}
}
And the I write in the main class
public void Camera(){
Photo camera = new Photo();
camera.tirarFoto("/sdcard/x.jpg");
}
Can anyone help?
You need to include the new activity in your android manifest.
Read up on it here
http://developer.android.com/guide/topics/manifest/manifest-intro.html
That's a good intro to the permissions you need to set in the android manifest. The manifest controls what other app's functions your app can call and respond to, you have to declare services and recievers in your manifest, any special permissions your app needs need to be declared in your manifest, and finally, any additional activities besides your main app activity also need to be declared here.
You also manage intent filters for your activities in the manifest.
try adding
<activity android:name=".Photo" android:label="#string/app_name" />
to your manifest.xml file