iam尝试在启动后使我的服务正常工作 它的工作版本少于23
但比那更重要 它不起作用
const prevData = this.state.data;
// Make first 3 are not overridden
var preserved = prevData.splice(3)
preserved.push(...newData)
this.setState({ data : preserved});
我的广播
my manifist
Permissions
<uses-permission-sdk-23 android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Reciever
<receiver
android:enabled="true"
android:name=".BootReciever"
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>
Service
<service
android:name=".Services.Azkar_Services"
android:enabled="true"
android:exported="true" />
感谢
答案 0 :(得分:0)
尝试从您的意图过滤器中删除类别标记,并将其设置为
<receiver
android:enabled="true"
android:name=".BootReciever"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
并且无需添加此内容
<uses-permission-sdk-23 android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
更新 这是我的服务代码
public class Azkar_Services extends Service {
public Azkar_Services() {
}
String[] Azkar;
AzkarUtility azkarUtility;
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Azkar = getResources().getStringArray(R.array.Azkar);
azkarUtility = new AzkarUtility(getApplicationContext(),Azkar);
azkarUtility.Notification();
return START_STICKY;
}
@Override
public void onDestroy() {
azkarUtility.IsWorking[0] = false;
}
}
这是AzkarUtility类
public class AzkarUtility {
private Context mContext;
private LayoutInflater mInflater;
private String[] Azkar_Array;
Random mRandom;
View mView;
WindowManager mWindowManager;
final boolean[] IsTouched = {false};
public boolean[] IsWorking = {true};
public AzkarUtility(Context context, String[] azkar_Array) {
mContext = context;
Azkar_Array = azkar_Array;
}
public Context getContext() {
return mContext;
}
public void setContext(Context context) {
mContext = context;
}
public String[] getAzkar_Array() {
return Azkar_Array;
}
public void setAzkar_Array(String[] azkar_Array) {
Azkar_Array = azkar_Array;
}
public void Notification(){
if (IsWorking[0] == true)
{
new CountDownTimer(3000, 1000) {
@Override
public void onTick(long l) {
}
@Override
public void onFinish() {
Notification();
Show_Elzekr();
}
}.start();
}
}
private void Show_Elzekr() {
mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mWindowManager = (WindowManager) mContext.getSystemService(WINDOW_SERVICE);
mView = mInflater.inflate(R.layout.single_zikr,null,false);
TextView textView = (TextView) mView.findViewById(R.id.single_Zikr_Page_Textview);
mRandom = new Random();
int number = mRandom.nextInt(Azkar_Array.length - 1)+1;
textView.setText(Azkar_Array[number]);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT
, ViewGroup.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT);
params.gravity = Gravity.TOP | Gravity.RIGHT;
params.x = 0;
params.y = 100;
mWindowManager.addView(mView,params);
mView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
mWindowManager.removeView(mView);
IsTouched[0] = true;
return true;
}
});
new CountDownTimer(2000, 1000) {
@Override
public void onTick(long l) {
}
@Override
public void onFinish() {
if (IsTouched[0]==false)
mWindowManager.removeView(mView);
}
}.start();
}
}