Hide the app from launcher
Этот коммит содержится в:
@@ -22,8 +22,10 @@ android {
|
|||||||
|
|
||||||
productFlavors {
|
productFlavors {
|
||||||
regular {
|
regular {
|
||||||
|
buildConfigField "boolean", "HIDDEN_APP", "false"
|
||||||
}
|
}
|
||||||
hidden {
|
hidden {
|
||||||
|
buildConfigField "boolean", "HIDDEN_APP", "true"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,18 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:label="@string/app_name_hidden"
|
android:label="@string/hidden_app_name"
|
||||||
tools:replace="label">
|
tools:replace="label">
|
||||||
|
|
||||||
|
<receiver android:name=".DialLaunchReceiver" >
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
@@ -16,13 +16,16 @@
|
|||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:theme="@style/TraccarTheme">
|
android:theme="@style/TraccarTheme">
|
||||||
|
|
||||||
<activity android:name=".MainActivity"
|
<activity android:name=".MainActivity" android:launchMode="singleTask" />
|
||||||
android:launchMode="singleTask">
|
|
||||||
|
<activity-alias
|
||||||
|
android:name=".Launcher"
|
||||||
|
android:targetActivity=".MainActivity">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity-alias>
|
||||||
|
|
||||||
<activity android:name=".StatusActivity"/>
|
<activity android:name=".StatusActivity"/>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.traccar.client;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
|
||||||
|
public class DialLaunchReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
|
private static final String LAUNCHER_NUMBER = "8722227"; // TRACCAR
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
|
||||||
|
if (phoneNumber.equals(LAUNCHER_NUMBER)) {
|
||||||
|
setResultData(null);
|
||||||
|
Intent appIntent = new Intent(context, MainActivity.class);
|
||||||
|
appIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
context.startActivity(appIntent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -18,6 +18,7 @@ package org.traccar.client;
|
|||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -59,6 +60,11 @@ public class MainActivity extends PreferenceActivity implements OnSharedPreferen
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
if (BuildConfig.HIDDEN_APP) {
|
||||||
|
removeLauncherIcon();
|
||||||
|
}
|
||||||
|
|
||||||
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
addPreferencesFromResource(R.xml.preferences);
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
initPreferences();
|
initPreferences();
|
||||||
@@ -68,6 +74,21 @@ public class MainActivity extends PreferenceActivity implements OnSharedPreferen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void removeLauncherIcon() {
|
||||||
|
ComponentName componentName = new ComponentName(getPackageName(), getPackageName() + ".Launcher");
|
||||||
|
PackageManager packageManager = getPackageManager();
|
||||||
|
if (packageManager.getComponentEnabledSetting(componentName) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
|
||||||
|
packageManager.setComponentEnabledSetting(
|
||||||
|
componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
|
||||||
|
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
|
builder.setIcon(android.R.drawable.ic_dialog_alert);
|
||||||
|
builder.setMessage(getString(R.string.hidden_alert));
|
||||||
|
builder.setPositiveButton(android.R.string.ok, null);
|
||||||
|
builder.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean hasPermission(String permission) {
|
private boolean hasPermission(String permission) {
|
||||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<string name="app_name">Traccar Client</string>
|
<string name="app_name">Traccar Client</string>
|
||||||
<string name="app_name_hidden">Device Settings</string>
|
|
||||||
<string name="app_logo">Traccar</string>
|
<string name="app_logo">Traccar</string>
|
||||||
|
|
||||||
<string name="settings_id_title">Device identifier</string>
|
<string name="settings_id_title">Device identifier</string>
|
||||||
@@ -41,4 +40,7 @@
|
|||||||
<string name="status_location_update">Location update</string>
|
<string name="status_location_update">Location update</string>
|
||||||
<string name="status_connectivity_change">Connectivity change</string>
|
<string name="status_connectivity_change">Connectivity change</string>
|
||||||
|
|
||||||
|
<string name="hidden_app_name">Device Settings</string>
|
||||||
|
<string name="hidden_alert">The app has been hidden from the phone launcher. To open it again please dial 8722227 (TRACCAR).</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user