mt6735 如何内置FM频道
时间:10-02
整理:3721RD
点击:
[DESCRIPTION]
如有5个频道需要内置,即烧完软件后第一次进入FM,还没有进行搜索时,列表就可以始终显示内置频道
[SOLUTION]
FMRadioService.java
1.private int defaultChannels[] = new int[] {875, 903, 918, 942, 1025};//自定义内置频道
2.initService()中添加insertDefaultStation(defaultChannels);
3.定义insertDefaultStation()函数
private int[] insertDefaultStation(int[] channels) {
LogUtils.d(TAG, "insertDefaultStation.firstValidChannel:" + Arrays.toString(channels));
int firstValidChannel = mCurrentStation;
int channelNum = 0;
if (null != channels) {
Arrays.sort(channels);
int size = channels.length;
// Save searched stations into database by batch
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
String defaultStationName = getString(R.string.default_station_name);
for (int i = 0; i < size; i++) {
if (FMRadioUtils.isValidStation(channels)) {
if (0 == channelNum) {
firstValidChannel = channels;
}
if (!FMRadioStation.isDefaultStation(mContext, channels)) {
ops.add(ContentProviderOperation.newInsert(Station.CONTENT_URI)
.withValue(Station.COLUMN_STATION_NAME, defaultStationName)
.withValue(Station.COLUMN_STATION_FREQ, channels)
.withValue(Station.COLUMN_STATION_TYPE, FMRadioStation.STATION_TYPE_SEARCHED)
.build());
}
channelNum++;
}
}
// Save search stations to database by batch
try {
mContext.getContentResolver().applyBatch(FMRadioStation.AUTHORITY, ops);
} catch (RemoteException e) {
LogUtils.d(TAG, "Exception when applyBatch searched stations " + e);
} catch (OperationApplicationException e) {
LogUtils.d(TAG, "Exception when applyBatch searched stations " + e);
}
}
LogUtils.d(TAG, "insertDefaultStation.firstValidChannel:" + firstValidChannel + ",channelNum:" +
channelNum);
return (new int[] { firstValidChannel, channelNum });
}
4.handleMessage()->case FMRadioListener.MSGID_SCAN_FINISHED:中
result = insertSearchedStation(channels);
insertDefaultStation(defaultChannels);//添加此行
5.FMRadioStation.java中添加
public static boolean isDefaultStation(Context context, int iStation) {
return isStationExist(context, iStation, STATION_TYPE_SEARCHED);
}
如有5个频道需要内置,即烧完软件后第一次进入FM,还没有进行搜索时,列表就可以始终显示内置频道
[SOLUTION]
FMRadioService.java
1.private int defaultChannels[] = new int[] {875, 903, 918, 942, 1025};//自定义内置频道
2.initService()中添加insertDefaultStation(defaultChannels);
3.定义insertDefaultStation()函数
private int[] insertDefaultStation(int[] channels) {
LogUtils.d(TAG, "insertDefaultStation.firstValidChannel:" + Arrays.toString(channels));
int firstValidChannel = mCurrentStation;
int channelNum = 0;
if (null != channels) {
Arrays.sort(channels);
int size = channels.length;
// Save searched stations into database by batch
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
String defaultStationName = getString(R.string.default_station_name);
for (int i = 0; i < size; i++) {
if (FMRadioUtils.isValidStation(channels)) {
if (0 == channelNum) {
firstValidChannel = channels;
}
if (!FMRadioStation.isDefaultStation(mContext, channels)) {
ops.add(ContentProviderOperation.newInsert(Station.CONTENT_URI)
.withValue(Station.COLUMN_STATION_NAME, defaultStationName)
.withValue(Station.COLUMN_STATION_FREQ, channels)
.withValue(Station.COLUMN_STATION_TYPE, FMRadioStation.STATION_TYPE_SEARCHED)
.build());
}
channelNum++;
}
}
// Save search stations to database by batch
try {
mContext.getContentResolver().applyBatch(FMRadioStation.AUTHORITY, ops);
} catch (RemoteException e) {
LogUtils.d(TAG, "Exception when applyBatch searched stations " + e);
} catch (OperationApplicationException e) {
LogUtils.d(TAG, "Exception when applyBatch searched stations " + e);
}
}
LogUtils.d(TAG, "insertDefaultStation.firstValidChannel:" + firstValidChannel + ",channelNum:" +
channelNum);
return (new int[] { firstValidChannel, channelNum });
}
4.handleMessage()->case FMRadioListener.MSGID_SCAN_FINISHED:中
result = insertSearchedStation(channels);
insertDefaultStation(defaultChannels);//添加此行
5.FMRadioStation.java中添加
public static boolean isDefaultStation(Context context, int iStation) {
return isStationExist(context, iStation, STATION_TYPE_SEARCHED);
}
:):):):):):)