<uses-feature
android:name="android.software.device_admin"
android:required="true"/>
<application
.........
<receiver
android:name=".Receiver.AdminReceiver"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data
android:name="android.app.device_admin"
android:resource="@xml/device_admin"/>
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/>
<action android:name="android.app.action.ACTION_PASSWORD_CHANGED"/>
<action android:name="android.app.action.ACTION_PASSWORD_FAILED"/>
<action android:name="android.app.action.ACTION_PASSWORD_SUCCEEDED"/>
<action android:name="android.permission.WRITE_SECURE_SETTINGS"/>
<action android:name="android.permission.WRITE_SETTINGS" />
</intent-filter>
</receiver>
import android.app.admin.DeviceAdminReceiver;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
public class AdminReceiver extends DeviceAdminReceiver {
@Override
public void onEnabled(Context ctxt, Intent intent) {
ComponentName cn=new ComponentName(ctxt, AdminReceiver.class);
DevicePolicyManager mgr=
(DevicePolicyManager)ctxt.getSystemService(Context.DEVICE_POLICY_SERVICE);
mgr.setPasswordQuality(cn,
DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC);
onPasswordChanged(ctxt, intent);
}
@Override
public void onPasswordChanged(Context ctxt, Intent intent) {
DevicePolicyManager mgr=
(DevicePolicyManager)ctxt.getSystemService(Context.DEVICE_POLICY_SERVICE);
String msgId = "";
if (mgr.isActivePasswordSufficient()) {
msgId="Ok";
}
else {
msgId="Fail";
}
Toast.makeText(ctxt, msgId, Toast.LENGTH_LONG).show();
}
@Override
public void onPasswordFailed(Context ctxt, Intent intent) {
}
@Override
public void onPasswordSucceeded(Context ctxt, Intent intent) {
}
}
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
<uses-policies>
<limit-password />
<watch-login />
<reset-password />
<force-lock />
<wipe-data />
<expire-password />
<encrypted-storage />
</uses-policies>
</device-admin>
public void closeKeyboard() {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
private void emulationOnTouch(View v) {
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis() + 100L;
float x = 0.0F;
float y = 0.0F;
int metaState = 0;
MotionEvent motionEvent = MotionEvent.obtain(downTime, eventTime, 6661024, x, y, metaState);
v.dispatchTouchEvent(motionEvent);
}
Button bin;
View v;
emulationOnTouch(btn);
emulationOnTouch(v);
ParseText.execute(hashMap.get(arrayList.get(position)));
parseText.execute(hashMap.get(arrayList.get(position)));
public class MessageService extends Service {
public static PendingIntent pendingIntent = null;
private void serviceMessageStart() {
Intent alarmIntent = new Intent(MessageService.this, AlarmReceiver.class);
pendingIntent = PendingIntent.getBroadcast(MessageService.this, 0, alarmIntent, PendingIntent.FLAG_CANCEL_CURRENT);
if (pendingIntent != null) {
AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
manager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 30 * 1000, 15 * 60 * 1000, pendingIntent);
}
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
public void onCreate() {
super.onCreate();
serviceMessageStart();
}
public void onDestroy() {
super.onDestroy();
}
}
public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Выполняем свои действия
}
}
<application
<service
android:name="ИМЯ.ПАКЕТА.ПРИЛОЖЕНИЯ.MessageService"
android:enabled="true"
android:exported="false">
</service>
<receiver android:name="ИМЯ.ПАКЕТА.ПРИЛОЖЕНИЯ.BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
public boolean isServiceRunning(Class<?> serviceClass) {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
//...
if(!isServiceRunning(MessageService.class)) {
startService(new Intent(this, MessageService.class));
}
//...
}
OutputStream outputStream = null;
try {
outputStream = openFileOutput(fileName, 0);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
OutputStreamWriter osw = new OutputStreamWriter(outputStream);
PackageManager pm = this.getPackageManager();
try {
PermissionInfo info = pm.getPermissionInfo(Manifest.permission.ACCESS_FINE_LOCATION, 0);
Log.d("TEST.PERM", info.loadLabel(pm).toString());
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
Log.d("TEST.PERM", "ERROR");
}
Ничего страшного, это норма для 2017сказано выше. Для 2016 года это была норма, в 2017 залатали все проблемы. В общем, не мучай себя, а отнести в СЦ. За 6-10 дней разберутся.