Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.61 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3. package="com.phx.batterylogger"
  4. android:versionCode="1"
  5. android:versionName="1.0"
  6. android:installLocation="internalOnly">
  7.  
  8. <uses-sdk android:minSdkVersion="8" />
  9. <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
  10. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  11. <uses-permission android:name="android.permission.BATTERY_STATS" />
  12.  
  13. <application android:icon="@drawable/icon" android:label="@string/app_name">
  14. <service android:name=".BatteryLogger"/>
  15. <receiver android:name=".StartupIntentReceiver">
  16. <intent-filter>
  17. <action android:name="android.intent.action.BOOT_COMPLETED" />
  18. </intent-filter>
  19. </receiver>
  20. </application>
  21.  
  22. </manifest>
  23.  
  24. package com.phx.batterylogger;
  25.  
  26. import android.content.BroadcastReceiver;
  27. import android.content.Context;
  28. import android.content.Intent;
  29.  
  30. public class StartupIntentReceiver extends BroadcastReceiver {
  31. @Override
  32. public void onReceive(Context context, Intent intent) {
  33. Intent serviceIntent = new Intent(context, BatteryLogger.class);
  34. context.startService(serviceIntent);
  35. }
  36. }
  37.  
  38. <?xml version="1.0" encoding="utf-8"?>
  39. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  40. package="pack.saltriver" android:versionCode="1" android:versionName="1.0"
  41. android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
  42.  
  43. <application android:icon="@drawable/icon" android:label="@string/app_name">
  44.  
  45. <receiver android:name=".autostart">
  46. <intent-filter>
  47. <action android:name="android.intent.action.BOOT_COMPLETED" />
  48. </intent-filter>
  49. </receiver>
  50.  
  51. <activity android:name=".hello"></activity>
  52. <service android:enabled="true" android:name=".service" />
  53. </application>
  54. <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
  55. </manifest>
  56.  
  57. public class autostart extends BroadcastReceiver
  58. {
  59. public void onReceive(Context arg0, Intent arg1)
  60. {
  61. Intent intent = new Intent(arg0,service.class);
  62. arg0.startService(intent);
  63. Log.i("Autostart", "started");
  64. }
  65. }
  66.  
  67. public class service extends Service
  68. {
  69. private static final String TAG = "MyService";
  70. @Override
  71. public IBinder onBind(Intent intent) {
  72. return null;
  73. }
  74. public void onDestroy() {
  75. Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show();
  76. Log.d(TAG, "onDestroy");
  77. }
  78.  
  79. @Override
  80. public void onStart(Intent intent, int startid)
  81. {
  82. Intent intents = new Intent(getBaseContext(),hello.class);
  83. intents.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  84. startActivity(intents);
  85. Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
  86. Log.d(TAG, "onStart");
  87. }
  88. }
  89.  
  90. public class hello extends Activity
  91. {
  92. public void onCreate(Bundle savedInstanceState)
  93. {
  94. super.onCreate(savedInstanceState);
  95. setContentView(R.layout.main);
  96. Toast.makeText(getBaseContext(), "Hello........", Toast.LENGTH_LONG).show();
  97. }
  98. }
  99.  
  100. public class MyReceiver extends BroadcastReceiver{
  101.  
  102. @Override
  103. public void onReceive(Context context, Intent intent) {
  104. Log.d("TAG", "MyReceiver");
  105. Intent serviceIntent = new Intent(context, Test1Service.class);
  106. context.startService(serviceIntent);
  107. }
  108. }
  109.  
  110.  
  111.  
  112.  
  113. public class Test1Service extends Service {
  114. /** Called when the activity is first created. */
  115. @Override
  116. public void onCreate() {
  117. super.onCreate();
  118. Log.d("TAG", "Service created.");
  119. }
  120.  
  121. @Override
  122. public int onStartCommand(Intent intent, int flags, int startId) {
  123. Log.d("TAG", "Service started.");
  124. return super.onStartCommand(intent, flags, startId);
  125. }
  126.  
  127. @Override
  128. public void onStart(Intent intent, int startId) {
  129. super.onStart(intent, startId);
  130. Log.d("TAG", "Service started.");
  131. }
  132. @Override
  133. public IBinder onBind(Intent arg0) {
  134. return null;
  135. }
  136. }
  137.  
  138.  
  139.  
  140.  
  141. <?xml version="1.0" encoding="utf-8"?>
  142. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  143. package="com.test"
  144. android:versionCode="1"
  145. android:versionName="1.0"
  146. android:installLocation="internalOnly">
  147. <uses-sdk android:minSdkVersion="8" />
  148.  
  149. <application android:icon="@drawable/icon" android:label="@string/app_name">
  150.  
  151. <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
  152. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  153. <uses-permission android:name="android.permission.BATTERY_STATS"
  154. />
  155. <!-- <activity android:name=".MyActivity">
  156. <intent-filter>
  157. <action android:name="android.intent.action.MAIN" />
  158. <category android:name="android.intent.category.LAUNCHER"></category>
  159. </intent-filter>
  160. </activity> -->
  161. <service android:name=".Test1Service"
  162. android:label="@string/app_name"
  163. >
  164. </service>
  165. <receiver android:name=".MyReceiver">
  166. <intent-filter>
  167. <action android:name="android.intent.action.BOOT_COMPLETED" />
  168. </intent-filter>
  169. </receiver>
  170. </application>
  171. </manifest>
  172.  
  173. <receiver android:name=".StartupIntentReceiver">
  174.  
  175. <receiver android:name="com.your.package.AutoStart">
  176.  
  177. package com.test.juxo.testservice;
  178.  
  179. import android.app.Service;
  180. import android.content.Intent;
  181. import android.os.Handler;
  182. import android.os.IBinder;
  183. import android.util.Log;
  184.  
  185. public class MonService extends Service {
  186. @Override
  187. public void onDestroy() {
  188. Log.v("LTM", "onDestroy");
  189. super.onDestroy();
  190. }
  191.  
  192. @Override
  193. public int onStartCommand(Intent intent, int flags, int startId) {
  194. Log.v( "LTM","onStartCommand" );
  195. int i = super.onStartCommand(intent, flags, startId);
  196. Thread monT = new Thread(new Sender());
  197. monT.start();
  198. return i;
  199. }
  200.  
  201. @Override
  202. public IBinder onBind( Intent arg0 ) {
  203. Log.v( "LTM","onBind" );
  204. return null;
  205. }
  206. }
  207.  
  208. package com.test.juxo.testservice;
  209.  
  210. import android.content.BroadcastReceiver;
  211. import android.content.Context;
  212. import android.content.Intent;
  213. import android.util.Log;
  214.  
  215. public class MyReceiver extends BroadcastReceiver {
  216. @Override
  217. public void onReceive( Context ctx, Intent i ) {
  218.  
  219. Log.v("LTM", "MyReceiver.onReceive : " + i.getAction());
  220.  
  221. Intent intent = new Intent( ctx, MonService.class );
  222. ctx.startService(intent);
  223. }
  224. }
  225.  
  226. <?xml version="1.0" encoding="utf-8"?>
  227. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  228. package="com.test.juxo.testservice"
  229. android:versionCode="1"
  230. android:versionName="1.1" >
  231.  
  232. <uses-sdk android:minSdkVersion="8" />
  233.  
  234. <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
  235.  
  236. <application
  237. android:icon="@drawable/ic_launcher"
  238. android:label="@string/app_name" >
  239. <service
  240. android:name="com.test.juxo.testservice.MonService"
  241. android:label="Mon beau service"
  242. android:enabled="true"
  243. android:exported="false" >
  244. </service>
  245.  
  246. <receiver
  247. android:name="com.test.juxo.testservice.MyReceiver"
  248. android:enabled="true"
  249. android:exported="false" >
  250. <intent-filter>
  251. <action android:name="android.intent.action.BOOT_COMPLETED" />
  252. </intent-filter>
  253. </receiver>
  254. </application>
  255.  
  256. </manifest>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement