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);
}
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";
}
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;
}
}
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.)
}
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();
}
Aggregations