Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 当手机处于睡眠状态时更新SQLite数据库_Android_Sqlite_Firebase_Firebase Cloud Messaging - Fatal编程技术网

Android 当手机处于睡眠状态时更新SQLite数据库

Android 当手机处于睡眠状态时更新SQLite数据库,android,sqlite,firebase,firebase-cloud-messaging,Android,Sqlite,Firebase,Firebase Cloud Messaging,我正在尝试更新接收到Firebase通知的SQLite数据库。它在手机处于唤醒状态(屏幕锁定或解锁)时工作 当手机处于睡眠状态时,手机会收到通知,但数据库不会更新 我如何更新我的数据库(但我真的不想使用Firebase数据库) 感谢您的帮助。1:检查您是否提供了唤醒锁定权限 2:ConversationAdapter构造函数看起来很奇怪,没有要创建的上下文?是的,我提供了唤醒锁定权限。我已编辑了我的问题,以使用ConversationAdapter构造函数进行更新。 public class M

我正在尝试更新接收到Firebase通知的SQLite数据库。它在手机处于唤醒状态(屏幕锁定或解锁)时工作

当手机处于睡眠状态时,手机会收到通知,但数据库不会更新

我如何更新我的数据库(但我真的不想使用Firebase数据库)


感谢您的帮助。

1:检查您是否提供了唤醒锁定权限


2:ConversationAdapter构造函数看起来很奇怪,没有要创建的上下文?

是的,我提供了唤醒锁定权限。我已编辑了我的问题,以使用ConversationAdapter构造函数进行更新。
public class MyFcmListenerService extends FirebaseMessagingService {

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {

        Long lUserId = Long.parseLong(values.get("from_user"));
        Long lPopId = Long.parseLong(values.get("msg_id"));
        String lText = values.get("text");

        Intent service = new Intent(this, DatabaseUpdateService.class);
        service.putExtra("user", lUserId);
        service.putExtra("msg_id", lPopId);
        service.putExtra("text", lText);

        sendNotification(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody(), service);
    }

    private void sendNotification(String mMessageTitle, String messageBody,  Intent service) {
        Intent intent = new Intent(this, ShowConversationActivity.class);

        Bundle lExtra = service.getExtras();
        intent.putExtras(lExtra);
        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,PendingIntent.FLAG_ONE_SHOT);

        String lTitle = getResources().getString(R.string.message_from) + " " + mMessageTitle;

        Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        android.support.v4.app.NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.brand_icon)
                .setContentTitle(lTitle)
                .setContentText(messageBody)
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);

        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        notificationManager.notify(0, notificationBuilder.build());

        // Start the service, keeping the device awake while it is launching.
        Log.d("DatabaseUpdateReceiver", "Starting service @ " + SystemClock.elapsedRealtime());
        startWakefulService(this, service);
    }
}

public class DatabaseUpdateService extends IntentService {
    private long mUserId;
    private Intent mIntent;

    public DatabaseUpdateService() {
        super("DatabaseUpdateService");
    }

    @Override
    protected void onHandleIntent(@Nullable Intent intent) {

        mIntent = intent;

        ConversationAdapter lConversationAdapter = new ConversationAdapter();

        Bundle lExtras = intent.getExtras();
        long lPopId = lExtras.getLong("user");
        mUserId = lExtras.getLong("msg_id");
        String lText = lExtras.getString("text");

        Log.d(getClass().getName(), "--------------- > " + lText);
        lConversationAdapter.insertMessage(lPopId, mUserId, lText, (long) 0);
    }
}

public ConversationAdapter() {
    mDatabase = DataBaseOpenHelper.getInstance().getDatabase();
}