まず最初に、私はJavaについて完全に初心者だと言わなければなりません。 私はこれをいくつかのチュートリアルを使って書いています。独自のサービス:受信者をインスタンス化できません
あなたが,,パッケージ名がマニフェストに正しく、エラーのスペルを間違えがない...
私は私のデバイスのためのサービスを作成しようとしています見ての通り、ウィッヒはそれを主導を制御します。しかし、私はこのエラーを取得しておくよ:
AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.gabrielgagz.ledpearlyn.LedPearlynReceiver" on path: DexPathList[[zip file "/system/app/LedPearlyn/LedPearlyn.apk"],nativeLibraryDirectories=[/system/app/LedPearlyn/lib/arm, /system/app/LedPearlyn/LedPearlyn.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib, /system/lib, /vendor/lib]]
LedPearlynReceiver:
package com.gabrielgagz.ledpearlyn;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import java.io.*;
public class LedPearlynReceiver extends BroadcastReceiver {
public static boolean wasScreenOn = true;
@Override
public void onReceive(final Context context, final Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF) || intent.getAction().equals(Intent.ACTION_DREAMING_STARTED)) {
try {
String[] cmd = { "/system/bin/sh", "-c", "echo 0 > /sys/class/leds/pearlyn/brightness"};
Runtime.getRuntime().exec(cmd);
} catch(IOException ie) {
ie.printStackTrace();
}
wasScreenOn = false;
Log.e("LedPearlyn","OFF");
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON) || intent.getAction().equals(Intent.ACTION_DREAMING_STOPPED)) {
try {
String[] cmd = { "/system/bin/sh", "-c", "echo 255 > /sys/class/leds/pearlyn/brightness"};
Runtime.getRuntime().exec(cmd);
} catch(IOException ie) {
ie.printStackTrace();
}
wasScreenOn = true;
Log.e("LedPearlyn","ON");
}
}
}
LedPearlynService:
package com.gabrielgagz.ledpearlyn;
import android.app.Service;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Binder;
import android.os.IBinder;
import android.content.BroadcastReceiver;
public class LedPearlynService extends Service {
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
final IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_DREAMING_STARTED);
filter.addAction(Intent.ACTION_DREAMING_STOPPED);
final BroadcastReceiver mReceiver = new LedPearlynReceiver();
registerReceiver(mReceiver, filter);
return super.onStartCommand(intent, flags, startId);
}
public class LocalBinder extends Binder {
LedPearlynService getService() {
return LedPearlynService.this;
}
}
}
AndroidManifest:あなたがで(android:exported="false"
を削除する必要が
<?xml version="1.0" encoding="utf-8"?>
<manifest android:sharedUserId="android.uid.system" android:versionCode="1" android:versionName="1.0" package="com.gabrielgagz.ledpearlyn" platformBuildVersionCode="25" platformBuildVersionName="7.1.2"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
<application>
<receiver android:label="LedPearlynReceiver" android:name=".LedPearlynReceiver" android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.SCREEN_ON" />
<action android:name="android.intent.action.SCREEN_OFF" />
<action android:name="android.intent.action.DREAMING_STARTED" />
<action android:name="android.intent.action.DREAMING_STOPPED" />
</intent-filter>
</receiver>
<service android:name=".LedPearlynService" android:exported="false"></service>
</application>
</manifest>
あなたの答えをありがとうが、あなたが提供したolutionでも同じ問題が残っています... – gabrielgagz
答えを更新しました。 –
もう一度ありがとう!しかし、いいえ、動作しません... – gabrielgagz