Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 创建可从ADB启动/停止的服务。(服务启动时振动)_Android_Service - Fatal编程技术网

Android 创建可从ADB启动/停止的服务。(服务启动时振动)

Android 创建可从ADB启动/停止的服务。(服务启动时振动),android,service,Android,Service,我想从ADB命令(甚至tcp/ip套接字)旋转手机。 所以我想有一个服务,我可以启动和停止从远程PC 我不知道我做错了什么,当我从studio“运行”应用程序时,我在服务列表中没有看到服务: 亚洲开发银行外壳服务清单 MyService.java: package com.example.vibrate; import android.app.Service; import android.content.Intent; import android.os.IBinder; import an

我想从ADB命令(甚至tcp/ip套接字)旋转手机。 所以我想有一个服务,我可以启动和停止从远程PC

我不知道我做错了什么,当我从studio“运行”应用程序时,我在服务列表中没有看到服务: 亚洲开发银行外壳服务清单

MyService.java:

package com.example.vibrate;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.Vibrator;

public class MyService extends Service {
    Vibrator vibrator;
    public MyService() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public void onCreate() {
        super.onCreate();

        vibrator = (Vibrator)getSystemService(VIBRATOR_SERVICE);

    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {

        vibrator.vibrate(2000);
        return super.onStartCommand(intent, flags, startId);

    }
}
AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.vibrate">

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <service
            android:name=".MyService"
            android:enabled="true"
            android:exported="true">
        </service>
    </application>



</manifest>


需要启动服务。所以你需要一个活动来启动它。@VladyslavMatviienko你能给我看一些代码吗?我真的不是Adnroid开发者,这是我需要的一个特定产品。