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.
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 am working on an well-being app that shuts your phone up for a given period of time (eg. 30min, 1hr, 1.5hr)
In this state user can only see a screen with remaining time on it and cannot
Access QS tiles
Access Volume panel
Navigate out of the Activity
something similar to Oneplus
Zen mode
things i have thought of for doing this
Killing the SystemUI process.(by doing so the QS and volume panel
would be dealt with most probably, maybe need root for that tho?
also SystemUI automatically restarts itself, quite stubborn)
Making app a launcher Dynamically?(technically you can't navigate
out of a launcher and on reboot you come back to it)
how can I get around accomplishing this? any ideas?
Making application the default launcher of the phone is more practical solution to what you're trying to achieve. I've done this previously in a Flutter application which was going to be installed on kiosk devices to get orders from customers and it worked perfectly. It's a bit tricky to make it work and there's lots of things to do. Here is a list of things I did back then:
Use FLAG_SHOW_WHEN_LOCKED flag to the window to bypass the lock screen.
Inside of onResume add FLAG_FULLSCREEN flags to hide the status bar.
Make your MainActivity launcher by adding LAUNCHER category to in AndroidManifest.xml. Also you can add other attributes I used (Search for them if you don't know what are they supposed to do).
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:excludeFromRecents="true"
android:hardwareAccelerated="true"
android:launchMode="singleInstance"
android:showOnLockScreen="true"
android:showWhenLocked="true"
android:theme="#style/LaunchTheme"
android:turnScreenOn="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Listen for window focus changes in your MainActivity and bring your application to front if it lost the focus.
private fun moveToFront() {
val closeDialog = Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)
sendBroadcast(closeDialog)
(activity.applicationContext.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager)
.moveTaskToFront(activity.taskId, ActivityManager.MOVE_TASK_WITH_HOME)
window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus)
if (!hasFocus) {
moveToFront()
}
}
I was also checking if my application is the default launcher.
private fun isAppDefault(): Boolean {
val intent = Intent(Intent.ACTION_MAIN)
intent.addCategory(Intent.CATEGORY_HOME)
val res: ResolveInfo = packageManager.resolveActivity(intent, 0)
return res.activityInfo != null && (packageName
== res.activityInfo.packageName)
}
And you're gonna need to communicate between Flutter and the platform using MethodChannel to enable and disable force mode and get the state of the application.
I have 2 product flavor. Let's say the example like this:
productFlavors {
free {
applicationId 'com.free.android'
}
premium {
applicationId 'com.premium.android'
}
My problem is when i use
Intent resultIntent = new Intent(this, ExpiryListActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(ExpiryListActivity.class);
stackBuilder.addNextIntent(resultIntent);
The problem happened when stackBuilder.addParentStack(ExpiryListActivity.class)
The first app which used the productFlavor free doesn't cause android.content.pm.PackageManager$NameNotFoundException error.
But the second app which used the productFlavor premium it causes android.content.pm.PackageManager$NameNotFoundException.
Then i read the docs that stackBuilder.addParentStack(<Class>) Add the activity parent chain as specified by manifest . How to solve this problem?
TL;DR
change your metadata as
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="originalPackageName.ui.MainActivity" />
The basic problem is that gradle is expanding the package name for the parent activity class that you wrote in the metadata.
In case of your free product flavor it tries to find a class at location com.free.android.ui.MainActivity
And in case of your paid flavor it tries to find a class at location com.premium.android.ui.MainActivity
But gradle actually does not restructure the packages when you mention different applicationId's for your product flavors and the class is still located at originalPackageName.ui.MainActivity and hence the NameNotFoundException
where originalPackageName is a placeholder for the package name you started your project with.
Looks like i found it. On AndroidManifest.xml
<activity
android:name=".ui.ExpiryListActivity"
android:label="#string/voucher_expiry_list"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar.Slidable" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.MainActivity" />
</activity>
I replace the meta-data name by:
<activity
android:name=".ui.ExpiryListActivity"
android:label="#string/voucher_expiry_list"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar.Slidable" >
<meta-data
android:name=".ui.ExpiryListActivity"
android:value=".ui.MainActivity" />
</activity>
It works, but when pressing back it cannot return to MainActivity. But, I know if this is not the best solution. Please let me know if there is another better solution.
NB: This seems only happened on Android Lollipop (5.0)
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
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