I want to add camera to a tab in a way that once i click that tab, the camera will work immediately.
I tried to use similar way to buttons by setting onClickListener but it seems tabs differs from buttons when it comes to listeners.
-May be this would help you.
-onselecting the tab you want to launch camera.. call intent class like this..
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
((Activity) con).startActivityForResult(cameraIntent,
CAMERA_REQUEST_CODE);
`
-Onactivity result method of new tabhost call your desired code further...
-THanks!
Related
Why when I use setSelector method it returns neither Camera activities nor Gallery Activities.I have the following code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent camera= new Intent("android.media.action.IMAGE_CAPTURE");
Intent gallery = new Intent();
gallery.setAction(android.content.Intent.ACTION_VIEW);
gallery.setType("image/*");
gallery.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
camera.setSelector(gallery);
startActivity(camera);
}
According to Android's reference API "If the selector is set, it will be used when trying to find entities that can handle the Intent, instead of the main contents of the Intent."
I thought that I will get a dialog that opens the gallery instead of camera. But, instead of these I got a dialog that returns arbitrary applications/activities, such as Call Settings, Network Settings, SIM Toolkit, etc.
When I remove the camera.setSelector(gallery); method everything works like a charm, but when I use camera.setSelector(gallery); method it returns neither Camera activities nor Gallery Activities.
Could somebody explain me why I got a dialog with these arbitrary activities instead of appropriate?
I don't want to remove the camera.setSelector(gallery); because I am trying to understand how it works!
use this intent to open your gallery
Intent pickPhoto = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
then use startActivityForResult to get the selected photo from gallery. hope this helps
Replace this code :
Intent camera= new Intent("android.media.action.IMAGE_CAPTURE");
With this :
Intent camera= new Intent(Intent.ACTION_VIEW,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
I downloaded from Android.com an example of Navigation Drawer (I want to make a Slideout)
but, in that example when I click in a item of the slideout, this will open an image, so, How can i open an Activity instead of an image?
please help me.
Use this code on press ( Button press or whatever is relavant to you)
Intent intent = new Intent(Currentactivity.this,Activitytoopen.class);
startActivity(intent);
Here:
1) Currentactivity.this should be replaced with the class name you are currently on.
2) Activitytoopen.class should be replaced with the activity name you want to navigate to.
Try to use this codes
Intent i = new Intent(Activity.this,NextActivity.class);
startActivity(i);
overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
I want to launch Android built-in camera app with a thumbnail icon on the right-bottom. Here is my code to open the camera app.
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
I think I need to put a intent data to do it. I look forward to your help.
Thanks.
Just create an image button, or button or anything you desire really.
In the onclick event add something like:
String saveFileName= Environment.getExternalStorageDirectory() + "/test.png";
// BUILT IN CAMERA
Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
camera.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(saveFileName) );
this.startActivityForResult(camera, 1);
Make sure you have necessary permissions set. Like saving to the SDCard.
You are very close, you dont need those flags set. And you should ideally specify where you are saving the image.
If you are wondering how to make the button take a look here
I am trying to make an app which have 2 main controls (along with other info fields)
1.> Next button
2.> Done button
I want to call the same activity when next button is pressed and display some other activity when Done button is pressed
Done button is working fine. But when I press Next button the app stops working. The error that I get is :
Unfortunately, myapp has stopped working
This is the same error which I usually get when I don't define activity in manifest file.
Can anyone please help me with this problem.
And finally Is is legitimate to call same activity within itself ?
Thanks
I think this should work
Intent i= new Intent(ActivityA.this,ActivityA.class);
You can use Intent flags to call the activity again. In the button click
setContentView(R.layout.main);
Intent intent= new Intent(this,SameClass.class);
startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT));
Try this
Intent intent= getIntent();
finish();
startActivity(intent);
Thank you
Why do you need to call the Activity within itself?
You can do following things:
1. You can reset data on next button click.
2. You can hide view or make visible on next button click.
Clear your requirements and show your code to check why the error Unfortunately, myapp has stopped working is coming.
Use TabGroupactivity
In the next button onclick write
public void next(View v) {
Intent next= new Intent(getParent(), next.class);
TabGroupActivity parentActivity = (TabGroupActivity) getParent();
parentActivity.startChildActivity("next", next);
}
Intent i= new Intent(ActivityA.this,ActivityA.class);
startActivity(i);
or
startActivity(new Intent(ActivityA.this,ActivityA.class));
I am writing an application that is composed of several tabs created in a tabhost with:
intent = new Intent().setClass(this, Home.class);
spec = tabHost.newTabSpec("Home").setIndicator("Home",
res.getDrawable(R.drawable.home))
.setContent(intent);
tabHost.addTab(spec);
In the tab in question I am using an ActivityGroup to change to different Activities in the tab:
Intent intent = new Intent(Info1.this, Enroll2.class);
intent.putExtra("info", Info);
View newView = Group.group.getLocalActivityManager().startActivity("Info1", intent
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
Group.group.replaceView(newView);
From one of these Activities I need to take a picture and I am trying to use the default camera app on the device using:
//define the file-name to save photo taken by Camera activity
String fileName = "picture" + Integer.toString(pictureCount);
//create parameters for Intent with filename
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, fileName);
values.put(MediaStore.Images.Media.DESCRIPTION,"Image capture by camera");
//imageUri is the current activity attribute, define and save it for later usage (also in onSaveInstanceState)
imageUri = getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
//create new Intent
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
This starts the camera app correctly, but after taking a picture it does not enter the onActivityResult method. I've tried placing this method in every class in the chain for the tab and it doesn't enter the code in any of them.
I noticed that this question was asked before at How to startactivityforresult in tab child of TabHost but the only potentially useful answer was a redirect to How to return a result (startActivityForResult) from a TabHost Activity? which is a question about using startActivityForResult from a basic Activity to start a tabActivity and not starting an Activity from a tabActivity so it was no use.
I also keep seeing people say that this doesn't work when you're using an ActivityGroup, but no one suggests how else to go about doing it.
Any help would be appreciated.
Alright, I was able to find a solution to this problem.
First, I created another activity that I started using the basic startActivity() call I called a Result Controller. This does not pass any data back to the tabbed activity which means you don't have to worry about where it's going.
Second, I created a simple static data class which I called DataConnector. The ResultController would get the instance of the DataConnector and insert the Data there
Then, in the original activity(in the tabs) I implemented the onWindowFocusChanged method to determine when the user is back to it. I got the instance of DataConnector and was able to pull the data I needed out of there.