设置默认的数据卡

手机第一次开机的时候,默认gprs是打开的,但是却不能上网,原因是没选择数据卡,如下图:

解决方法:找到一个静态广播TelephonyIntents.ACTION_SIM_STATE_CHANGED(android.intent.action.SIM_STATE_CHANGED),我是在alps/vendor/mediatek/proprietary/packages/apps/Mms/src/com/android/mms/transaction/SmsSystemEventReceiver.java

public class SmsSystemEventReceiver extends BroadcastReceiver {
    private static final String TAG = "SmsSystemEventReceiver";
    @Override
    public void onReceive(Context context, Intent intent) {
        MmsLog.i(MmsApp.TXN_TAG, "onReceive(): intent=" + intent.toString());
        String action = intent.getAction();

        /// Add for runtime permission @{
        if (!PermissionCheckUtil.checkRequiredPermissions(context)) {
            MmsLog.d(MmsApp.LOG_TAG, "SmsSystemEventReceiver no permissions return !!");
            return;
        } else {
            MmsLog.d(MmsApp.LOG_TAG, "SmsSystemEventReceiver onReceive() has permisson DraftCache:"
                    + DraftCache.getInstance());
            if (DraftCache.getInstance() == null) {
                MmsApp.getApplication().onRequestPermissionsResult();
            }
        }
        /// @}

        if (action != null && action.equals(Intent.ACTION_BOOT_COMPLETED)) {
            handleBootCompleted(context);
        } else if  (action != null
                && action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
				
				//wdh_add
				int setDefaultSubId = intent.getIntExtra(
                        PhoneConstants.SUBSCRIPTION_KEY,
                        SubscriptionManager.INVALID_SUBSCRIPTION_ID);
				MmsLog.i(TAG, "subId wdh ===" +setDefaultSubId);
				final SubscriptionManager subscriptionManager = SubscriptionManager.from(context);
				/// M: for plug-in, need to call before setDefaultDataSubId
				subscriptionManager.setDefaultDataSubId(setDefaultSubId);
				/// M: for plug-in, need to call after setDefaultDataSubId
				subscriptionManager.setDefaultSmsSubId(setDefaultSubId);
						
            String newState = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
            // if sim is plug out, then set outbox and queued sms to failed.
            if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(newState)) {
                // get the absent sub id
                int subId = intent.getIntExtra(
                        PhoneConstants.SUBSCRIPTION_KEY,
                        SubscriptionManager.INVALID_SUBSCRIPTION_ID);

                if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID
                        || subId < 0) {
                    return;
                }
                String selection = " and sub_id=" + subId;
                MmsLog.i(MmsApp.TXN_TAG, "SmsSystemEventReceiver" +
                        " onReceive() SIM absent, selection: " + selection);

                int numMoved = moveOutboxMessagesToFailedBox(context, selection);
                numMoved = numMoved + moveQueuedMessagesToFailedBox(context, selection);
                if (numMoved > 0) {
                    MessagingNotification.notifySendFailed(context.getApplicationContext(), true);
                    // Called off of the UI thread so ok to block.
                    MessagingNotification.blockingUpdateNewMessageIndicator(
                            context, MessagingNotification.THREAD_ALL, false, null);
                }
            }
        }
    }
AndroidMainfest.xml

   <receiver android:name=".transaction.SmsSystemEventReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SIM_STATE_CHANGED" />
            </intent-filter>
        </receiver>
主要是用了
SubscriptionManager的下面这个方法
/** @hide */
public void setDefaultDataSubId(int subId) {
    if (VDBG) logd("setDataSubscription sub id = " + subId);
    try {
        ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub"));
        if (iSub != null) {
            iSub.setDefaultDataSubId(subId);
        }
    } catch (RemoteException ex) {
        // ignore it
    }
}



阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_25815655/article/details/79202643
上一篇修改Email的ActionBar的Title字体大小
下一篇ViewPager + Fragment 实现类微信界面
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