相关疑难解决方法(0)

在Android中检查Internet连接是否经常可用?

Hai我的应用程序是通过NetConnection保存(到服务器)数据.如果net不可用,我在本地保存,然后当net可用时再发送到服务器.我的问题是Frequetly检查Internet连接.所以我尝试了服务功能来检查网络连接.但它只召唤一次.如何解决我的问题.有人帮我提前谢谢!

更新

package com.android.cdtech;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.ConnectivityManager;
import android.view.View;

class ReceiverName extends Activity {
    BroadcastReceiver r = new BroadcastReceiver(){

    @Override
    public void onReceive(Context context, Intent intent) {
        ConnectivityManager cm = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE));
        if (cm == null)
            return;
        if (cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected()) {
            saveData();
        } else {
            // Do nothing or notify user somehow
        }

    }
    // code to handle broadcase

    private void saveData() {
        final …
Run Code Online (Sandbox Code Playgroud)

service android netconnection

3
推荐指数
1
解决办法
6917
查看次数

标签 统计

android ×1

netconnection ×1

service ×1