[Q] Bluetooth toggle from within app - Windows Phone 7 Q&A, Help & Troubleshooting

I want toggle bluetooth states from within the app i'm making between off, connectable & discoverable and connectable.....
i've tried
Code:
private void radioButton1_Checked(object sender, RoutedEventArgs e)
{
Phone.OS.Bluetooth.Turn(Phone.OS.Bluetooth.BTH_RADIO_MODE.BTH_POWER_OFF);
}
private void radioButton2_Checked(object sender, RoutedEventArgs e)
{
Phone.OS.Bluetooth.Turn(Phone.OS.Bluetooth.BTH_RADIO_MODE.BTH_CONNECTABLE);
}
private void radioButton3_Checked(object sender, RoutedEventArgs e)
{
Phone.OS.Bluetooth.Turn(Phone.OS.Bluetooth.BTH_RADIO_MODE.BTH_DISCOVERABLE);
}
how do I get this done?

Related

help with this code

i wnat to use the random outside the method
plz help
Code:
public class asd2 extends Activity {
private Button Button01;
private Button Button02;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button01 = (Button) findViewById(R.id.Button01);
Button02 = (Button) findViewById(R.id.Button02);
final SeekBar seekBar01 = (SeekBar) findViewById(R.id.SeekBar01);
final Random anyrandom = new Random();
final EditText EditText01 = (EditText) findViewById(R.id.EditText01);
Button01.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// i need help to move to other activity in my app with this
// intent
Intent asdintenet = new Intent(this, secjavafile);
startActivity(asdintenet);
// this is the random i want to use (asdrandom)outside this
// method
int asdrandom = anyrandom.nextInt(30) + 1;
seekBar01.setProgress(asdrandom);
}
});
Button02.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
seekBar01
.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar,
int progress, boolean fromUser) {
/*
* I WANT to use the random here e.g
* EditText01.setText("progress is"+asdrandom);when i
* use progress int the app crash
*/
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}
}
this file contains the project
as u c I'm beginner
i;ve solved one
i used string.valueof(progress)
any help with intent to other activity???

[Q] DEV get the outgoing call number: howto?

