Package com.mitac.api.libs
Class PackageManager
- java.lang.Object
-
- com.mitac.api.libs.ApiBindBase
-
- com.mitac.api.libs.PackageManager
-
public class PackageManager extends ApiBindBase
This class provides PackageManager related APIs.Java Sample Code:
package com.mitac.api; import android.app.Activity; import android.os.Bundle; import com.mitac.api.libs.PackageManager; import com.mitac.api.libs.ServiceStatusCallback; public class MainActivity extends Activity { private PackageManager mPackageManager;
@Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // when creating the instance the service is auto binding // register a callback to listen service status mPackageManager = new PackageManager(getApplicationContext(), new ServiceStatusCallback() {@Override
public void ready() { startTest(); } }); } private void startTest() { final String apiKey = "9f66a532226a9c78bcffe50133bd1d034e0059ba"; // the API key is different from client to client final String packageName = "com.mitac.milock"; final String apkPath = "/mnt/sdcard/Download/com.mitac.milock.apk"; if (mPackageManager != null) { if (!mSystemUi.installPackageSilently(apiKey, packageName, apkPath)) { // remote fail to do the operation } } }@Override
protected void onStop() { super.onStop(); if (mPackageManager != null) { mPackageManager.unbindService(); } } }Kotlin Sample Code:
package com.mitac.kotlinapitest import android.content.Context import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.util.Log import com.mitac.api.libs.PackageManager import com.mitac.api.libs.ServiceStatusCallback class MainActivity : AppCompatActivity() { val TAG: String = "PackageManager" var packageManager: PackageManager? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) testSystemUiApi(applicationContext) } fun testPackageManagerApi(context: Context) { packageManager = PackageManager(context, object: ServiceStatusCallback { override fun ready() { Log.d(TAG, "service is ready") var apiKey = "9f66a532226a9c78bcffe50133bd1d034e0059ba" var packageName = "com.mitac.milock" var apkPath = "/mnt/sdcard/Download/com.mitac.milock.apk packageManager!!.installPackageSilently(apiKey, packageName, apkPath) } override fun stopped() { Log.d(TAG, "service is stopped") } }) } }
-
-
Constructor Summary
Constructors Constructor Description PackageManager(android.content.Context context)
This constructor will not bind the service automatically.PackageManager(android.content.Context context, ServiceStatusCallback callback)
This constructor will bind the service automatically.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
bindService()
Bind serviceboolean
installPackageSilently(java.lang.String apiKey, java.lang.String packageName, java.lang.String apkPath)
Install apk package silently.void
unbindService()
Unbind service
-
-
-
Constructor Detail
-
PackageManager
public PackageManager(android.content.Context context)
This constructor will not bind the service automatically. Please callbindService()
at least once before using APIs.- Parameters:
context
- better to useContext.getApplicationContext()
to prevent memory leaks- Throws:
java.lang.IllegalArgumentException
- if context is null.
-
PackageManager
public PackageManager(android.content.Context context, ServiceStatusCallback callback)
This constructor will bind the service automatically.- Parameters:
context
- better to useContext.getApplicationContext()
to prevent memory leakscallback
- used to get the notification when service is ready.- Throws:
java.lang.IllegalArgumentException
- if context or callback is null.- See Also:
ServiceStatusCallback
-
-
Method Detail
-
installPackageSilently
public boolean installPackageSilently(java.lang.String apiKey, java.lang.String packageName, java.lang.String apkPath)
Install apk package silently.- Parameters:
apiKey
- The key used to check the client and must be provided by MiTAC.packageName
- The package to install.apkPath
- The apk package source path.- Returns:
false
if fail.
-
bindService
public void bindService()
Bind service- Specified by:
bindService
in classApiBindBase
-
unbindService
public void unbindService()
Unbind service- Specified by:
unbindService
in classApiBindBase
-
-