java sendcommand_位置sendExtraCommands - 方法不起作用並關閉應用程序

我嘗試通過使用sendExtraCommand() - 方法以編程方式清除智能手機的gps芯片。在我的清單文件我加入到送這樣的額外命令的權限:位置sendExtraCommands - 方法不起作用並關閉應用程序

方法本身我把這樣的:

locationManager.sendExtraCommand(LocationManager.GPS_PROVIDER, "delete_aiding_data", null)

當我嘗試在模擬器上或上我的智能手機的應用程序崩潰。我不知道我做錯了什麼,所以如果有人能看看我的問題,我將非常感激。

我唯一的活動,在MainActivity:

public class MainActivity extends AppCompatActivity {

private TextView textView;

private Button button;

private LocationManager locationManager;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

textView = (TextView) findViewById(R.id.txtView1);

textView.setText("Gps Reset: ");

button = (Button) findViewById(R.id.button);

locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

boolean enabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

System.out.println(enabled);

button.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

sendXtraCommand();

}

});

}

private void sendXtraCommand(){

boolean reset = locationManager.sendExtraCommand(LocationManager.GPS_PROVIDER, "delete_aiding_data", null);

if(reset){

textView.append("true");

}else{

textView.append("false");

}

}

}

在這裏,我的清單文件:

package="com.example.felix.resetgps">

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:supportsRtl="true"

android:theme="@style/AppTheme">

這是我得到的控制檯上的消息:

11/25 14:32:41: Launching app

$ adb shell am start -n "com.example.felix.resetgps/com.example.felix.resetgps.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D

Waiting for application to come online: com.example.felix.resetgps | com.example.felix.resetgps.test

Waiting for application to come online: com.example.felix.resetgps | com.example.felix.resetgps.test

Connecting to com.example.felix.resetgps

I/art: Not late-enabling -Xcheck:jni (already on)

W/art: Unexpected CPU variant for X86 using defaults: x86

W/ActivityThread: Application com.example.felix.resetgps is waiting for the debugger on port 8100...

I/System.out: Sending WAIT chunk

[ 11-25 13:32:41.598 1794: 1815 D/ ]

HostConnection::get() New Host Connection established 0x8bf7f400, tid 1815

I/art: Debugger is active

Connected to the target VM, address: 'localhost:8615', transport: 'socket'

I/System.out: Debugger has connected

I/System.out: waiting for debugger to settle...

I/System.out: waiting for debugger to settle...

I/System.out: waiting for debugger to settle...

I/System.out: waiting for debugger to settle...

I/System.out: waiting for debugger to settle...

I/System.out: waiting for debugger to settle...

I/System.out: waiting for debugger to settle...

I/System.out: debugger has settled (1396)

W/System: ClassLoader referenced unknown path: /data/app/com.example.felix.resetgps-1/lib/x86

I/InstantRun: Instant Run Runtime started. Android package is com.example.felix.resetgps, real application class is null.

W/System: ClassLoader referenced unknown path: /data/app/com.example.felix.resetgps-1/lib/x86

I/art: Starting a blocking GC Instrumentation

W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable

I/System.out: true

I/OpenGLRenderer: Initialized EGL, version 1.4

D/OpenGLRenderer: Swap behavior 1

D/AndroidRuntime: Shutting down VM

E/AndroidRuntime: FATAL EXCEPTION: main

Process: com.example.felix.resetgps, PID: 4869

java.lang.SecurityException: "gps" location provider requires ACCESS_FINE_LOCATION permission.

at android.os.Parcel.readException(Parcel.java:1683)

at android.os.Parcel.readException(Parcel.java:1636)

at android.location.ILocationManager$Stub$Proxy.sendExtraCommand(ILocationManager.java:1274)

at android.location.LocationManager.sendExtraCommand(LocationManager.java:2226)

at com.example.felix.resetgps.MainActivity.sendXtraCommand(MainActivity.java:51)

at com.example.felix.resetgps.MainActivity.access$000(MainActivity.java:16)

at com.example.felix.resetgps.MainActivity$1.onClick(MainActivity.java:44)

at android.view.View.performClick(View.java:5610)

at android.view.View$PerformClick.run(View.java:22265)

at android.os.Handler.handleCallback(Handler.java:751)

at android.os.Handler.dispatchMessage(Handler.java:95)

at android.os.Looper.loop(Looper.java:154)

at android.app.ActivityThread.main(ActivityThread.java:6077)

at java.lang.reflect.Method.invoke(Native Method)

at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

Disconnected from the target VM, address: 'localhost:8615', transport: 'socket'

2017-11-25

Felix

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值