1

BroadcastReceiverのBOOT_COMPLETED後にSIMカードが変更されたかどうかを検出したい大きな問題があります。マニフェストにこれを書いています

        <receiver android:name="startMobBroacastReciver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
        </intent-filter>
    </receiver>

そしてパーミッションは

   <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
   <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

ここに私のコードがあります

        public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub


    if("android.intent.action.BOOT_COMPLETED".equals(intent.getAction()))
    {

          tm=(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
            tel_num= (GsmCellLocation) tm.getCellLocation();
           prefs=context.getSharedPreferences("myprefs", 0);
           Log.i("SIM", " "+tel_num.getCid()+" "+tel_num.getLac()+" "+tm.getSimSerialNumber());
           sim_serial_number=prefs.getString("SIM_serial", "null");

 Toast.makeText(context, "add "+tm.getSimSerialNumber(), Toast.LENGTH_LONG).show();

ちなみに、tel_num.getCid() と tel_num.getLac() は値を返しますが、tm.getSimSerialNumber() は null を返します。これが私を夢中にさせるものです:(助けてください

4

1 に答える 1

0

SIM カードからデータを取得するまでの遅延を最大 1 分に設定します。カードの初期化が必要です。

于 2016-11-08T21:15:05.740 に答える