I'm developing my first application.
I've done a service that get the phone calls and does something...
No problem for incoming calls, the telephonymanager with his phonestatelistener gives me the incoming number in the CALL_STATE_RINGING, but how to get the outgoing call number?
I'm getting mad!
thanks for any help.
rabarama said:
I'm developing my first application.
I've done a service that get the phone calls and does something...
No problem for incoming calls, the telephonymanager with his phonestatelistener gives me the incoming number in the CALL_STATE_RINGING, but how to get the outgoing call number?
I'm getting mad!
thanks for any help.
Click to expand...
Click to collapse
Stop getting mad! Dark3n comes to your rescue!
You are right phonestate listener doesn't give you the outgoing calls.
You will have to make a broadcast receiver for "android.intent.action.NEW_OUTGOING_CALL", the intent you get will have an extra "Intent.EXTRA_PHONE_NUMBER" and thats the outgoing call number.
btw you the permission "android.permission.PROCESS_OUTGOING_CALLS" to do this
May your first application be downloaded lots of times
Thanks a lot, but i'm not totally out of troubles...
How to get the broadcastReceiver inside my service?
I tried only inserting a inner class inside my service but it gives me error when i make a call...
i post some code...
Code:
package mypackage;
import ...
public class MyService extends Service {
String TELEPHONENUMBER="";
//here is the problem...
public class OutgoingCallReceiver extends BroadcastReceiver {
public void onReceive(Context context, final Intent intent) {
if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
TELEPHONENUMBER = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER");
}
}
}
@Override
public void onCreate() {
super.onCreate();
try{
TelephonyManager telephonyManager=(TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);;
PhoneStateListener listener;
listener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
String stateString = "N/A";
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
//if the previous state was offhook tellme "i had a call with TELEPHONENUMBER"
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
//if previous state wasn't ringin HERE I HAVE TO GET THE OUTGOING CALL NUMBER...
break;
case TelephonyManager.CALL_STATE_RINGING:
//get TELEPHONENUMBER fron incoming call and do something
TELEPHONENUMBER=incomingNumber;
break;
}
}
};
telephonyManager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);
}catch(Exception ie){}
}
how to simply register a litener for outgoingcalls as i did with phonestatelistener?
SOLVED
SOLVED!!
ok, i'm now dancing naked and drunk...
it was quite easy in effect...
I post some code for who will be in my situation...
If you have to get phone numbers from incoming and outgoing calls in a service this could be one way...
Code:
package mypackage;
import ...
public class MyService extends Service {
@Override
public void onCreate() {
super.onCreate();
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
br=new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
try {
if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
TELEPHONENUMBER = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER");
}
} catch (Exception e) {
}
}
};
this.registerReceiver(br,new IntentFilter("android.intent.action.NEW_OUTGOING_CALL"));
try{
TelephonyManager telephonyManager=(TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
PhoneStateListener listener;
listener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
String stateString = "N/A";
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
//do what you want
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
//do what you want
break;
case TelephonyManager.CALL_STATE_RINGING:
TELEPHONENUMBER=incomingNumber;
//do what you want
break;
}
};
telephonyManager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);
}catch(Exception ie){}
}
Awesome !
I recommend unregistering your receiver like this.
@Override
public void onDestroy() {
this.unregisterReceiver(br);
super.onDestroy();
}
Click to expand...
Click to collapse
In your service.
make call without intents
Hi all,
I have a specific problem hopefully someone can help me..
I would like to make an Android application to measure and diagnose
mobile networks. Hence I have to make calls and meanwhile check the
mobile network parameters.
I tried to use ACTION_DIAL intent but in this case I cannot get
parameters of calls (e.g. call setup time)because the intent hides it.
I debugged it and checked what happen in the sdk when setup a call but
I couldn't find out.
I look into the sdk's internal telephony package and try to find the
class which use the dial function, I found several classes and I gone
through them by the callhierarchy.
Finally I got to the CallManager class and I didn't find further class
which use this class' dial function.
Please help me to find a way to make a call without intents.
Someone of you have a good hint for me?
Another issue: Is it possible to simulate a speech to play a voice file (mp3, wav etc) during a call?
Could someone help me about this issue?
Thanks in advance!
speky
Tried to record call\s using the above code.. some probs..
Dark3n said:
Awesome !
I recommend unregistering your receiver like this.
In your service.
Click to expand...
Click to collapse
thanks.. Dark3n.. For your useful code... I used theese code to record incoming & outgoing calls.. It records the calls only one after the other...
..
If 1,2,3,4,5,6,7 are the calls i made.
Then 1(Call recorded,service killed),2(Service Started,Call not recorded),3(Call recorded,service killed),4(Service Started,Call not recorded),5(Call recorded,service killed),6(Service Started,Call not recorded),7(Call recorded,service killed)......
Why this happens....Any solutions to record all calls from service??
Thanks in advance..
HEre is my code..
package com.exampled.demoserv;
import java.io.File;
import java.io.IOException;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.MediaRecorder;
import android.os.Environment;
import android.os.IBinder;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.widget.Toast;
public class ParentalService extends Service {
String TELEPHONENUMBER;
boolean recording=false;
final MediaRecorder recorder=new MediaRecorder();
@Override
public void onCreate() {
super.onCreate();
//NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Toast.makeText(getApplicationContext(), "Service created", Toast.LENGTH_SHORT).show();
BroadcastReceiver br=new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
try {
if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
TELEPHONENUMBER = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER");
}
} catch (Exception e) {
}
}
};
this.registerReceiver(br,new IntentFilter("android.intent.action.NEW_OUTGOING_CALL"));
startMonitoring();
}
public void startMonitoring()
{
TelephonyManager mTelephonyMgr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
mTelephonyMgr.listen(new TeleListener(), PhoneStateListener.LISTEN_CALL_STATE);
}
class TeleListener extends PhoneStateListener
{
@Override
public void onCallStateChanged(int state, String incomingNumber) {
String stateString = "N/A";
switch (state)
{
case TelephonyManager.CALL_STATE_IDLE:
Toast.makeText(getApplicationContext(), "CALL_STATE_IDLE", Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "Stop CaLLED "+recording+TELEPHONENUMBER, Toast.LENGTH_LONG).show();
stopRecording();
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Toast.makeText(getApplicationContext(), "CALL_STATE_OFFHOOKing"+TELEPHONENUMBER, Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "Start CaLLED "+recording+TELEPHONENUMBER, Toast.LENGTH_LONG).show();
startRecording();
break;
case TelephonyManager.CALL_STATE_RINGING:
TELEPHONENUMBER=incomingNumber;
Toast.makeText(getApplicationContext(), "CALL_STATE_RINGINGini:"+TELEPHONENUMBER, Toast.LENGTH_SHORT).show();
break;
}
}
}
public void startRecording()
{
if(recording==false)
{
Toast.makeText(getApplicationContext(), "Recorder_Sarted"+TELEPHONENUMBER, Toast.LENGTH_LONG).show();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
String file= Environment.getExternalStorageDirectory().toString();
String filepath= file+"/11111111111111";
File dir= new File(filepath);
dir.mkdirs();
filepath+="/"+TELEPHONENUMBER+".3gp";
recorder.setOutputFile(filepath);
try {
recorder.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
recorder.start();
recording=true;
}
}
public void stopRecording()
{
if(recording==true)
{
Toast.makeText(getApplicationContext(), "Recorder_Relesed from "+recording, Toast.LENGTH_LONG).show();
recorder.stop();
recorder.reset();
recorder.release();
recording=false;
}
}
@Override
public IBinder onBind(Intent intent)
{
// TODO Auto-generated method stub
return null;
}
}
Click to expand...
Click to collapse

