Hide the app from launcher
Этот коммит содержится в:
@@ -16,13 +16,16 @@
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/TraccarTheme">
|
||||
|
||||
<activity android:name=".MainActivity"
|
||||
android:launchMode="singleTask">
|
||||
<activity android:name=".MainActivity" android:launchMode="singleTask" />
|
||||
|
||||
<activity-alias
|
||||
android:name=".Launcher"
|
||||
android:targetActivity=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</activity-alias>
|
||||
|
||||
<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.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
@@ -59,6 +60,11 @@ public class MainActivity extends PreferenceActivity implements OnSharedPreferen
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (BuildConfig.HIDDEN_APP) {
|
||||
removeLauncherIcon();
|
||||
}
|
||||
|
||||
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
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) {
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
return true;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
<resources>
|
||||
|
||||
<string name="app_name">Traccar Client</string>
|
||||
<string name="app_name_hidden">Device Settings</string>
|
||||
<string name="app_logo">Traccar</string>
|
||||
|
||||
<string name="settings_id_title">Device identifier</string>
|
||||
@@ -41,4 +40,7 @@
|
||||
<string name="status_location_update">Location update</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>
|
||||
|
||||
Ссылка в новой задаче
Block a user