how to print log for camera action - android

In my project i tried to implement camera action in onReceive method. While clicking on camera icon can we print log . i tried it in broadcast receiver. but i cant able to get the result.i attached my piece of code here.
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_CAMERA_BUTTON)) {
Log.e("cam0","cam");
//Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
//context.startService(cameraIntent);
// startActivity(cameraIntent, CAMERA_PIC_REQUEST);
}
}
is it possible to print log for that. Im cracking my head still i cant find the result. Looking for help in this situation. Thank you in advance.

You can create a filter for Logcat so that every log with a specific TAG gets grouped together for quick and easy viewing. Just open up the Logcat view and to the left there is a button (green plus sign) for adding new filters.
And its convention to declare a constant in the class to be used as a log tag, for example private static final string TAG = TAG_camActivity.
If the log isn't showing up then that if statement in all likelihood isn't being evaluated to true.

Related

Method that uses Intent

OK, so I'm not sure how to explain this, but basically what I want to do is when a web/ URL request is passed in a android phone, I want to find out how to get the Intent of that request/action.
For example, when I do this:
MS.FUNCTION("android.content.Intent", new MS.FUNCTION() {
public void classLoaded(Class<?> content) {
Method **SOMETHING**;
try {
open = intent.getMethod("open", Integer.TYPE);
} catch (NoSuchMethodException d)
I want a method (in place of SOMETHING) that passes/uses an Intent when executed, so then I can get extra information. At this point, it is just for web/URL Intents
Thanks so much for any help, and sorry for the probable confusion. I would be glad to answer any other questions regarding clarification.
Also, I have been to the android Intent website, and I have not found what I am looking for. However, this could very easily just be my searching skills.

Android custom keyboard for sending images

I am currently trying to implement a custom keyboard that sends an image (possibly via an intent?) to a certain application. More specifically, I am trying to I am trying to create a key on a custom keyboard that would send an image to the default messaging app so that it can be sent as an MMS.
I have modified the sample SoftKeyboard project in order to do this. Here is what I have so far:
private void handleCharacter(int primaryCode, int[] keyCodes) {
if (isInputViewShown()) {
if (mInputView.isShifted()) {
primaryCode = Character.toUpperCase(primaryCode);
}
}
if (isAlphabet(primaryCode) && mPredictionOn) {
mComposing.append((char) primaryCode);
// Send message here
Intent pictureMessageIntent = new Intent(Intent.ACTION_SEND);
pictureMessageIntent.setType("image/png");
Uri uri = Uri.parse("android.resource://" + this.getPackageName() + "/drawable/icon_en_gb");
pictureMessageIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(pictureMessageIntent);
getCurrentInputConnection().setComposingText(mComposing, 1);
updateShiftKeyState(getCurrentInputEditorInfo());
updateCandidates();
} else {
getCurrentInputConnection().commitText(
String.valueOf((char) primaryCode), 1);
}
}
The problem is I am getting a runtime exception that says:
android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
I'm unfamiliar with Android custom keyboards, but I'm not sure if starting a new Activity is the best idea. Does anyone have any suggestions?
The problem is that Activities are typically meant to be started from other Activities. Android added this error to make sure that developers only change this flow willingly and consciously.
Add the following line before sending the intent to fix the problem:
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
You need to do exactly what it says- add the FLAFG_ACTIVITY_NEW_TASK flag to the intent. Any intent from a service needs that. Fix that and it should work (or at least start the activity).
Put this line:
pictureMessageIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
as you are creating this keyboard for sending images from uri, then add this line too:
// To get images from uri
pictureMessageIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Before the line:
startActivity(pictureMessageIntent);

Where to add #SdkConstant?

Evening all, I have an android device with an SOS button on it (hardware) I am trying to set it up so that it calls up a test application I have created purely as a proof of concept.
This is the information I have been provided by the manufacturer
// Add for SOS/PTT Key Start
#SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_EXT_PTTDOWN = "com.TMZP.Main.PTTDown";
#SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_EXT_PTTUP = "com.TMZP.Main.PTTUp";
#SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_EXT_SOSDOWN = "com.TMZP.Main.SOSDown";
#SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_EXT_SOSUP = "com.TMZP.Main.SOSUp";
// Add for SOS/PTT Key End
Please NOTE:
Both the PTT up and PTT down intent are useful.
int ACTION_DOWN getAction() value: the key has been pressed down.
int ACTION_UP getAction() value: the key has been released.
The problem is, I don't know what to do with the #SdkConstant, I've never seen it before and cant seem to find any explanation.
Currently I have simply added the following intent filter to my test activity, however pressing the hardware button produces no result.
<intent-filter>
<action android:name="com.TMZP.Main.SOSDown"/>
</intent-filter>
Any insight into where I add the #SdkContant would be really helpful (or simply pointing me towards some reading material.)
Thanks in advance.
#SdkConstant, AFAIK, is from the Android OS source code itself, or things built into a revised version of that OS.
For your purposes, just comment them out.
Currently I have simply added the following intent filter to my test activity, however pressing the hardware button produces no result.
That is because, based on the #SdkConstant lines, those are used for broadcasts, not starting activities. Try implementing a BroadcastReceiver that listens for them.

android - manipulating the 'share' menu

first off - let me just say that I am NOT asking how to implement a share button in my app or anything like that. I know all about using Intents and Intent Filters etc etc.
what I AM asking about is this: is there any way to get access to the "Share" menu itself? in other words, I'd love to build an app that filters out some of the services I never use but that I don't want to delete from my phone completely.
I tried looking it up in the Android API, but only found info on getting your app to show up in the menu or putting a 'Share' button in your app etc.
Being that I'm still somewhat of a novice programmer, I'm also wondering if there's some way for me to sniff out the API objects that are being created/used when the 'Share' menu is built/displayed? Seems like I could do it in a Debugger session, but I'm not sure how.
Thank you in advance.
b
Well, there are two ways to go around Share menu. First one is to use
startActivity(Intent.createChooser(Intent, CharSequence)
But in this case, I am not sure how to obtain an access to the created share menu, coz it is a separate activity.
However, if you wish to have a control over the list of share items being displayed for your app, there is another way to approach your share menu item implementation.
Take a look at this code snippet:
//Prepare an intent to filter the activities you need
//Add a List<YourItemType> where you going to store the share-items
List<YourItemType> myShareList = new List<YourItemType>;
PackageManager packageManager = mContext.getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0);
int numActivities = activities.size();
for (int i = 0; i != numActivities; ++i) {
final ResolveInfo info = activities.get(i);
String label = info.loadLabel(packageManager).toString();
//now you can check label or some other info and decide whether to add the item
//into your own list of share items
//Every item in your list should have a runnable which will execute
// proper share-action (Activity)
myShareList.add(new YourItemType(label, info.loadIcon(packageManager), new Runnable()
{
public void run() {
startResolvedActivity(intent, info);
}
}));
}
This code snippet shows how to get a list of the activities which are able to process share request. What you need to do next is to show your own UI. It is up to you what you are going to choose.

How do I use voice search and VoiceRecognition on Android?

I want to use VoiceRecognition in my application, but this application needs to install voice search.
I don't want the user to have to install another other application then return to my application to run it. I want voice search to be installed from my application, or alternatively I'd like to find a tutorial to on how to add Voice Search capability to my application.
What can I do?
Use the RecognizerIntent to fire the speech recognizer installed on your device
This can be done in a few simple steps:
Create some sort of button in your activity, and place the following code in its OnClickListener:
// Define MY_REQUEST_CODE as an int constant in your activity...I use ints in the 10000s
startVoiceRecognitionActivity(MY_REQUEST_CODE, "Say something.");
Override the onActivityResult() method in your activity. In the implementation, place a switch block or if statement to run some logic when the requestCode argument matches your MY_REQUEST_CODE constant. Logic similar to the following will get you the list of results the speech recognition activity thought it heard:
ArrayList keywordMatches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
You may get 0 or many matches from the recognizer. Be sure to handle all cases.
In some cases, the speech recognizer may not even be on the device. Try to handle that where you call startVoiceRecognitionActivity().
I found this tutorial :
http://www.jameselsey.co.uk/blogs/techblog/android-how-to-implement-voice-recognition-a-nice-easy-tutorial/
hope this helps.
Android Open Source VoiceRecognition Example
Here is a Simple way to Handle Voice Search
Step 1 Call this method on button click
public void startVoiceRecognition() {
Intent intent = new Intent("android.speech.action.RECOGNIZE_SPEECH");
intent.putExtra("android.speech.extra.LANGUAGE_MODEL", "free_form");
intent.putExtra("android.speech.extra.PROMPT", "Speak Now");
this.mContainerActivity.startActivityForResult(intent, 3012);
}
Step 2 Override onActivityResult method
# Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 3012 && resultCode == RESULT_OK) {
ArrayList < String > matches = data.getStringArrayListExtra("android.speech.extra.RESULTS");
String result= matches.get(0);
//Consume result
edittext.setText(result);
}
}
Thats all, DONE

Categories

Resources