Simple MediaPlayer project, problems WP7

I'm trying to create simple mediaplayer and using MediaPlayer Class, but I have some problems. When I select song from the list, my buttons Next and Prev stopped working. I try some things but nothing works, what I have to do, to fix this problem. I don't know how to use EventHandler - MediaStateChanged, will see this in the code below. I want to add simple progress bar, but this class don't have current position event. I read some about DispatcherTimer, but ...
The code:
Code:
namespace MediaViewer
{
public partial class MainPage : PhoneApplicationPage
{
private App app;
int songIndexForDetails;
public MainPage()
{
InitializeComponent();
app = Application.Current as App;
List<CategoryDetailsViewModel> items = new List<CategoryDetailsViewModel>();
items.Add(app.MusicModel);
PivotControl.ItemsSource = items;
ProgressBar.Visibility = Visibility.Collapsed;
txtCurrentState.Text = MediaPlayer.State.ToString();
}
private void ItemsListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ListBox list = (ListBox)sender;
int selectedCategoryIndex = list.SelectedIndex;
songIndexForDetails = list.SelectedIndex;
if (selectedCategoryIndex == -1)
return;
List<CategoryDetailsViewModel> model = PivotControl.ItemsSource as List<CategoryDetailsViewModel>;
if (model[PivotControl.SelectedIndex].IsAnyItemAvailable())
{
if (model[PivotControl.SelectedIndex].PrepareItemForPreview(selectedCategoryIndex))
{
if (model[PivotControl.SelectedIndex] is MusicCategoryModel)
{
MediaLibrary library = new MediaLibrary();
FrameworkDispatcher.Update();
MediaPlayer.Play(library.Songs[selectedCategoryIndex]);
ProgressBar.Visibility = Visibility.Visible;
txtCurrentState.Text = MediaPlayer.State.ToString();
}
}
else
MessageBox.Show("Warining!\n\nUnable to open selected file.\nMake sure that your device is disconnected from the computer.");
}
}
private void detailsButton_Click(object sender, RoutedEventArgs e)
{
if (songIndexForDetails == -1)
{
return;
}
NavigationService.Navigate(new Uri("/Pages/SongDetailsPage.xaml?SelectedItem=" + songIndexForDetails, UriKind.Relative));
}
private void pauseButton_Click(object sender, RoutedEventArgs e)
{
MediaPlayer.Pause();
ProgressBar.Visibility = Visibility.Collapsed;
txtCurrentState.Text = MediaPlayer.State.ToString();
}
private void stopButton_Click(object sender, RoutedEventArgs e)
{
MediaPlayer.Stop();
ProgressBar.Visibility = Visibility.Collapsed;
txtCurrentState.Text = MediaPlayer.State.ToString();
}
private void playButton_Click(object sender, RoutedEventArgs e)
{
MediaLibrary library = new MediaLibrary();
FrameworkDispatcher.Update();
if (MediaPlayer.State == MediaState.Paused)
{
MediaPlayer.Resume();
}
else
{
MediaPlayer.Play(library.Songs);
ProgressBar.Visibility = Visibility.Visible;
txtCurrentState.Text = MediaPlayer.State.ToString();
}
}
private void nextButton_Click(object sender, RoutedEventArgs e)
{
MediaPlayer.MoveNext();
}
private void previousButton_Click(object sender, RoutedEventArgs e)
{
MediaPlayer.MovePrevious();
}
public Song GetModelForIndex(int itemIndex)
{
if (itemIndex < Songs.Count)
return Songs[itemIndex];
else
return null;
}
private List<Song> Songs { get; set; }
}
}

