ソーリー全員。まず、AUTO START MANAGERのためにデバイスでアプリケーションが閉じられたときにレシーバーが動作しません。私は愚かな気がします...そして、私はそれを解決しようとしていたときに非常に重要なことを学びました。重複電話の状態ロリポップアプリ受信終了時に放送受信機とサービスが動作しない
http://www.skoumal.net/en/android-duplicated-phone-state-broadcast-on-lollipop/
おかげで放送...
私はAndroidと私に新たなんだ - アンドロイド:まず Broadcast Receivers not working in Android 6.0 Marshmallow
第二のAndroid 6.0許可要求が
BroadcastReceiver &サービスを学びたいこのコードでは、BroadcastReceiverはオフホークとアイドル状態の電話を聴き、インテントを送信します。サービスは何かを行います。アプリケーションはすべて正常に動作しますが。近いアプリケーションBroadcastReceiverとサービスの後に動作しません。
更新:アプリケーションの実行と通常のすべてのサービスが2回開始され、2回停止されていることにも気付きました。
サービスが開始されている間、私はこのメッセージを参照してください。
Toast.makeText(文脈、 "" + phoneState +」 "+、レコード、Toast.LENGTH_SHORT).SHOW();
Toast.makeText(getApplicationContext()、 "サービス作業"、Toast.LENGTH_SHORT).show();
再び1 Toast.makeText(コンテキスト "" + phoneState +」 "+レコード、Toast.LENGTH_SHORT).SHOW();
再び2 Toast.makeText(getApplicationContext()、 "サービスの仕事"、Toast.LENGTH_SHORT).SHOW()
サービスがストーピングている間、私はこのメッセージを参照してください。
トースト。 makeText(context、 "" + phoneState + "" +レコード、Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext()、 "サービスが停止します。"、Toast.LENGTH_SHORT).show();
再び1 Toast.makeText(コンテキスト "" + phoneState +」 "+レコード、Toast.LENGTH_SHORT).SHOW();
再度2. Toast.makeText(getApplicationContext()、 "サービスは停止します。"、Toast.LENGTH_SHORT).show();
すべてを繰り返します。
マニフェスト:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="devapp.deneme">
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:enabled="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".MyService"
android:enabled="true"
android:exported="true" />
<receiver
android:name="devapp.deneme.MyReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
<action android:name="android.intent.action.PHONE_STATE"/>
</intent-filter>
</receiver>
</application>
</manifest>
ブロードキャストレシーバー
package devapp.deneme;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.widget.Toast;
public class MyReceiver extends BroadcastReceiver {
public MyReceiver(){
}
Intent service = null;
Bundle bundle = null;
String phoneState = null;
boolean record = false;
@Override
public void onReceive(Context context, Intent intent) {
service = new Intent(context, MyService.class);
bundle = intent.getExtras();
phoneState = bundle.getString(TelephonyManager.EXTRA_STATE);
if (phoneState!=null){
if ((phoneState.equals(TelephonyManager.EXTRA_STATE_OFFHOOK))||(phoneState.equals(TelephonyManager.EXTRA_STATE_IDLE))){
service.putExtra("durum", phoneState);
if (phoneState.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
record = true;
}
else {
record = false;
}
}
service.putExtra("record",record);
Toast.makeText(context, "" +phoneState +" " +record, Toast.LENGTH_SHORT).show();
context.startService(service);
}
}
}
サービス
package devapp.deneme;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.widget.Toast;
public class MyService extends Service {
public MyService() {
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
public int onStartCommand (Intent intent, int flags, int startId){
boolean record = intent.getBooleanExtra("record", false);
if (record) {
Toast.makeText(getApplicationContext(), "service work", Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(getApplicationContext(), "service will be stopped.", Toast.LENGTH_SHORT).show();
stopSelf();
}
return super.onStartCommand(intent, flags, startId);
}
}
ことであなたが強制終了を意味するならば、それは動作しません閉じる。 – Shaishav
タスクマネージャを右または左にスライド – Murat
これはAPIレベルと権限に関するものです。http://stackoverflow.com/questions/33036523/broadcast-receivers-not-working-in-android-6-0-marshmallow – Murat