2016-07-29 113 views
-1

我的應用程序由名爲FirstService.Java的服務組成。錯誤關閉應用程序以啓動Android服務

當設備連接要啓動服務 但是一個錯誤的服務鼐啓動:關閉應用

我這個代碼:

StartService.java

import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent; 
import android.widget.Toast; 

public class StartService extends BroadcastReceiver { 
    @Override 
    public void onReceive(Context context, Intent intent) { 

     Toast.makeText(context, "Exemplo Toast", Toast.LENGTH_SHORT).show(); 


      if (intent.getAction().equalsIgnoreCase(Intent.ACTION_BOOT_COMPLETED)) { 
       Intent serviceIntent = new Intent(context, FirstService.class); 
       context.startService(serviceIntent); 
      } 

    } 

} 

Manifest.xml有它

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.niceplace.liveslink" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="17" /> 
    <uses-feature /> 


    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="android.permission.VIBRATE" /> 
     <uses-permission android:name="android.permission.WRITE_SETTINGS"/> 
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 



    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="com.niceplace.liveslink.MainActivity" 
      android:theme="@android:style/Theme.NoTitleBar" 
      android:label="@string/app_name" > 

      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 

     </activity> 

     <activity 
      android:name=".image" 
      android:theme="@android:style/Theme.NoTitleBar" 
      android:label="Imagem" > 
     </activity> 


     <service 
     android:name="com.niceplace.liveslink.FirstService" 
     android:enabled="true" 
     /> 

    <receiver android:name=".StartService"> 
    <intent-filter> 
    <action android:name="android.intent.action.BOOT_COMPLETED" /> 
    </intent-filter> 
    </receiver> 


    </application> 



</manifest> 

回答

0

設法解決這個問題,這是我的腳本的行一直在尋找一個的getCookie餅乾

當你啓動服務時,它不是cookie!但是如果我進入應用程序,他會得到cookie!

String uid = getCookie("www.liveslibk.com", "uid"); 

謝謝所有試圖幫助我的人!

0

我認爲你必須給RECEIVE_BOOT_COMPLETED允許添加到您的AndroidManifest.xml:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 
+0

我已將它添加到我的清單中,更多錯誤仍在繼續! –

+0

當我調用服務 –

+0

'if(intent.getAction()。equalsIgnoreCase(Intent.ACTION_BOOT_COMPLETED)){ }意圖serviceIntent = new Intent(context,FirstService.class); context.startService(serviceIntent); }' –

相關問題