I am programming for android 2.2 API Level 8 and I am trying to find out if there is currently a bluetooth headset connected when my application starts initially. I can not seem to find a solution to this issue.
Once my application is up and running I can listen for BluetoothDevice.ACTION_ACL_CONNECTED and BluetoothDevice.ACTION_ACL_DISCONNECTED as denoted here which works great mind you. But I can't figure out how to tell before the BroadcastReceiver is on if there is currently a bluetooth headset connected.
I am hoping that someone out there already has a solution to this issue for API Level 8. I do realize that in API 11 there are some new classes such as BluetoothProfile and BluetoothHeadset that could probably do this in 1 line of code, but again I am trying to do this in API Level 8
I am willing to try anything at this point.
Thanks in advance
-H
Something like this
http://stackoverflow.com/questions/4544042/how-to-detect-if-bluetooth-device-is-connected
maybe?
You probably will have to find out if one of the devices is a headset...
Nope. That only shows the paried or configured bonded devices that have been at some point bonded/paired to the device.
which can be simply done like this
Code:
BluetoothAdapter mBluetoothAdapter = null;
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if(mBluetoothAdapter != null)
{
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
if (pairedDevices.size() != 0)
{
// the device has paired devices
for (BluetoothDevice device : pairedDevices)
{
Log.i(TAG, "device name: " + device.getName());
Log.i(TAG, "device address: " + device.getAddress());
}
}
else
{
// no paired devices
Log.i(TAG, "no paired devices");
}
}
I had stumbled across this
http://stackoverflow.com/questions/...g-a-private-unpublished-method-in-android-api
but I am new to reflection and very rusty with java. I was not able to get it to work as expected nor did I see anyone else get this answered.
I did find http://java.sun.com/developer/technicalArticles/ALT/Reflection/ which was super useful for refection.
Any advice/help/suggestions/code would help me tons.
Related
Hi I want to make an application using location, I found this tutorial
http://msdn.microsoft.com/en-us/library/dd938890.aspx#RetrievingLocationInformationthroughGPS
which looks very helpful but because I am new to visual studio I am having some problems.
1) is the article it says "This article includes complete sample code." but I cant find a download for all the code.
2) he only mentions referencing Microsoft.WindowsMobile.Samples.Location.dll which I have done but the class LatLong is still unknown
3) I made a sample program without the LatLong class just to experiment I get the following error on my device
"Microsoft.WindowsMobile.Samples.Location, Version=1.0.3448.25673, Culture=neutral, PublicKeyToken=null, or one of its dependencies, was not found
any idea what this means?
4) Could all my problems be because I am using visual studio 2005 and not 2008? I found a code project that looked really helpful but when trying to open it it says that it cant because it is from a newer version of the software, anything that can be done?
5) I find MSDN confusing for finding out what to reference to add a class for example this is the page for the LatLong class http://msdn.microsoft.com/en-us/library/cc514548.aspx
with the java online info the first thing you always see is where the class is found but it seems to be missing for this class. Other basig classes appear similar to java.
below is my sample code its basically taken from the article but I have commented out the references to LatLong and put in checks instead
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsMobile.Samples.Location;
namespace DeviceApplication3
{
public partial class Form1 : Form
{
private Gps gps;
int count = 0;
public Form1()
{
InitializeComponent();
gps = new Gps();
gps.Open();
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = (getGpsString());
}
private string getGpsString()
{
GpsPosition position = gps.GetPosition();
/*LatLong location = new LatLong();
if (position.LatitudeValid)
location.Latitude = position.Latitude;
if (position.LongitudeValid)
location.Longitude = position.Longitude;
if (position.HeadingValid)
location.Heading = position.Heading;*/
StringBuilder sb = new StringBuilder();
sb.Append("\n");
sb.Append("Latitude = ");
if (position.LatitudeValid)
{
sb.Append(position.Latitude.ToString() + "\n");
}
else
{
sb.Append("Not found yet\n");
}
sb.Append("Longitude = ");
if (position.LongitudeValid)
{
sb.Append(position.Longitude.ToString() + "\n");
}
else
{
sb.Append("Not found yet\n");
}
sb.Append("Heading = ");
if (position.HeadingValid)
{
sb.Append(position.Heading.ToString() + "\n");
}
else
{
sb.Append("Not found yet\n");
}
return sb.ToString();
}
}
}
Microsoft.WindowsMobile.Samples.Location.dll
is this file located in bin\debug and or \bin\release
?
and does it only give runtime errors or also compile time ?
no it compiles fine, can you see anything wrong with my code? The weird thing is the form comes up using the emulator but not on the device. Could it be because I have a custom rom that seems to have compact framework 3.5? I would assume it would be back compatible?
How have you deployed it to the device? Have you copied the .exe and the Location.dll?
one thing you could also test was if you could disable the stuff in the gps
and just run a program without it to verify that it's not missing net3.5's fault
heliosdev said:
How have you deployed it to the device? Have you copied the .exe and the Location.dll?
Click to expand...
Click to collapse
Hi thanks for this I didnt copy over the dll I'm very silly.
So what do you guys think about loading projects ment for vs 2008 in 2005 is this impossible ? or can i convert them somehow?
sure it's only the project and solution files which differ
add the cs files manualy and it should work fine
Use the same name to create the new project in vs2005 to have the same namespace.
You'll have to do some manual changes if the code uses c#3.0 .net 3.5 features.
Thanks guys your awesome,
very random and off topic but since your programming kings ill ask anyway,
I think I want to eventually work in the gaming industry, I'm close(3months) to finishing my MSc CompSci conversion course and I am looking for jobs, its quite aparent that most games companys don't want unexperienced people so do you guys have any ideas of places to apply for that will give the the necessary experience? btw I have no taught experience with C++ which I think is my biggest dissadvantage, I do know C and java quite well though and as you can tell just starting to play with C#.
your help is always appreciated.
well, continue with general programming (object oriented programming, ui development, database, network,...). There are so many different fields in software development!
For example take a look at the chapters of the books in the game programming gems series to see what (not only) gaming companies are working on. In general for beginning there is a lot of information online where you'll find tons of tutorials.
Try to get a profound base in programming.
Starting with your gps application, develop a gui, save/load the positions (database), visualize the points...
heliosdev said:
well, continue with general programming (object oriented programming, ui development, database, network,...). There are so many different fields in software development!
For example take a look at the chapters of the books in the game programming gems series to see what (not only) gaming companies are working on. In general for beginning there is a lot of information online where you'll find tons of tutorials.
Try to get a profound base in programming.
Starting with your gps application, develop a gui, save/load the positions (database), visualize the points...
Click to expand...
Click to collapse
Hi sorry for the late reply I upgraded to windows 7 last night to try and improve my rubbish laptop, seems to be a bit better btw,
anyway just want to say thanks for the advice. also my app will use google maps yahoo zonetag and windows live earth (or bing maps if thats what there calling it now) I think for some of thoes services I will need to pay to realease my app to the public even if its free but what about testers would I be able to give it to say 10 people?
From multiple sources (http://www.nextbestgeek.com/2010/12/30/getting-a-more-secure-windows-phone-7-app/, http://www.djawirlabs.com/1855/) i have heard that its possible to track down pirated apps by searching for a xml in the xap, the one thing i wonder, "have one person passed with this though submission process"?
Coder > submission process > add of "WMAppPRHeader.xml" > Marketplace ?
That above is the way i think it is, but if submission does not have "WMAppPRHeader.xml" in xap, the "checkers" will have a auto exit application if coded that way. Or is it?:
Coder > add of "WMAppPRHeader.xml" > submission process > Marketplace ?
Code:
public static bool IsHackedMarketplaceApp()
{
#if DEBUG
return false;
#endif
#pragma warning disable
try
{
var content = System.Xml.Linq.XDocument.Load("WMAppPRHeader.xml");
return false;
}
catch
{
return true;
}
#pragma warning restore
}
Without having a "is WMAppPRHeader.xml" present, if not "enter password" type setup, it won't be possible to have apps that work and pass certification.
With the password part, you can add a tester note in the submission forms with a password/method for installing that should get checked.
The alternative is the "IsTrial()" method with a lot of obfuscation surrounding any mentions of it.
Both of these methods are possible to get round with a moderate knowledge of C# and .Net Reflector, but with obfuscation it's a hell of a lot harder.
Obfuscation make it a lot difficult, but ive seen an obfuscator for pc that i used once, if we obfucate using that then reflector or any other program i tried to disassemble it crashed. Though i didnt check with hhd hex editor neo. for sure redgates reflector and another prog i used had no luck..
According to chevron group app piracy wont work when nodo update comes, not cox side loading wont work but the way they handle homebrew and marketplace app it seems
Hi all,
i am working for VC++, please tell me how can i identify here the Windows Phone 7 is connected to PC By USB cable .
thanks in advance.
You should be more specific. Where you need identify connection: on the handset or on PC? BTW, C++ isn't supported by WP7 SDK (C# and VB only).
I want to identify connection on PC .
is there any option n c# to identify this please tell me.
AFAIK, there is no WP7 API or documentation for this from PC side (but probably you can find something in WinMo 6/6.5 SDK's), however you can monitor and detect Zune run or get background task on WP7 telling you what kind of connection handset is using right now.
P.S. Take a look to the http://msdn.microsoft.com/en-us/library/bb840031.aspx , also check this thread http://forum.xda-developers.com/showthread.php?t=1016766
I believe it's possible using Windows CE/Windows Mobile "old technique" ('cause WP7 based on WinCE 7.0 and CE services).
so please tell me how?
Also you can use Microsoft.Smartdevice.Connectivity assembly but it's not a best way (no events defined, you should pull device for connection periodically).
Code:
using Microsoft.SmartDevice.Connectivity;
static DeviceInfo[] GetDevices()
{
List<DeviceInfo> list = new List<DeviceInfo>();
try
{
DatastoreManager manager = new DatastoreManager(0x409);
foreach (Platform platform in manager.GetPlatforms())
foreach (Device device in platform.GetDevices())
list.Add(new DeviceInfo(platform.Id.ToString(), device.Id.ToString(), device.Name));
}
catch {}
return list.ToArray();
}
static bool IsDeviceConnected (DeviceInfo deviceInfo)
{
bool bResult = false;
try
{
DatastoreManager manager = new DatastoreManager(0x409);
Device device = manager.GetPlatform(new ObjectId(deviceInfo.PlatformId)).GetDevice(new ObjectId(deviceInfo.DeviceId));
bResult = device.IsConnected();
}
catch {}
return bResult;
}
Of course it's just a prototypes. Actually you need to get device once and periodically pull .IsConnected().
error ::comes when i use this.
error CS0234:The type or namespace name 'SmartDevice' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
error CS0246: The type or namespace name 'DeviceInfo' could not be found (are you missing a using directive or an assembly reference?)
Click to expand...
Click to collapse
sensboston said:
AFAIK, there is no WP7 API or documentation for this from PC side (but probably you can find something in WinMo 6/6.5 SDK's), however you can monitor and detect Zune run or get background task on WP7 telling you what kind of connection handset is using right now.
P.S. Take a look to the http://msdn.microsoft.com/en-us/library/bb840031.aspx , also check this thread http://forum.xda-developers.com/showthread.php?t=1016766
I believe it's possible using Windows CE/Windows Mobile "old technique" ('cause WP7 based on WinCE 7.0 and CE services).
Click to expand...
Click to collapse
have u ever tried this ?
please help.
[email protected] said:
please help.
Click to expand...
Click to collapse
Watch this video, it will explain your needs completely!
P.S. Always try 2google first! Nobody will do your job for you...
thread moved to Q&A
Hi,
During the last two weeks I've been trying to do some simple USB communication using my Xoom (MZ601) as USB host. This have proven to be harder than I expected and my latest theory is that the USB API not activated on my tablet.
My simplest test app just tries to enumerate USB devices and is as follows:
I added this to my AndroidManifest.xml:
Code:
...
<uses-sdk android:minSdkVersion="12" />
<uses-feature android:name="android.hardware.usb.host" />
...
My activity looks like:
Code:
public class USBFinderActivity extends Activity
{
private static final String TAG = "USB Finder";
private UsbManager mManager;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mManager = (UsbManager)getSystemService(Context.USB_SERVICE);
Log.i(TAG, "Manager is: " + mManager.toString());
Log.i(TAG, "Device are: " + mManager.getDeviceList().toString());
for (UsbDevice device : mManager.getDeviceList().values())
{
Log.i(TAG, "Device: " + device.toString());
}
}
}
But all I get is:
Code:
D/USB Finder( 3157): Manager is: [email protected]
D/USB Finder( 3157): Device are: {}
I have tried this together with my mouse, USB-memory headset and HTC Desire in combination with the following ROMs: Stock 3.1, Stock + Rooted 3.2.2, Tiamat 2.1-Hammerhead and Tiamat 2.2.2-Moray, but the result is the same.
Some other tests I've done are:
USB-mouse works out of the box for all the different ROM:s.
USB-memorys work good with Tiamat ROM:s.
USB-headset shows up in logcat, dmesg and lsusb at least.
Connecting the Xoom to my HTC Desire and run AdbTest without success
Testing the market app USB Device Info. Devices show up under the Linux tab, but the Android Tab say "No devices detected".
I've spent a lot of time searching information. I'm not alone with this problem. There are more people who has the same problem, while others get it to work directly. I can not see any connection to why it works for some and others not. It's spread over different makes, models and versions.
So if anyone out there got some experience or information about this, feel free to post. I'm starting to run out of debugging ideas.
Solution
Apparently the US-Wifi (MZ604) is a GDE (Google Device Experience) tablet. This means that it is Google that handles the updates for the device, without any involving from Motorola. For all other devices, Motorola customize the software before shipping it to the users.
For some reason, Motorola's software does not support the USB-host API. So if you want to enable USB-host you on your MZ601 will have to change the device software to US-Wifi (MZ604).
My Xoom is a WiFi/3G MZ601 bought in Sweden. I think the original image was “Build H.6.1-38-1”. I changed the image to “HWI69 for US Retail” (MZ604), installed the over-the-air updates and now USB-host is work as it is supposed to.
Hi, this is my first thread, I want to record a call in my app.
Can anyone help me with this task?
I have some code, but the file created by de recorder is empty.
Thanks!
some help
can anyone help me?, please!
first of all what's the phone you have and what's android version you use? i know that call record possible only from 2.3.3 and not on all kernels
I'd like to know this too
I use the one of the bigest russian sites 4PDA, and see that you need custom kernel with recording option: that you can to use aftermarket app. http://forum.xda-developers.com/showthread.php?t=488475
well, the thing is I need to make a recording app, but the code get stack in the record state, like a loop, and the activity don't refresh
it's a dev problem. if anyone have some code of info, post it please!
thanks a lot!
need a brainstorm or a good teacher
last chance to this thread...
some android dev to help me?
Although it might be a problem with your code at the moment, it ultimatively is a problem with the kernel.
The android api natively allows you to use i.e. a MediaRecorder and just select the call as source.
BUT on most kernels it doesn't work because it is intentionally crippled by the manufactor to avoid legal problems.
That being said, how can anyone help you with your code, if you don't show it.
I use a good aplication to record all the calls in my android phone. The aplication is CallRecorder 1.0.43 alpha. It's perfect for me in my hd2 with a TBD 3.5 room. In a other sites i see another version 1.1.5 trial, but i don't wannna change the things working good.
Dark3n said:
Although it might be a problem with your code at the moment, it ultimatively is a problem with the kernel.
The android api natively allows you to use i.e. a MediaRecorder and just select the call as source.
BUT on most kernels it doesn't work because it is intentionally crippled by the manufactor to avoid legal problems.
That being said, how can anyone help you with your code, if you don't show it.
Click to expand...
Click to collapse
U r right Dark3n...here is...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this._fileTrace = new FileTraceListener();
try {
File myNewFolder = new File(REPOSITORY + "/logs/");
if (!myNewFolder.exists())
myNewFolder.mkdirs();
this._logFileName = "/calldate" + sdf.format(c1.getTime()) + ".log";
this._fileTrace.open(myNewFolder.toString() + _logFileName);
} catch (Exception exc) {
exc.printStackTrace();
this._fileTrace.close();
this._fileTrace = null;
}
}
protected void onResume() {
super.onResume();
setContentView(R.layout.testcallactivity);
try {
_CurrTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
} catch (Exception exc) {
exc.printStackTrace();
}
phoneListener = new PhoneStateListener() {
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
if (call) { //call is a boolean
recorder.stop();
recorder.release();
}
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
call = true; recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL); recorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(REPOSITORY + "/calls/audio.3gp");
recorder.setMaxDuration(30000);
try {
recorder.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
recorder.start();
break;
case TelephonyManager.CALL_STATE_RINGING:
if (call) {
recorder.stop();
recorder.release();
}
break;
}
}
};
_CurrTelephonyManager.listen(phoneListener,
PhoneStateListener.LISTEN_CALL_STATE);
}
Thanks!
Well yeah... No...
Post here, post link
https://gist.github.com/
Dark3n said:
Well yeah... No...
Post here, post link
https://gist.github.com/
Click to expand...
Click to collapse
great web...
https://gist.github.com/1829663
thankz again!
Took a quick glance.
Looks okay, most likely what i already mentioned.
Code:
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
Your kernel has the VOICE_CALL crippled. You will need an uncrippled one for your device.
Dark3n said:
Took a quick glance.
Looks okay, most likely what i already mentioned.
Code:
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
Your kernel has the VOICE_CALL crippled. You will need an uncrippled one for your device.
Click to expand...
Click to collapse
this is the problem?
the statement recorder.play() stock becuase the kernel has the VOICE_CALL crippled, I try it in the AVD from Android SDK, you know if I can chance something to probe my code?
At the moment I try to change VOICE_CALL to MIC and post again whit the result
Thanks again men!
Well, I probe with MIC and DEFAULT, but the application still block in the recorder.start()
I'm going INSANE!!! LOL!
well, even if I made a simply record app, the statement recorder.start() still block my app.
some tips to this crazy bug?