我想从GSM网络中抽出时间 [英] I want to get time from GSM network

查看:70
本文介绍了我想从GSM网络中抽出时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码,但是它通过wifi提供时间..当我关闭wifi时,它没有给我时间... 我想从我的GSM服务提供商那里抽出时间... 我正在使用的代码.

I am using this code but it gives time by wifi..when i turn off wifi,it is not giving me the time... I want to get the time from my GSM service provider... The code which I am using..

LocationManager locMan = (LocationManager) arg0.getSystemService(Context.LOCATION_SERVICE);
        long networkTS = locMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER).getTime();
        Toast.makeText(arg0,""+networkTS,Toast.LENGTH_LONG ).show();
        Date date = new Date(networkTS);
        SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        format.setTimeZone(TimeZone.getTimeZone("GMT+5:30"));
        String formatted = format.format(date);
        Toast.makeText(arg0,""+formatted,Toast.LENGTH_LONG ).show();

最主要的是

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.block_time"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.block_time.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <receiver android:name=".Tim">
            <intent-filter>
                <action android:name="android.intent.action.TIME_SET" />
            </intent-filter>
        </receiver>

    </application>

</manifest>

推荐答案

 long networkTS = locMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER).getTime();

如果您想使用当前时间,则getLastKnowLocation返回的时间可能会很旧

Time returned by getLastKnowLocation could be old if you want current time use

locMan.requestSingleUpdate()并通过网络提供商

这篇关于我想从GSM网络中抽出时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