0

這裏是logcat的錯誤我得到:錯誤在谷歌Play服務:讀取失敗:EPERM(不允許的操作)

android java.io.IOException: read failed: EPERM (Operation not permitted) 
    at libcore.io.IoBridge.read(IoBridge.java:435) 

的錯誤是在下面的代碼,在這裏我想註冊一個給定的設備使用AsyncTask:

private void registerInBackground(){ 
    mRegisterIdTask = new AsyncTask<Void, Void, Void>() { 

     @Override 
     protected Void doInBackground(Void... params) { 
      String msg = ""; 
      try { 
       if (gcm == null) { 
        gcm = GoogleCloudMessaging.getInstance(context); 
       } 
       regId = gcm.register(SENDER_ID); 
       msg = "Device registered, registration ID=" + regId; 
       /* TODO : Send regId to backend to store in database so backend can send... 
        TODO : ...push notification request to GooglePlayMessaging 
       */ 
       sendRegistrationIdToBackend(); 
       storeRegistrationId(context, regId); 
      } catch (IOException e) { 
       msg = "Error : " + e.getMessage(); 
      } 
      return null; 
     } 

     @Override 
     protected void onPostExecute(Void result) { 
      Log.i("Google Play", "Status : Finished "); 
      mRegisterIdTask = null; 
     } 
    }.execute(null, null, null); 
} 

現在好了,我得到這個,我沒有改變任何東西。

05-15 17:33:35.253 16020-16271/? E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #1 
Process: com.panicsystems.kyuubi.legalpanicpartner, PID: 16020 
java.lang.RuntimeException: An error occured while executing doInBackground() 
     at android.os.AsyncTask$3.done(AsyncTask.java:300) 
     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355) 
     at java.util.concurrent.FutureTask.setException(FutureTask.java:222) 
     at java.util.concurrent.FutureTask.run(FutureTask.java:242) 
     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
     at java.lang.Thread.run(Thread.java:841) 
Caused by: java.lang.SecurityException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.REGISTER pkg=com.google.android.gms (has extras) } without permission com.google.android.c2dm.permission.RECEIVE 
     at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1603) 
     at android.app.ContextImpl.startService(ContextImpl.java:1580) 
     at android.content.ContextWrapper.startService(ContextWrapper.java:494) 
     at com.google.android.gms.gcm.GoogleCloudMessaging.zzs(Unknown Source) 
     at com.google.android.gms.gcm.GoogleCloudMessaging.register(Unknown Source) 
     at com.kyuubi.MainActivity$2.doInBackground(MainActivity.java:171) 
     at com.kyuubi.MainActivity$2.doInBackground(MainActivity.java:161) 
     at android.os.AsyncTask$2.call(AsyncTask.java:288) 
     at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
     at java.lang.Thread.run(Thread.java:841) 
+0

您使用氰? –

+3

分享使用Google Play服務的代碼。 – pelya

+0

不使用Cyanogen mod – reemul

回答

0

如果您實際上讀取日誌,則很明顯是什麼問題。

您缺少使用GCM所需的必需權限。

所致:java.lang.SecurityException異常:不允許啓動服務 意圖{ACT = com.google.android.c2dm.intent.REGISTER PKG = com.google.android.gms(具有額外)}擅自 com.google.android.c2dm.permission.RECEIVE

內AndroidManifest.xml中添加:

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 

並確保你有一個GCM接收器registe紅

 <receiver 
      android:name="com.google.android.gms.gcm.GcmReceiver" 
      android:exported="true" 
      android:permission="com.google.android.c2dm.permission.SEND" > 
      <intent-filter> 
       <action android:name="com.google.android.c2dm.intent.RECEIVE" /> 

       <!-- support pre-4.4 KitKat devices --> 
       <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> 

       <category android:name="com.company.app" /> 
      </intent-filter> 
     </receiver> 

和服務:

<service 
     android:name="com.company.app.service.GcmRegistrationIntentService" 
      android:exported="false" > 
</service> 
+0

我解決這個問題已經有一段時間了,但我確實認爲這是問題所在。 – reemul

相關問題