Data Transfer from Andread Wear Watch to phone via bluetooth - Wear OS Q&A, Help & Troubleshooting

Hello,
I'm currently trying to send a textfile from the wearable (MOTO 360 Android 5.1.1) to my phone (Moto X Android 4.4.4) via bluetooth, but when i execute the "onSendToPhone" method I get the following error message on the watch:
No application can handle this action
Maybe someone can help me and find a solution
This is the code I use to transfer data from the watch:
Code:
public void onSendToPhone(View view)
{
//...
// inside method
// Check if bluetooth is supported
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
if (btAdapter == null) {
// Device does not support Bluetooth
// Inform user that we're done.
Log.d("TAG","Bluetooth not found");
return;
}
File sendFile= new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "<filename>");
// bring up Android chooser
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(sendFile));
startActivity(intent);
Log.d("TAG", "File is sent via Bluetooth");
}

Related

Getting back from security & location to my application

Hi,
I have an application that allows the user to enable GPS.
In order to do it, first in the main activity I do:
Code:
lm = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
if (!lm.isProviderEnabled(LocationManager.GPS_PROVIDER)){
showGpsOptions();
}
showGpsOptions() is:
Code:
private void showGpsOptions()
{
Intent gpsOptionsIntent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivityForResult(gpsOptionsIntent, BACK_FROM_GPS_ACT);
}
and finally I override main activity onActivityResult in this way:
Code:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == BACK_FROM_GPS_ACT){
;
}
super.onActivityResult(requestCode, resultCode, data);
}
Problem: the page show up and works, but when I press back I get back to home screen.
Question: how can I get back to my application?
Thanks a lot

[Q] Problem to run the Torch from source

Hello, i have downloaded the Torch source code from cyanogen repository and i have this problem:
1º I put the code in a empty project in Eclipse
2º I havent errors and the code compile correctly
3º I run the app in my device (Nexus One) and work well all buttons and options, but when i press in "On" button for active i get a error and the app crash.
Debugging i have seen the following:
For active flash i have put a "1" in file "/sys/devices/platform/flashlight.0/leds/flashlight/brightness" (If i put a "1" manually with terminal the flash is active correctly)
In code, we have this:
public class FlashDevice {
private static final String DEVICE = "/sys/devices/platform/flashlight.0/leds/flashlight/brightness";
...
public synchronized void setFlashMode(int mode) {
try {
if (mWriter == null) {
mWriter = new FileWriter(DEVICE);
}
int value = mode;
switch (mode) {
case STROBE:
value = OFF;
break;
case DEATH_RAY:
value = useDeathRay ? DEATH_RAY : HIGH;
break;
}
mWriter.write(String.valueOf(value));
mWriter.flush();
mFlashMode = mode;
if (mode == OFF) {
mWriter.close();
mWriter = null;
}
} catch (IOException e) {
throw new RuntimeException("Can't open flash device: " + DEVICE, e);
}
}
public synchronized int getFlashMode() {
return mFlashMode;
}
}
Click to expand...
Click to collapse
I get this error in line "mWriter = new FileWriter(DEVICE);":
java.io.FileNotFoundException: /sys/devices/platform/flashlight.0/leds/flashlight/brightness (Permission denied)
Someone know the cause????
Try using the original source code from the repository by
Code:
svn checkout http://n1torch.googlecode.com/svn/trunk/ n1torch-read-only
and importing it as a project into eclipse.

FileChooser no Jpg

Hi. I´m from Germany. Sorry for my bad English.
On my Work, there is a Server with Wlan. The Page on this Server is like a Forum (Like XDA).
I´m a beginner in Android, but my app is 90% finish.
Now my Problem. In the Forum page there is "like XDA" an upload button. I have make my Filechooser but there is the problem. When i upload test.pdf or test.bmp. Server says ok, name of the file is test.pdf or test.bmp. So i can upload
My problem is only with jpg. When Filechooser open and i choose the jpg (sdcard0 oder extsdcard) the name on the server gives the picture a number. That means test.jpg = 1983 . Can´t upload.
I hope you understand me, and can give me a fix. Thanks for Help!!!
Here my Code
HTML:
webView.setWebChromeClient(new WebChromeClient() {
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("*/*");
startActivityForResult(Intent.createChooser(i, "File Chooser"),
MainActivity.FILECHOOSER_RESULTCODE);
}
// For Android 3.0+
public void openFileChooser(ValueCallback uploadMsg,
String acceptType) {
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("*/*");
startActivityForResult(Intent.createChooser(i, "File Chooser"),
MainActivity.FILECHOOSER_RESULTCODE);
;
}
// For Android 4.1
public void openFileChooser(ValueCallback<Uri> uploadMsg,
String acceptType, String capture) {
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("*/*");
startActivityForResult(Intent.createChooser(i, "File Chooser"),
MainActivity.FILECHOOSER_RESULTCODE);
}
});
}
[user=439709]@override[/user]
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
if (requestCode == FILECHOOSER_RESULTCODE) {
if (null == mUploadMessage)
return;
Uri result = intent == null || resultCode != RESULT_OK ? null
: intent.getData();
String filePath = result.getPath();
mUploadMessage.onReceiveValue(result);
mUploadMessage = null;
}
}
Hi. Nobody can help me? Plz. I need it.
Plz help. I need it. I spend much time, but i can´t find a fix.

