Bonjour,
Je souhaiterais créer un service lors du démarrage du smartphone pour pouvoir par la suite envoyer des notifications.
Cependant, lorsque je compile et execute, android studio me met ce message : client not ready yet.
Pourriez vous me dire ce qu'il faut que je fasse pour que mon programme fonctionne ?
Voici les codes :
le service :
le receiver :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.util.Log; public class Monservice extends Service { public Monservice() { } @Override public IBinder onBind(Intent arg0) { // TODO Auto-generated method stub return null; } @Override public void onRebind(Intent intent) { super.onRebind(intent); Log.d("TestApp", ">>>onRebind()"); } @Override public void onCreate() { super.onCreate(); Log.d("TestApp", ">>>onCreate()"); } @Override public void onStart(Intent intent, int startId) { super.onStart(intent, startId); Log.d("TestApp", ">>>onStart()"); } @Override public boolean onUnbind(Intent intent) { return super.onUnbind(intent); } }
le manifest :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.telephony.PhoneStateListener; import android.telephony.TelephonyManager; import android.util.Log; public class Myreceiver extends BroadcastReceiver { public static final String TAG = "TestApp"; @Override public void onReceive(Context context, Intent intent) { Log.d("TestApp", "Got the Boot Event>>>"); Log.d("TestApp", "Starting MySimpleService>>>"); context.startService(new Intent().setComponent(new ComponentName( context.getPackageName(), Monservice.class.getName()))); } }
Cordialement
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 <manifest xmlns:android="http://schemas.android.com/apk/res/android" <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <service android:label="mon service" android:name=".Monservice" android:exported="true"> </service> <receiver android:name=".Myreceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <category android:name="android.intent.category.HOME" /> </intent-filter> </receiver> </application> </manifest>
Partager