Я создаю мобильное приложение, чтобы взять имя подключенного APN. Я сделал следующим образом. Но я получил нулевое значение для имени APN. Так что я должен сделать для этого? На самом деле я следовал документации android и использовал для этого ApnSetting.Builder . ApnSetting.Builder был добавлен в API 28. Так что он новый и нет примера кода, чтобы узнать об APN. На самом деле мне нужно программно добавить пользовательский APN для мобильного приложения. Итак, какие шаги необходимо выполнить для этой задачи?
package com.example.myapplication;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.telephony.data.ApnSetting;
import android.util.Log;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private static String TAG = "MainActivity";
private Context context;
@RequiresApi(api = Build.VERSION_CODES.P)
public String getApn(){
ApnSetting apn = new ApnSetting.Builder().build();
String apnName =null;
try{
apnName = apn.getApnName();
}catch (NullPointerException e){
Log.e(TAG, "null pointer exception");
}
Log.i(TAG, "The app name"+apnName);
return apnName;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String apnName = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
apnName = getApn();
}
Log.i(TAG, "**************Name"+apnName+"********************");
}
}
Но результат был следующим.
02/05 13:41:49: Launching 'app' on Samsung SM-A107F.
$ adb shell am start -n "com.example.myapplication/com.example.myapplication.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Waiting for process to come online...
Connected to process 11575 on device 'samsung-sm_a107f-R9AMA2040EJ'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
E/MainActivity: null pointer exception
I/MainActivity: The app namenull
**************Namenull********************
I/MultiWindowDecorSupport: updateCaptionType >> com.android.internal.policy.MultiWindowDecorSupport@17b781a, isFloating: false, isApplication: true, hasWindowDecorCaption: false, hasWindowControllerCallback: true
D/MultiWindowDecorSupport: setCaptionType = 0
W/e.myapplicatio: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
W/e.myapplicatio: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
D/OpenGLRenderer: Skia GL Pipeline
D/EmergencyMode: [EmergencyManager] android createPackageContext successful
D/InputTransport: Input channel constructed: fd=56
D/ViewRootImpl@2b90b35[MainActivity]: setView = DecorView@a321bca[MainActivity] TM=true MM=false
D/ViewRootImpl@2b90b35[MainActivity]: Relayout returned: old=[0,0][720,1520] new=[0,0][720,1520] result=0x7 surface={true 3385311232} changed=true
D/Surface: Surface::allocateBuffers(this=0xc9c7c000)
I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 2
E/IMGSRV: :0: GetRenderableInternalFormatInfoEntry: Unsupported renderable internal format 37808
:0: GetRenderableInternalFormatInfoEntry: Unsupported renderable internal format 37810
:0: GetRenderableInternalFormatInfoEntry: Unsupported renderable internal format 37809
:0: GetRenderableInternalFormatInfoEntry: Unsupported renderable internal format 37811
:0: GetRenderableInternalFormatInfoEntry: Unsupported renderable internal format 37812
:0: GetRenderableInternalFormatInfoEntry: Unsupported renderable internal format 37813
:0: GetRenderableInternalFormatInfoEntry: Unsupported renderable internal format 37814
:0: GetRenderableInternalFormatInfoEntry: Unsupported renderable internal format 37815
:0: GetRenderableInternalFormatInfoEntry: Unsupported renderable internal format 37816
:0: GetRenderableInternalFormatInfoEntry: Unsupported renderable internal format 37817
:0: GetRenderableInternalFormatInfoEntry: Unsupported renderable internal format 37818
:0: GetRenderableInternalFormatInfoEntry: Unsupported renderable internal format 37819
:0: GetRenderableInternalFormatInfoEntry: Unsupported renderable internal format 37820
:0: GetRenderableInternalFormatInfoEntry: Unsupported renderable internal format 37821
D/Surface: Surface::connect(this=0xc9c7c000,api=1)
D/OpenGLRenderer: eglCreateWindowSurface = 0xdc66ba60, 0xc9c7c008
E/ion: ioctl c0044901 failed with code -1: Invalid argument
D/ViewRootImpl@2b90b35[MainActivity]: MSG_RESIZED: frame=[0,0][720,1520] ci=[0,55][0,84] vi=[0,55][0,84] or=1
D/ViewRootImpl@2b90b35[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 1 1
D/InputMethodManager: prepareNavigationBarInfo() DecorView@a321bca[MainActivity]
getNavigationBarColor() -855310
D/InputMethodManager: prepareNavigationBarInfo() DecorView@a321bca[MainActivity]
getNavigationBarColor() -855310
V/InputMethodManager: Starting input: tba=com.example.myapplication ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false
D/InputMethodManager: startInputInner - Id : 0
I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus
D/InputTransport: Input channel constructed: fd=75
D/InputMethodManager: prepareNavigationBarInfo() DecorView@a321bca[MainActivity]
getNavigationBarColor() -855310
V/InputMethodManager: Starting input: tba=com.example.myapplication ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false
D/InputMethodManager: startInputInner - Id : 0