[Q] Android BLE Scan Blocks UI Threads

I am working on an Andriod project with Bluetooth LE. While BLE thread was scanning, this thread blocks other threads such as HTTP request and MediaPlayer . Http request is going to timeout or when i play music with meidplayer in app then app is freezing. I get this problem on thees android devices,Samsung Glaxy Tab SM-T700 and Samsung Galaxy TAB SM-T800. But i do not get this problem on Samsung Galaxy TAB SM-T520 device and any android phones.
Code:
BLE Scan Algorithm ` private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() {
@Override
public void onLeScan(final BluetoothDevice device, final int rssi,
final byte[] scanRecord) {
ac.runOnUiThread(new Runnable() {
@Override
public void run() {
final BluetoothLeDevice deviceLe = new BluetoothLeDevice(
device, rssi, scanRecord, System
.currentTimeMillis());
// mDevices.add(deviceLe);
String rssiString = ac.getString(R.string.formatter_db,
String.valueOf(deviceLe.getRssi()));
if (tempDevice == null) {
tempDevice = deviceLe;
} else {
if (deviceLe.getRunningAverageRssi() > tempDevice
.getRunningAverageRssi()) {
IBeaconDevice newBeacon = new IBeaconDevice(
deviceLe);
IBeaconDevice bestDevice = new IBeaconDevice(
tempDevice);
if (newBeacon.getMajor() != bestDevice.getMajor()
|| newBeacon.getMinor() != bestDevice
.getMinor()) {
tempDevice = deviceLe;
}
}
}
}
// }
});
}
};` Music Play Algorithm . Mediaplayer is initialed before this code ` public void PlayPause() {
Log.e("Çalan", UrlSes);
if (mediaPlayer.isPlaying()) {
mediaPlayer.stop();
mediaPlayer.reset();
}
try {
mediaPlayer.setDataSource(UrlSes); // setup song from
// http://www.hrupin.com/wp-content/uploads/mp3/testsong_20_sec.mp3
// URL to mediaplayer data
// source
mediaPlayer.prepare(); // you must call this method after setup the
// datasource in setDataSource method. After
// calling prepare() the instance of
// MediaPlayer starts load data from URL to
// internal buffer.
} catch (Exception e) {
e.printStackTrace();
}
mediaFileLengthInMilliseconds = mediaPlayer.getDuration(); // gets the
// song
// length in
// milliseconds
// from URL
if (!mediaPlayer.isPlaying()) {
mediaPlayer.start();
imgPlay.setImageResource(R.drawable.footer_pause);
} else {
mediaPlayer.pause();
imgPlay.setImageResource(R.drawable.footer_play);
}
primarySeekBarProgressUpdater();
}` app freeze on mediplayer.prepare() I use mediplayer.prepareasync() but not plyaed . my web Request code `public JSONObject getJSONInfo(String functionName) {
HttpClient client = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000);
HttpResponse response;
JSONObject json = null;
JSONObject send = new JSONObject();
try {
HttpPost post = new HttpPost(
""+url);
send.put("", variable1);
send.put("", variable1);
send.put("", variable2);
send.put("", variable1);
StringEntity se = new StringEntity(send.toString());
se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE,
"application/json"));
Log.e("test", send.toString());
post.setEntity(se);
response = client.execute(post);
if (response.getStatusLine().getStatusCode() == 200) {
json = new JSONObject(
EntityUtils.toString(response.getEntity()));
}
} catch (Exception e) {
e.printStackTrace();
}
return json;
}
I'think This problem not about code or algorithm. Maybe about setting in device. Please help.
Same problem
Hi, did you find any solution for this ? I stucked on same problem and cant find how to solve this problem. :crying:
Thaks a lot for any advice.

Reading\Changing CANbus API for New Car

Hi,
I will get straight to point.I am trying to Understand\Make custom Protocol Setting for a car model.
currently I am using XY Auto 9270 Model and a custom CAN analyzer.
Even if not answered hope follolwing information , will give initial information to developers how are beginningsto reverse engineer in Chinese Android Head Units.
I have note that for my car model,door , stearing data is present at which address , now my challenge is to format the serial packet to be send to Android Head Unit.
I have read that some users have decompiled the CANbus.apk and CANbus2.apk( in my case ) but there is no proof whether after decompiling it worked.What's more important is where to change\look into APK.
Aim 1 - "Debug Canbox serial data input to Android Head Unit"
(Missing - 4th Point )
1) Decompile CANBUS apk.
2) Search for "baud" keyword inside folders.
3) Install Serial-USB-Terminal ( But Serial Port is not listed)
I checked in CanbusSerial.Java located in CanBus2_source_from_JADX\sources\com\canbus\data there is mention of baudrate.
4) I am unable to find a way to view serial data to Headunit inside an APK running on Head Unit.
Aim2 - " Modify APK - Change . Java or .json files of canbus.apk
(Missing - 5th Point )
1)Searched for keyword door.
2) Was able to idetify that there is a location CanBus2_source_from_JADX\sources\com\canbus\json\
this might be location for intializing functions and variables for all car features (doors, aircon, trajectory,key etc.)
For Eg: This is java code for door
CardoorSerial.java - CanBus2_source_from_JADX\sources\com\canbus\json\door
Java:
package com.canbus.json.door;
import com.canbus.json.p001rx.RxData;
import java.util.List;
import java.util.Set;
public class CarDoorSerial {
private List<CarDoor> carDoors;
private Set<RxData> rxDatas;
public Set<RxData> getRxDatas() {
return this.rxDatas;
}
public void setRxDatas(Set<RxData> rxDatas2) {
this.rxDatas = rxDatas2;
}
public List<CarDoor> getCarDoors() {
return this.carDoors;
}
public void setCarDoors(List<CarDoor> carDoors2) {
this.carDoors = carDoors2;
}
public String toString() {
return "CarDoorSerial{rxData=" + this.rxDatas + ", carDoors=" + this.carDoors + '}';
}
}
3. I was also able to identify a file , where most probably packet is being prepared for sending to Parsing Function which will further be send to display functions.
Jsonutils.java - CanBus2_source_from_JADX\sources\com\canbus\json\utils
Java:
public static CarDoorSerial getCarDoorSerial(String json) {
try {
CarDoorSerial carDoorSerial = new CarDoorSerial();
JSONObject carDoorSerialJsonObject = new JSONObject(json);
Set<RxData> rxDatas = new HashSet<>();
List<CarDoor> carDoors = new ArrayList<>();
JSONArray carDoorJsonArray = carDoorSerialJsonObject.getJSONArray("carDoors");
for (int i = 0; i < carDoorJsonArray.length(); i++) {
JSONObject carDoorJsonObject = carDoorJsonArray.getJSONObject(i);
CarDoor carDoor = new CarDoor();
carDoor.setName(carDoorJsonObject.getInt("name"));
carDoor.setDataIndex(carDoorJsonObject.getInt("dataIndex"));
carDoor.setBit(carDoorJsonObject.getInt("bit"));
RxData rxData = new RxData();
rxData.setDataType((byte) Integer.parseInt(carDoorJsonObject.getString("dataType"), 16));
rxData.setLength(Integer.parseInt(carDoorJsonObject.getString("length"), 16));
carDoor.setRxData(rxData);
rxDatas.add(rxData);
carDoors.add(carDoor);
}
carDoorSerial.setRxDatas(rxDatas);
carDoorSerial.setCarDoors(carDoors);
return carDoorSerial;
} catch (JSONException e) {
CatchUtils.catchException(e);
return null;
}
}
4)There is also Canbuserial.Java , In this function there are different serial handler algortihms for different CANbox for eg: Hi World.
Java:
public void RxData(byte[] data, int size) {
int baudRate = CanbusStatus.getBaudRate();
this.handler.removeCallbacks(this.delayOvertime);
this.handler.postDelayed(this.delayOvertime, 500);
for (int i = 0; i < size; i++) {
byte[] bArr = this.rx_save;
int i2 = this.rx_put;
this.rx_put = i2 + 1;
bArr[i2] = data[i];
if (this.rx_put >= MAX_SAVE_BYTES) {
this.rx_put = 0;
}
}
switch (baudRate) {
case 9601:
anyuan_rx_uart();
return;
case 9602:
foton_rx_uart();
return;
case 19200:
elysee_rx_uart();
return;
case 19201:
hyudnai_rx_uart();
return;
case 19202:
qiruiA3_rx_uart();
return;
case 19203:
tpms_rx_uart();
return;
case 19205:
case 38403:
hiWorld_rx_uart_aa55();
return;
case 38401:
hiWorld_rx_uart();
return;
case 38402:
X80_rx_uart();
return;
case 38405:
xp_rx_uart_fd();
return;
case 38406:
xp_rx_uart_aa55();
return;
case 38407:
hiWorld_rx_uart_key();
return;
default:
canbox_rx_uart();
return;
}
}
5) How can I find\change the information inside APK file (json \ Java ) for , changing the parsing array match string ( For EG: If there is any match string after parsing the information ) may be, I can send the information from my CAN device to the Android Unit in similar way.
According to the message on UART being recieved, or how can we know the Parsing algorithm (for EG: Array to which receive strings are being matched to get door data etc.)

Categories

Resources