android 禁止第三方apk安装和卸载的方法详解

需求是这样的,客户要求提供系统的接口来控制apk的安装和卸载,接口如下

boolean setAppInstallationPolicies(int mode, String[] appPackageNames)
mode:应用名单类型
0:黑名单(应用包名列表中的所有项都不允许安装);
1:白名单(只允许安装应用包名列表中的项)。
appPackageNames:应用包名列表。当appPackageNames为空时,取消所有已设定的应用。
成功返回true;失败返回false。
String[] getAppInstallationPolicies()
返回值为当前应用安装管控状态
string[0]:功能模式,参见setAppInstallationPolicies方法的mode参数。
string[1]至string[n-1]:应用包名列表。

boolean setAppUninstallationPolicies(int mode, String[] appPackageNames)
mode:应用名单类型
0:黑名单(应用包名列表中的所有项均强制卸载);
1:白名单(应用包名列表中的所有项禁止卸载)。
appPackageNames:应用包名列表。当appPackageNames为空时,取消所有已设定的应用。
成功返回true;失败返回false。
String[] getAppUninstallationPolicies()
返回值为当前应用卸载管控状态
string[0]:功能模式,参见setAppUninstallationPolicies方法的mode参数。
string[1]至string[n-1]:应用包名列表。

android版本为9.0,首先想到的是在系统里面添加一个自己的service,分别在frameworks/base/core/java/android/app/添加IPolicyManager.aidl,frameworks/base/services/core/java/com/android/server/添加PolicyManagerService.java,在frameworks/base/添加policy/java/ga/mdm/PolicyManager.java,内容如下

package android.app;

/** {@hide} */
interface IPolicyManager
{

	boolean setAppInstallationPolicies(int mode,inout String[] appPackageNames);

	String[] getAppInstallationPolicies();

	boolean setAppUninstallationPolicies(int mode,inout String[] appPackageNames);

	String[] getAppUninstallationPolicies();

}
package com.android.server;

import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

import android.os.ServiceManager;
import android.os.SystemProperties;
import android.provider.Settings;
import android.util.Slog;

import java.lang.reflect.Field;
import java.util.ArrayList;

import android.app.IPolicyManager;
import android.net.wifi.WifiManager;
import android.content.pm.PackageManager;
import android.app.ActivityManager;
import android.content.pm.IPackageDataObserver;

public class PolicyManagerService extends IPolicyManager.Stub {

	private final String TAG = "PolicyManagerService";
	private Context mContext;

	private String[] mAppPackageNames = null;

	private String[] mAppUninstallPackageNames = null;

 public PolicyManagerService(Context context) {
  mContext = context;

 }

	@Override
	public boolean setAppInstallationPolicies(int mode, String[] appPackageNames){
		if(mode==0){
			Settings.System.putInt(mContext.getContentResolver(),"customer_app_status", 0);
		}else if(mode==1){
			Settings.System.putInt(mContext.getContentResolver(),"customer_app_status", 1);
		}else{
			return false;
		}
		mAppPackageNames = appPackageNames;
		return true;
	}

	@Override
	public String[] getAppInstallationPolicies(){
		return mAppPackageNames;
	}
	@Override
	public boolean setAppUninstallationPolicies(int mode,String[] appPackageNames){
		if(mode==0){
			Settings.System.putInt(mContext.getContentResolver(),"customer_appuninstall_status", 0);
		}else if(mode==1){
			Settings.System.putInt(mContext.getContentResolver(),"customer_appuninstall_status", 1);
		}else{
			return false;
		}
		mAppUninstallPackageNames = appPackageNames;
		return true;
	}
	@Override
	public String[] getAppUninstallationPolicies(){
		return mAppUninstallPackageNames;
	}
}
package ga.mdm;

import android.util.Slog;
import android.os.RemoteException;
import android.content.Context;
import android.app.IPolicyManager;

public class PolicyManager {
	private final String TAG = "PolicyManager";
	Context mContext;

 private final IPolicyManager mService;

 public PolicyManager(Context context,IPolicyManager mService) {
		mContext = context;
  this.mService = mService;
 }

