Search in sources :

Example 86 with PackageManager

use of android.content.pm.PackageManager in project Notes by lguipeng.

the class SettingPresenter method initFeedbackPreference.

private void initFeedbackPreference() {
    Uri uri = Uri.parse("mailto:lgpszu@163.com");
    final Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
    PackageManager pm = mContext.getPackageManager();
    List<ResolveInfo> infos = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    if (infos == null || infos.size() <= 0) {
        view.setFeedbackPreferenceSummary(mContext.getString(R.string.no_email_app_tip));
        return;
    }
    Preference.OnPreferenceClickListener l = (preference -> {
        mContext.startActivity(intent);
        return true;
    });
    view.setFeedbackPreferenceClickListener(l);
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) Preference(android.preference.Preference) Intent(android.content.Intent) Uri(android.net.Uri)

Example 87 with PackageManager

use of android.content.pm.PackageManager in project Notes by lguipeng.

the class AboutActivity method getVersion.

private String getVersion(Context ctx) {
    try {
        PackageManager pm = ctx.getPackageManager();
        PackageInfo pi = pm.getPackageInfo(ctx.getPackageName(), PackageManager.GET_ACTIVITIES);
        return pi.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return "1.0.0";
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo)

Example 88 with PackageManager

use of android.content.pm.PackageManager in project Notes by lguipeng.

the class AboutActivity method isInstallApplication.

private boolean isInstallApplication(String packageName) {
    try {
        PackageManager pm = this.getPackageManager();
        pm.getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}
Also used : PackageManager(android.content.pm.PackageManager)

Example 89 with PackageManager

use of android.content.pm.PackageManager in project ARChon-Packager by bpear96.

the class activityInstalled method SelectedAPK.

public void SelectedAPK() throws IOException {
    //If user selects apk manually. Run this.
    String APKFilePath = g.getAPKPath();
    PackageManager pm = getPackageManager();
    PackageInfo pi = pm.getPackageArchiveInfo(APKFilePath, 0);
    // tell package info where app is located.
    pi.applicationInfo.sourceDir = APKFilePath;
    pi.applicationInfo.publicSourceDir = APKFilePath;
    String PackageName = pi.packageName;
    String AppName = (String) pi.applicationInfo.loadLabel(pm);
    g.setSelectedAppName(AppName);
    g.setPackageName(PackageName);
    Drawable icon = pi.applicationInfo.loadIcon(pm);
    Bitmap bmpIcon = ((BitmapDrawable) icon).getBitmap();
    //Make folders on phones storage
    setupFolders();
    // Extract icon
    String extStorageDirectory = Environment.getExternalStorageDirectory().toString() + "/ChromeAPKS/" + AppName + File.separator;
    OutputStream outStream = null;
    File file = new File(extStorageDirectory, "icon.png");
    try {
        outStream = new FileOutputStream(file);
        bmpIcon.compress(Bitmap.CompressFormat.PNG, 100, outStream);
        outStream.flush();
        outStream.close();
    } catch (Exception e) {
        Toast.makeText(activityInstalled.this, "Error: App Icon was not extracted.", Toast.LENGTH_LONG).show();
    }
    //Copy APK from selected source to ChromeAPKS location
    File apksource = new File(APKFilePath);
    File apkdst = new File(Environment.getExternalStorageDirectory().toString() + File.separator + "ChromeAPKS/" + AppName + "/vendor/chromium/crx/" + PackageName + ".apk");
    copy(apksource, apkdst);
    // End dialog activity to return to app wizard.
    finish();
//TODO: Cleanup leftover directories (Unzipped app directory, pulled app directory are not needed.)
}
Also used : Bitmap(android.graphics.Bitmap) PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 90 with PackageManager

use of android.content.pm.PackageManager in project ARChon-Packager by bpear96.

the class activityInstalled method pullAPk.

public void pullAPk() {
    //Pull APK from selected installed app. Uses PackageInfo and PackageManager.
    List<PackageInfo> PackList = getPackageManager().getInstalledPackages(0);
    PackageInfo PackInfo = PackList.get(SelectedAppId);
    if ((PackInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
        File org = new File(PackInfo.applicationInfo.publicSourceDir);
        String PackageNamePull = PackInfo.applicationInfo.packageName;
        g.setPackageName(PackageNamePull);
        //Setup directories.
        setupFolders();
        //Extract app icon to use with chrome.
        PackageManager pm = getPackageManager();
        Drawable icon = PackInfo.applicationInfo.loadIcon(pm);
        Bitmap bmpIcon = ((BitmapDrawable) icon).getBitmap();
        String extStorageDirectory = Environment.getExternalStorageDirectory().toString() + "/ChromeAPKS/" + SelectedAppName + File.separator;
        OutputStream outStream = null;
        File file = new File(extStorageDirectory, "icon.png");
        try {
            outStream = new FileOutputStream(file);
            bmpIcon.compress(Bitmap.CompressFormat.PNG, 100, outStream);
            outStream.flush();
            outStream.close();
        } catch (Exception e) {
            Toast.makeText(activityInstalled.this, "Error: APK not pulled.", Toast.LENGTH_LONG).show();
        }
        try {
            String file_name = PackInfo.applicationInfo.loadLabel(getPackageManager()).toString();
            Log.d("file_name--", " " + file_name);
            PackageName = PackInfo.applicationInfo.packageName;
            // make directory for pulled apks
            File apk = new File(Environment.getExternalStorageDirectory().toString() + "/ChromeAPKS/Pulled");
            apk.mkdirs();
            // Set pulled apk to its proper name
            apk = new File(apk.getPath() + "/" + file_name + ".apk");
            // Move APK
            apk.createNewFile();
            InputStream in = new FileInputStream(org);
            OutputStream out = new FileOutputStream(apk);
            byte[] buf = new byte[1024];
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            in.close();
            out.close();
            System.out.println("File copied.");
        } catch (FileNotFoundException ex) {
            System.out.println(ex.getMessage() + " in the specified directory.");
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }
        g.setAPKPath(Environment.getExternalStorageDirectory() + "/ChromeAPKS/Pulled/" + SelectedAppName + ".apk");
        File apksource = new File(Environment.getExternalStorageDirectory() + "/ChromeAPKS/Pulled/" + SelectedAppName + ".apk");
        File apkdst = new File(Environment.getExternalStorageDirectory().toString() + File.separator + "ChromeAPKS/" + SelectedAppName + "/vendor/chromium/crx/" + PackageName + ".apk");
        try {
            copy(apksource, apkdst);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //Finish activity dialog to return to main wizard.
    finish();
}
Also used : PackageInfo(android.content.pm.PackageInfo) BufferedInputStream(java.io.BufferedInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) FileNotFoundException(java.io.FileNotFoundException) BitmapDrawable(android.graphics.drawable.BitmapDrawable) IOException(java.io.IOException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream) Bitmap(android.graphics.Bitmap) PackageManager(android.content.pm.PackageManager) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Aggregations

PackageManager (android.content.pm.PackageManager)1482 Intent (android.content.Intent)505 ResolveInfo (android.content.pm.ResolveInfo)460 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)353 PackageInfo (android.content.pm.PackageInfo)270 ApplicationInfo (android.content.pm.ApplicationInfo)253 ComponentName (android.content.ComponentName)241 ArrayList (java.util.ArrayList)158 ActivityInfo (android.content.pm.ActivityInfo)140 IOException (java.io.IOException)127 RemoteException (android.os.RemoteException)105 Drawable (android.graphics.drawable.Drawable)94 IPackageManager (android.content.pm.IPackageManager)93 Resources (android.content.res.Resources)91 PendingIntent (android.app.PendingIntent)75 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)69 Context (android.content.Context)68 Bundle (android.os.Bundle)60 HashMap (java.util.HashMap)55 ServiceInfo (android.content.pm.ServiceInfo)48