I need help with my android project

could you help me figure out how can i stop sound with mediaplayer after clicking another soundbutton?
*and how can i set alarm/ringtone/notification when long press
*and i need help with adding admob on my app, ive read all posts i could google but still i get errors, i cant understand what am i doing wrong, if anybody wishes to help me please pm me your skype.
thank you very much.
code:
final MediaPlayer sound01 = MediaPlayer.create(this, R.raw.sound01);
Button s01 = (Button) findViewById(R.id.button01);
s01.setText(this.getString(R.string.quote01));
s01.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try {
sound01.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
sound01.start();
}
Stop sound
Add this in your app:
Button s02 = (Button) findViewById(R.id.button02);
s02.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
sound01.stop();
}
});
thanks for posting mate, but when i added it, it will only play the first sound when i start the app, after i press the second button and then want to play the first button again it wont start...
also i have like 20 sounds, and for example if i want to play like sound 4 and then sound one again how will it stop?
Button s01 = (Button) findViewById(R.id.button01);
s01.setText(this.getString(R.string.quote01));
s01.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try {
sound01.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
sound01.start();
}
});
registerForContextMenu(s01);
Button s02 = (Button) findViewById(R.id.button02);
s02.setText(this.getString(R.string.quote02));
s02.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
sound01.stop();
try {
sound02.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
bump
still need help with my project.... is this thing really so hard that few ppl only know how to do it?
please i still need help with my code | bump
bump
MediaPlayer might not be what you want.
For playing sounds in an app try AsyncPlayer or AudioTrack.
(Note also that MediaPlayer.create() already does a prepare().)
thank you for posting, but im still very noob at this thing, could you copy me a code that works ? or help me add stuff to it? im looking in to that asyncplayer you suggested

[Q] Sending "string" serially (byte code given)

Hi all,
I am developing an android app for my project which sends data serially, through RS232 + OTG cable, to a circuit developed by me (and the PC code for which is already done and developed in C#). I'm new to android and tried to get help from example apps. i found an app which establishes the serial communication successfully but the problem is that it sends data in the form of byte, but i want data to be sent as a string and also received as a string. portion of the activity of interest is being added which sends binary 10101010... but I want data in string format. like "abcdefg". it must also be noted that this code is ignoring the incoming data but i want the incoming data to be stored in a variable (which i think is not very difficult but it could be handy if someone can also guide about that)
if someone can help, it'll be highly appreciated
Code:
package android_serialport_api.sample;
import java.io.IOException;
import java.util.Arrays;
import android.os.Bundle;
import java.io.*;
import java.util.*;
//import javax.comm.*; // for SUN's serial/parallel port libraries
public class Sending01010101Activity extends SerialPortActivity {
SendingThread mSendingThread;
byte[] mBuffer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sending01010101);
mBuffer = new byte[1024];
Arrays.fill(mBuffer, (byte) 0x55);
if (mSerialPort != null) {
mSendingThread = new SendingThread();
mSendingThread.start();
}
}
@Override
protected void onDataReceived(byte[] buffer, int size) {
// ignore incoming data
}
private class SendingThread extends Thread {
@Override
public void run() {
while (!isInterrupted()) {
try {
if (mOutputStream != null) {
mOutputStream.write(mBuffer);
} else {
return;
}
} catch (IOException e) {
e.printStackTrace();
return;
}
}
}
}
}
not enough info is availabe on the internet on this topic and I only expect help from this forum. its very important for me

Categories

Resources