PROFESSIONAL NEWSGROUPS
WINDEV
,
WEBDEV
and
WINDEV Mobile
Home
|
Recent messages
|
Connect
|
Sign out
|
English
Home
→
WINDEV Mobile 2024
→
lancer un backgroundservice en code java
lancer un backgroundservice en code java
Started by Niels, Jun., 26 2017 11:01 AM - No answer
Connect yourself…
Niels
#1
Posted on June, 26 2017 - 11:01 AM
bonjour,
j'essaie de lancer un backgroudservice en code java dans WINDEV Mobile 22.
J'ai essaié tous les choses possible pour le lancer mais il n'y a rien que marche.
Le code marche dans un application android separée.
le code dans windev
android.content.Context activity = getApplicationContext();
activity.startService(new android.content.Intent(activity, be.mydigi.BlueToothService.class));
et le code de OnCreate() pour le service.
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
arrayForBlueToothDevice = new ArrayList
();
if (Debug)
Log.e(TAG, "===onCreate==");
final BluetoothManager bluetoothManager =
(BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter = bluetoothManager.getAdapter();
// Checks if Bluetooth is supported on the device.
if (mBluetoothAdapter == null) {
Toast.makeText(this, "error_bluetooth_not_supported", Toast.LENGTH_SHORT).show();
}
mBluetoothAdapter.enable();
//To monitor reader connection status
//#1, register card status monitoring
BlueToothReceiver.registerCardStatusMonitoring(mHandler);
//MyBroadcastReceiver
receiver = new BlueToothReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction("android.bluetooth.device.action.ACL_CONNECTED");
filter.addAction("android.bluetooth.device.action.ACL_DISCONNECTED");
filter.addAction("android.bluetooth.device.action.FOUND");
filter.addAction("android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED");
//register receiver
registerReceiver(receiver, filter);
try {
OutputStream out = new FileOutputStream(Environment.getExternalStorageDirectory().getAbsolutePath() + "/config.txt");
outputStreamWriter = new OutputStreamWriter(out);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
outputStreamWriter.write("hello");
} catch (IOException e) {
e.printStackTrace();
}
final Handler h = new Handler();
final int delay = 180000; //milliseconds
h.postDelayed(new Runnable() {
public void run() {
//do something
serviceStarted = true;
fethianHasEID();
h.postDelayed(this, delay);
}
}, delay);
return super.onStartCommand(intent, flags, startId);
}
Report
0
0
→ Go back to WINDEV Mobile 2024
WINDEV 2024
WEBDEV 2024
WINDEV Mobile 2024
WINDEV (earlier versions)
Français
English
Español
Portuguesa
Close this window
Search type
Only topics
All the messages
Search period
Any time
Past hour
Past 24 hours
Past week
Past month
Past year
Cancel
Preview of your message
Adding an image
Import an image from a URL
Send an image from a file of your disk
Drop a file or click "Browse..."
or
Cancel
0%
WLanguage
SQL
XML, HTML
JAVA, Javascript
Text