	public boolean setAppInstallationPolicies(int mode,String[] appPackageNames){
		try {
			return mService.setAppInstallationPolicies(mode,appPackageNames);
  } catch (RemoteException ex) {
   ex.printStackTrace();
			return false;
  }
	}

	public String[] getAppInstallationPolicies(){
		try {
			return mService.getAppInstallationPolicies();
  } catch (RemoteException ex) {
   ex.printStackTrace();
			return null;
  }
	}

	public boolean setAppUninstallationPolicies(int mode,String[] appPackageNames){
		try {
			return mService.setAppUninstallationPolicies(mode,appPackageNames);
  } catch (RemoteException ex) {
   ex.printStackTrace();
			return false;
  }
	}

	public String[] getAppUninstallationPolicies(){
		try {
			return mService.getAppUninstallationPolicies();
  } catch (RemoteException ex) {
   ex.printStackTrace();
			return null;
  }
	}

}

同时在frameworks/base/policy/添加Android.mk

# Copyright (C) 2014 The Android Open Source Project
#
# 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.

LOCAL_PATH := $(call my-dir)

# Build the java code
# ============================================================

include $(CLEAR_VARS)

LOCAL_AIDL_INCLUDES := $(LOCAL_PATH)/java
LOCAL_SRC_FILES := $(call all-java-files-under, java) \
	$(call all-Iaidl-files-under, java) \
	$(call all-logtags-files-under, java)

LOCAL_JAVA_LIBRARIES := services
LOCAL_MODULE := policy

include $(BUILD_JAVA_LIBRARY)

include $(call all-makefiles-under,$(LOCAL_PATH))

这里为什么将PolicyManager.java单独出来,因为PolicyManager.java是提供给客户用的,单独生成一个jar包,客户只需要使用policy.jar就可以调用,同时需要添加

--- frameworks/base/Android.bp	(revision 221)
+++ frameworks/base/Android.bp	(working copy)
@@ -46,7 +46,8 @@
     "wifi/java/**/*.java",
     "keystore/java/**/*.java",
     "rs/java/**/*.java",
-
+		"policy/java/**/*.java",
+
     ":framework-javastream-protos",

     "core/java/android/accessibilityservice/IAccessibilityServiceConnection.aidl",
@@ -105,6 +106,7 @@
     "core/java/android/app/usage/ICacheQuotaService.aidl",
     "core/java/android/app/usage/IStorageStatsManager.aidl",
     "core/java/android/app/usage/IUsageStatsManager.aidl",
+		"core/java/android/app/IPolicyManager.aidl",
     ":libbluetooth-binder-aidl",
     "core/java/android/content/IClipboard.aidl",
     "core/java/android/content/IContentService.aidl",

将路径添加到,否则不会编译

-- build/make/core/pathmap.mk	(revision 221)
+++ build/make/core/pathmap.mk	(working copy)
@@ -83,6 +83,7 @@
 	  lowpan \
 	  keystore \
 	  rs \
+		policy \
 	 )

添加模块

--- build/make/target/product/base.mk	(revision 221)
+++ build/make/target/product/base.mk	(working copy)
@@ -142,7 +142,8 @@
   traced_probes \
   vdc \
   vold \
-  wm
+  wm \
+	policy

添加注册服务的代码

--- frameworks/base/core/java/android/content/Context.java	(revision 221)
+++ frameworks/base/core/java/android/content/Context.java	(working copy)
@@ -4198,6 +4198,9 @@
   * @see #getSystemService(String)
   */
   public static final String CROSS_PROFILE_APPS_SERVICE = "crossprofileapps";
