Код: Выделить всё
notif.flags |= Notification.FLAG_FOREGROUND_SERVICE;
startForeground(1, notif);
Код: Выделить всё
notif.flags |= Notification.FLAG_FOREGROUND_SERVICE;
startForeground(1, notif);
Тут смотрели? http://developer.android.com/guide/topi ... ement.htmlpowercat писал(а):А можно пояснить? Взял из Инета пример
<receiver android:name=".MyReceiver " android:enabled="true" android:exported="false">
Что тут значит enable и exported?
И что вообще сюда можно засунуть и для чего?
Хелп сообщает, что это только для бродкастов фишка:Andy_ua писал(а):вопрос по поводу автозагрузкт сервиса
почему нельзя сразу прописать в интенет фильтре сервиса в манифесте
<action android:name="android.intent.action.BOOT_COMPLETED" />
?
Broadcast Action: This is broadcast once, after the system has finished booting.
нужно чтобы сервис сам запустился. был в автозагрузке.
Код: Выделить всё
public class BootUpReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
//для Activity
// Intent ativivtyIntent = new Intent(context, GPSSampleActivity.class);
// ativivtyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// context.startActivity(ativivtyIntent);
// String mountState = Environment.getExternalStorageState();
// int tries = 7;
// do {
// if (!mountState.equals(Environment.MEDIA_MOUNTED)) {
// Log.i("BootUpReceiver", "External media present but not mounted. Waiting 7 seconds for mount...");
// try {
// Thread.sleep(1000); // sleep for a second
// } catch (InterruptedException e) {
// Log.w("BootUpReceiver", "Interrupted!");
// break;
// }
// mountState = Environment.getExternalStorageState();
// } else {
// Log.i("BootUpReceiver", "External media mounted");
// break;
// }
// } while (--tries > 0);
//для Service
Intent serviceIntent = new Intent(context, YourServiceName.class);
context.startService(serviceIntent);
}
Код: Выделить всё
<application
...
<receiver
android:name="your.package.BootUpReceiver"
android:enabled="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
при остановке сразу же запустился.
Код: Выделить всё
Листинг 9.7. Повышение приоритета для Сервиса
int NOTIFICATION_ID = 1;
Intent intent = new Intent(this, MyActivity.class);
PendingIntent pi = PendingIntent.getActivity(this, 1, intent, 0));
Notification notification = new Notification(R.drawable.icon, "Running in the Foreground", System.currentTimeMillis());
notification.setLatestEventInfo(this, "Title", "Text", pi);
notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;
startForeground(NOTIFICATION_ID, notification);
еще проверка интернет включен или нет
Код: Выделить всё
private void createInternetStatusReceiver() {
networkStateReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
try {
if ( ( (connectManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)!=null)
&& (connectManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED) )
|| ( (connectManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)!=null)
&& (connectManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI ).getState() == NetworkInfo.State.CONNECTED) ) )
internetAvailable = true;
else
internetAvailable = false;
} catch (Exception e) {
internetAvailable = true;
}
}
};
IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(networkStateReceiver, filter);
}
Смотреть LocationListenerи нахождение gps координат.
какие теги? Подчеркивание переменных или что? Что делать он должен?как в эклипсе включить эти теги ну чтоб код читать нормально. я что то не могу найти.