+
+
+	public static final String POLICY_SERVICE = "policy";
+import ga.mdm.PolicyManager;
+
 /**
 * Manages all of the system services that can be returned by {@link Context#getSystemService}.
 * Used by {@link ContextImpl}.
@@ -982,6 +984,15 @@
         return new VrManager(IVrManager.Stub.asInterface(b));
       }
     });
+
+		registerService(Context.POLICY_SERVICE, PolicyManager.class,
+        new CachedServiceFetcher<PolicyManager>() {
+      @Override
+      public PolicyManager createService(ContextImpl ctx) {
+        IBinder b = ServiceManager.getService(Context.POLICY_SERVICE);
+        IPolicyManager service = IPolicyManager.Stub.asInterface(b);
+        return new PolicyManager(ctx, service);
+    }});
+import com.android.server.PolicyManagerService;
+
 public final class SystemServer {
   private static final String TAG = "SystemServer";

@@ -1287,7 +1289,14 @@
         }
         traceEnd();
       }
-
+
+			try {
+				Slog.i(TAG, "ClassMonitor Service is create");
+				ServiceManager.addService(Context.POLICY_SERVICE, new PolicyManagerService(context));
+			} catch (Throwable e) {
+				reportWtf("starting ClassMonitorService", e);
+			}

还需要添加selinux权限

--- system/sepolicy/Android.mk	(revision 221)
+++ system/sepolicy/Android.mk	(working copy)
@@ -244,10 +244,10 @@

 ifneq ($(with_asan),true)
 ifneq ($(SELINUX_IGNORE_NEVERALLOWS),true)
-LOCAL_REQUIRED_MODULES += \
-  sepolicy_tests \
-  treble_sepolicy_tests_26.0 \
-  treble_sepolicy_tests_27.0 \
+#LOCAL_REQUIRED_MODULES += \
+#  sepolicy_tests \
+#  treble_sepolicy_tests_26.0 \
+#  treble_sepolicy_tests_27.0 \

 endif
 endif
Index: system/sepolicy/prebuilts/api/26.0/nonplat_sepolicy.cil
===================================================================
--- system/sepolicy/prebuilts/api/26.0/nonplat_sepolicy.cil	(revision 221)
+++ system/sepolicy/prebuilts/api/26.0/nonplat_sepolicy.cil	(working copy)
@@ -135,6 +135,8 @@
 (typeattributeset hal_wifi_supplicant_server (hal_wifi_supplicant_default))
 (typeattribute adbd_26_0)
 (roletype object_r adbd_26_0)
+(typeattribute policy_service_26_0)
+(roletype object_r policy_service_26_0)
 (typeattribute audioserver_26_0)
 (roletype object_r audioserver_26_0)
 (typeattribute blkid_26_0)
Index: system/sepolicy/prebuilts/api/27.0/nonplat_sepolicy.cil
===================================================================
--- system/sepolicy/prebuilts/api/27.0/nonplat_sepolicy.cil	(revision 221)
+++ system/sepolicy/prebuilts/api/27.0/nonplat_sepolicy.cil	(working copy)
@@ -267,6 +267,8 @@
 (typeattributeset hal_wifi_supplicant_server (hal_wifi_supplicant_default))
 (typeattribute adbd_27_0)
 (roletype object_r adbd_27_0)
+(typeattribute policy_service_26_0)
+(roletype object_r policy_service_26_0)
 (typeattribute adbd_exec_27_0)
 (roletype object_r adbd_exec_27_0)
 (typeattribute audioserver_27_0)
Index: system/sepolicy/prebuilts/api/28.0/private/app_neverallows.te
===================================================================
--- system/sepolicy/prebuilts/api/28.0/private/app_neverallows.te	(revision 221)
+++ system/sepolicy/prebuilts/api/28.0/private/app_neverallows.te	(working copy)
@@ -128,7 +128,6 @@
  proc_stat
  proc_swaps
  proc_uptime
- proc_version
  proc_vmallocinfo
  proc_vmstat
 }:file { no_rw_file_perms no_x_file_perms };
Index: system/sepolicy/prebuilts/api/28.0/private/compat/26.0/26.0.cil
===================================================================
--- system/sepolicy/prebuilts/api/28.0/private/compat/26.0/26.0.cil	(revision 221)
+++ system/sepolicy/prebuilts/api/28.0/private/compat/26.0/26.0.cil	(working copy)
@@ -15,6 +15,7 @@
 (type rild)

 (typeattributeset accessibility_service_26_0 (accessibility_service))
+(typeattributeset policy_service_26_0 (policy_service))
 (typeattributeset account_service_26_0 (account_service))
 (typeattributeset activity_service_26_0 (activity_service))
 (typeattributeset adbd_26_0 (adbd))
Index: system/sepolicy/prebuilts/api/28.0/private/compat/27.0/27.0.cil
===================================================================
--- system/sepolicy/prebuilts/api/28.0/private/compat/27.0/27.0.cil	(revision 221)
+++ system/sepolicy/prebuilts/api/28.0/private/compat/27.0/27.0.cil	(working copy)
@@ -718,6 +718,7 @@
 (expandtypeattribute (zygote_exec_27_0) true)
 (expandtypeattribute (zygote_socket_27_0) true)
 (typeattributeset accessibility_service_27_0 (accessibility_service))
+(typeattributeset policy_service_27_0 (policy_service))
 (typeattributeset account_service_27_0 (account_service))
 (typeattributeset activity_service_27_0 (activity_service))
 (typeattributeset adbd_27_0 (adbd))
Index: system/sepolicy/prebuilts/api/28.0/private/service_contexts
===================================================================
--- system/sepolicy/prebuilts/api/28.0/private/service_contexts	(revision 221)
+++ system/sepolicy/prebuilts/api/28.0/private/service_contexts	(working copy)
@@ -186,3 +186,4 @@
 wifirtt                  u:object_r:rttmanager_service:s0
 window                  u:object_r:window_service:s0
 *                     u:object_r:default_android_service:s0
+policy                  u:object_r:policy_service:s0
Index: system/sepolicy/prebuilts/api/28.0/private/system_server.te
===================================================================
--- system/sepolicy/prebuilts/api/28.0/private/system_server.te	(revision 221)
+++ system/sepolicy/prebuilts/api/28.0/private/system_server.te	(working copy)
@@ -806,7 +806,7 @@
 # Do not allow opening files from external storage as unsafe ejection
 # could cause the kernel to kill the system_server.
 neverallow system_server sdcard_type:dir { open read write };
-neverallow system_server sdcard_type:file rw_file_perms;
+# neverallow system_server sdcard_type:file rw_file_perms;

 # system server should never be operating on zygote spawned app data
 # files directly. Rather, they should always be passed via a
Index: system/sepolicy/prebuilts/api/28.0/public/service.te
===================================================================
--- system/sepolicy/prebuilts/api/28.0/public/service.te	(revision 221)
+++ system/sepolicy/prebuilts/api/28.0/public/service.te	(working copy)
@@ -32,6 +32,7 @@
 type virtual_touchpad_service, service_manager_type;
 type vold_service,       service_manager_type;
 type vr_hwc_service,      service_manager_type;
+type policy_service, 		system_api_service, system_server_service, service_manager_type;

 # system_server_services broken down
 type accessibility_service, app_api_service, ephemeral_app_api_service, system_server_service, service_manager_type;
Index: system/sepolicy/private/app_neverallows.te
===================================================================
--- system/sepolicy/private/app_neverallows.te	(revision 221)
+++ system/sepolicy/private/app_neverallows.te	(working copy)
@@ -128,7 +128,6 @@
  proc_stat
  proc_swaps
  proc_uptime
- proc_version
  proc_vmallocinfo
  proc_vmstat
 }:file { no_rw_file_perms no_x_file_perms };
Index: system/sepolicy/private/compat/26.0/26.0.cil
===================================================================
--- system/sepolicy/private/compat/26.0/26.0.cil	(revision 221)
+++ system/sepolicy/private/compat/26.0/26.0.cil	(working copy)
@@ -15,6 +15,7 @@
 (type rild)

 (typeattributeset accessibility_service_26_0 (accessibility_service))
+(typeattributeset policy_service_26_0 (policy_service))
 (typeattributeset account_service_26_0 (account_service))
 (typeattributeset activity_service_26_0 (activity_service))
 (typeattributeset adbd_26_0 (adbd))
Index: system/sepolicy/private/compat/27.0/27.0.cil
===================================================================
--- system/sepolicy/private/compat/27.0/27.0.cil	(revision 221)
+++ system/sepolicy/private/compat/27.0/27.0.cil	(working copy)
@@ -718,6 +718,7 @@
 (expandtypeattribute (zygote_exec_27_0) true)
 (expandtypeattribute (zygote_socket_27_0) true)
 (typeattributeset accessibility_service_27_0 (accessibility_service))
+(typeattributeset policy_service_27_0 (policy_service))
 (typeattributeset account_service_27_0 (account_service))
 (typeattributeset activity_service_27_0 (activity_service))
 (typeattributeset adbd_27_0 (adbd))
Index: system/sepolicy/private/service_contexts
===================================================================
--- system/sepolicy/private/service_contexts	(revision 221)
+++ system/sepolicy/private/service_contexts	(working copy)
@@ -186,3 +186,4 @@
 wifirtt                  u:object_r:rttmanager_service:s0
 window                  u:object_r:window_service:s0
 *                     u:object_r:default_android_service:s0
+policy                  u:object_r:policy_service:s0
Index: system/sepolicy/private/system_server.te
===================================================================
--- system/sepolicy/private/system_server.te	(revision 221)
+++ system/sepolicy/private/system_server.te	(working copy)
@@ -806,7 +806,7 @@
 # Do not allow opening files from external storage as unsafe ejection
 # could cause the kernel to kill the system_server.
 neverallow system_server sdcard_type:dir { open read write };
-neverallow system_server sdcard_type:file rw_file_perms;
+# neverallow system_server sdcard_type:file rw_file_perms;

 # system server should never be operating on zygote spawned app data
 # files directly. Rather, they should always be passed via a
Index: system/sepolicy/public/service.te
===================================================================
--- system/sepolicy/public/service.te	(revision 221)
+++ system/sepolicy/public/service.te	(working copy)
@@ -32,6 +32,7 @@
 type virtual_touchpad_service, service_manager_type;
 type vold_service,       service_manager_type;
 type vr_hwc_service,      service_manager_type;
+type policy_service, 		system_api_service, system_server_service, service_manager_type;

 # system_server_services broken down
 type accessibility_service, app_api_service, ephemeral_app_api_service, system_server_service, service_manager_type;

这样就行了,烧录重新开机使用adb shell service list可以看到添加的service

policy: [android.app.IPolicyManager]

在\out\target\common\obj\JAVA_LIBRARIES\policy_intermediates找到classes.jar,这就是提供给客户用的jar

具体的禁止和卸载方法如下:

禁止安装可以修改PackageManagerService.java,在handleStartCopy方法中添加下面的代码

public void handleStartCopy() throws RemoteException {
      int ret = PackageManager.INSTALL_SUCCEEDED;

      // If we're already staged, we've firmly committed to an install location
      if (origin.staged) {
        if (origin.file != null) {
          installFlags |= PackageManager.INSTALL_INTERNAL;
          installFlags &= ~PackageManager.INSTALL_EXTERNAL;
        } else {
          throw new IllegalStateException("Invalid stage location");
        }
      }

      final boolean onSd = (installFlags & PackageManager.INSTALL_EXTERNAL) != 0;
      final boolean onInt = (installFlags & PackageManager.INSTALL_INTERNAL) != 0;
      final boolean ephemeral = (installFlags & PackageManager.INSTALL_INSTANT_APP) != 0;
      PackageInfoLite pkgLite = null;

      if (onInt && onSd) {
        // Check if both bits are set.
        Slog.w(TAG, "Conflicting flags specified for installing on both internal and external");
        ret = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION;
      } else if (onSd && ephemeral) {
        Slog.w(TAG, "Conflicting flags specified for installing ephemeral on external");
        ret = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION;
      } else {
        pkgLite = mContainerService.getMinimalPackageInfo(origin.resolvedPath, installFlags,
            packageAbiOverride);

				//add by jueme
				PolicyManager policyManager = (PolicyManager)mContext.getSystemService("policy");
				String[] appNames = policyManager.getAppInstallationPolicies();
				if(appNames!=null && appNames.length>0){
					int app_status = android.provider.Settings.System.getInt(mContext.getContentResolver(),"customer_app_status", -1);
					Slog.w(TAG,"app_status "+app_status);
					if(app_status==0){
						for (int i = 0; i < appNames.length; i++) {
							Slog.w(TAG,"appNames 0 "+appNames[i]);
							if (pkgLite.packageName.equals(appNames[i])){
								ret = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION;
								break;
							}
						}
					}else if(app_status==1){
						for (int i = 0; i < appNames.length; i++) {
							Slog.w(TAG,"appNames 1 "+appNames[i]);
							if (pkgLite.packageName.equals(appNames[i])){
								ret = PackageManager.INSTALL_SUCCEEDED;
								break;
							}else{
								ret = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION;
							}
						}
					}
				}
				//add end

这样在安装时候就会报安装位置不对的信息。

接着是禁止卸载,在PackageInstallerService.java的uninstall添加下面的方法。

@Override
  public void uninstall(VersionedPackage versionedPackage, String callerPackageName, int flags,
        IntentSender statusReceiver, int userId) throws RemoteException {
		//add by jueme
		PolicyManager policyManager = (PolicyManager)mContext.getSystemService("policy");
		String[] appNames = policyManager.getAppUninstallationPolicies();
		if(appNames!=null && appNames.length>0){
			int appuninstall_status = android.provider.Settings.System.getInt(mContext.getContentResolver(),"customer_appuninstall_status", -1);
			Slog.w(TAG,"appuninstall_status "+appuninstall_status+" mInstallerPackageName "+versionedPackage.getPackageName());
			boolean isUninstall = true;//默认都是可卸载
			if(appuninstall_status==0){
				for (int i = 0; i < appNames.length; i++) {
					if (versionedPackage.getPackageName().equals(appNames[i])){
						isUninstall = true;
						break;
					}else{
						isUninstall = false;
					}
				}
				if(!isUninstall){
					return;
				}
			}else if(appuninstall_status==1){
				//应用包名列表中的所有项禁止卸载
				for (int i = 0; i < appNames.length; i++) {
					if (versionedPackage.getPackageName().equals(appNames[i])){
						isUninstall = false;
						break;
					}else{
						isUninstall = true;
					}
				}
				if(!isUninstall){
					return;
				}
			}
		}
		//add end

到此这篇关于android 禁止第三方apk安装和卸载的方法详解的文章就介绍到这了,更多相关android 禁止第三方apk内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • 详解android.mk中引用第三方库的方法

    一.集成第三方jar包: 1.在项目目录下创建目录libs(不创建也行,一会儿指向对应路径就好),将第三方的jar包放进去. 2.在Android.mk文件中进行配置: include $(CLEAR_VARS) LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := smartphotolib:../../libs/smartphotolib.jar #前面为自定义的名(umeng_message_push),起什么名都可以,":"后面的为jar包在项目下对应

  • Android使用第三方库实现日期选择器

    本文主要是介绍利用第三方库实现底部日期选择器滚轮效果,类似IOS日期效果,只记录了一种展示效果,是项目中常用到的,至于用到其他效果以及自定义扩展的可以参考原文自行学习. 原文github地址 效果图参考: 使用方法: 1.AS添加依赖: compile 'com.contrarywind:Android-PickerView:3.2.6' 2.在Activity中添加如下代码: TimePickerView pvTime = new TimePickerView.Builder(this, ne

  • Android.mk引入第三方jar包和so库文件的方法

    以SystemUI为例,如果需要在SystemUI中引入第三方jar包以及so库,可作如下处理: 首先,在frameworks\base\packages\SystemUI下新建libs目录: 将需要引入的jar包放置到libs目录下.然后修改Android.mk文件: 也就说引入jar包主要依赖的是LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES和LOCAL_STATIC_JAVA_LIBRARIES.下面吧完整的Android.mk贴出来,方便拷贝. LOCAL_PA

  • Android使用友盟集成QQ、微信、微博等第三方分享与登录方法详解

    最近项目需要加入第三方分享和登录功能,之前其他项目的第三方分享和登录一直都使用ShareSDK实现的.为了统一使用友盟的全家桶,所以三方分享和登录也就选择了友盟.这里记录一下完整的集成与使用流程. 1.申请友盟Appkey 直接到友盟官网申请即可 2.下载SDK 下载地址:http://dev.umeng.com/social/android/sdk-download 下载的时候根据自己需求进行选择,我这里选择选择的是精简版(包含常用的分享与登录功能),只测试微信,QQ,新浪微博. 下载后解压出

  • Android Studio工程引用第三方so文件的方法

    应用程序二进制接口(Application Binary Interface)定义了二进制文件(尤其是.so文件)如何运行在相应的系统平台上,从使用的指令集,内存对齐到可用的系统函数库.在Android 系统上,每一个CPU架构对应一个ABI:armeabi,armeabi-v7a,x86,mips,arm64- v8a,mips64,x86_64. jar包存放到工程的libs目录下. 在main下建个文件叫jniLibs android { compileSdkVersion 26 buil

  • Android仿微信调用第三方地图应用导航(高德、百度、腾讯)

    实现目标 先来一张微信功能截图看看要做什么 其实就是有一个目的地,点击目的地的时候弹出可选择的应用进行导航. 大脑动一下,要实现这个功能应该大体分成两步: 底部弹出可选的地图菜单进行展示 点击具体菜单某一项的时候调用对应地图的api进行导航就ok啦 底部菜单这里用PopupWindow来做. 实现 1.菜单显示 PopupWindow支持传入view进行弹出展示,所有我们直接写一个菜单布局,高德.百度.腾讯 再加一个取消. map_navagation_sheet.xml <?xml versi

  • Android Studio实现第三方QQ登录操作代码

    来看看效果图吧     http://wiki.open.qq.com/wiki/mobile/SDK%E4%B8%8B%E8%BD%BD 下载SDKJar包 接下来就可以 实现QQ登录了, 新建一个项目工程 ,然后把我们刚才下载的SDK解压将jar文件夹中的jar包拷贝到我们的项目libs中 导入一个下面架包就可以 项目结构如下 打开我们的清单文件Androidmanifest 在里面加入权限和注册Activity 如下 <?xml version="1.0" encoding

  • android 禁止第三方apk安装和卸载的方法详解

    需求是这样的,客户要求提供系统的接口来控制apk的安装和卸载,接口如下 boolean setAppInstallationPolicies(int mode, String[] appPackageNames) mode:应用名单类型 0:黑名单(应用包名列表中的所有项都不允许安装): 1:白名单(只允许安装应用包名列表中的项). appPackageNames:应用包名列表.当appPackageNames为空时,取消所有已设定的应用. 成功返回true:失败返回false. String[

  • Android中gson、jsonobject解析JSON的方法详解

    JSON的定义: 一种轻量级的数据交换格式,具有良好的可读和便于快速编写的特性.业内主流技术为其提供了完整的解决方案(有点类似于正则表达式 ,获得了当今大部分语言的支持),从而可以在不同平台间进行数据交换.JSON采用兼容性很高的文本格式,同时也具备类似于C语言体系的行为. JSON对象: JSON中对象(Object)以"{"开始, 以"}"结束. 对象中的每一个item都是一个key-value对, 表现为"key:value"的形式, ke

  • Python安装依赖(包)模块方法详解

    Python模块,简单说就是一个.py文件,其中可以包含我们需要的任意Python代码.迄今为止,我们所编写的所有程序都包含在单独的.py文件中,因此,它们既是程序,同时也是模块.关键的区别在于,程序的设计目标是运行,而模块的设计目标是由其他程序导入并使用. 不是所有程序都有相关联的.py文件-比如说,sys模块就内置于Python中,还有些模块是使用其他语言(最常见的是C语言)实现的.不过,Python的大多数库文件都是使用Python实现的,因此,比如说,我们使用了语句import coll

  • 在Android中使用WebSocket实现消息通信的方法详解

    前言 消息推送功能可以说移动APP不可缺少的功能之一,一般简单的推送我们可以使用第三方推送的SDK,比如极光推送.信鸽推送等,但是对于消息聊天这种及时性有要求的或者三方推送不满足业务需求的,我们就需要使用WebSocket实现消息推送功能. 基本流程 WebSocket是什么,这里就不做介绍了,我们这里使用的开源框架是https://github.com/TakahikoKawasaki/nv-websocket-client 基于开源协议我们封装实现WebSocket的连接.注册.心跳.消息分

  • 在 Pycharm 安装使用black的方法详解

    PyCharm是一种Python IDE,带有一整套可以帮助用户在使用Python语言开发时提高其效率的工具,比如调试.语法高亮.Project管理.代码跳转.智能提示.自动完 成.单元测试.版本控制.此外,该IDE提供了一些高级功能,以用于支持Django框架下的专业Web开发. 简介 针对代码风格不一致问题,导致的维护成本过高,针对性的镇定代码风格统一标准,是很有必要的.目前市面上用的比较多的python代码格式化工具有YAPF.Black. Black,号称不妥协的代码格式化工具,它检测到

  • Docker部署安装Redash中文版的方法详解

    1安装说明 相比Linux环境本地安装而言,Docker安装方式更为简便,Docker脚本化安装过程会自动获取Redis.postgres.Python3.7镜像,构造Redash最新的后台server.worker.schedule镜像.前端npm依赖包安装和前端最新代码打包是通过卷映射方式挂载到server容器,因此这些工作需要人工一次执行:另外构建初始数据库表结构也需要人工一次执行.这些动作执行完毕,启动Docker容器就可以访问了.由于安装过程需要访问国外服务器,极难一次安装成功,需要反

  • python安装sklearn模块的方法详解

    可直接用这行命令!: pip install -U scikit-learn 其他命令: (1)更新pip python -m pip install --upgrade pip (2)安装 scipy 在网址http://www.lfd.uci.edu/~gohlke/pythonlibs/ 中找到你需要的版本scipy 例如windows 64 位 Python2.7 对应下载:scipy-0.18.0-cp27-cp27m-win_amd64.whl cd 下载scipy 目录下,安装 p

  • Android高级组件ImageSwitcher图像切换器使用方法详解

    图像切换器(ImageSwitcher),用于实现类似于Windows操作系统的"Windows照片查看器"中的上一张.下一张切换图片的功能.在使用ImageSwitcher时,必须实现ViewSwitcher.ViewFactory接口,并通过makeView()方法来创建用于显示图片的ImageView.makeView()方法将返回一个显示图片的ImageView.在使用图像切换器时,还有一个方法非常重要,那就是setImageResource方法,该方法用于指定要在ImageS

  • Android开发中使用Intent打开第三方应用及验证可用性的方法详解

    本文实例讲述了Android开发中使用Intent打开第三方应用及验证可用性的方法.分享给大家供大家参考,具体如下: Android中提供了Intent机制来协助应用间的交互与通讯.可作为不同组件之间通讯的媒介完成应用之间的交互.这里讨论一下针对Intent打开第三方应用的相关操作. 本文主要记录: ① 使用 Intent 打开第三方应用或指定 Activity 的三种方式 ② 使用上面三种方式时分别如何判断该 Intent 能否被解析 ③ 判断该 Intent 能否被解析中可能出现的遗漏 基础

  • 读写Android中assets目录下的文件的方法详解

    Android资源文件大致可以分为两种: 第一种是res目录下存放的可编译的资源文件: 这种资源文件系统会在R.java里面自动生成该资源文件的ID,所以访问这种资源文件比较简单,通过R.XXX.ID即可: 第二种是assets目录下存放的原生资源文件: 因为系统在编译的时候不会编译assets下的资源文件,所以我们不能通过R.XXX.ID的方式访问它们.那我么能不能通过该资源的绝对路径去访问它们呢?因为apk安装之后会放在/data/app/**.apk目录下,以apk形式存在,asset/r

随机推荐