Android实例-调用系统APP(XE10+小米2)

相关资料:
1.群号383675978
2.http://blog.sina.com.cn/s/blog_44fa172f0101rmjt.html
3.PS:ListView1.ItemAppearanceObjects.ItemObjects.Text.Font.Size:=20; 设置字体大小,属性面板也可以设置。代码设置时需要看一下手机支持的大小是多少。
实例源码:
unit Unit1; interface uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
FMX.Controls.Presentation, FMX.Edit,
Androidapi.JNI.JavaTypes,//JString使用
Androidapi.JNI.GraphicsContentViewText,//JIntent使用
FMX.Surfaces,//TBitmapSurface使用
Androidapi.Helpers,//SharedActivity使用
System.IOUtils,//TPath使用
Androidapi.JNIBridge,//ILocalObject使用
FMX.Helpers.Android,//JBitmapToSurface使用
System.Generics.Collections,//TList使用
FMX.ListView.Types, FMX.ListView.Appearances,
FMX.ListView.Adapters.Base, FMX.ListView, FMX.StdCtrls, FMX.ScrollBox,
FMX.Memo; type
TForm1 = class(TForm)
Edit1: TEdit;
ListView1: TListView;
Button1: TButton;
Memo1: TMemo;
procedure Edit1Change(Sender: TObject);
procedure Edit1Typing(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ListView1ItemClick(const Sender: TObject;
const AItem: TListViewItem);
private
{ Private declarations }
MainList : TList<JActivityInfo>;
dictAppIcons : TDictionary<Integer, TBitmap>;
//过虑方法
procedure FilterListView(AListView: TListView; AFilterName: string);
//打开APP方法
procedure OpenApp(PackageName, AppName : JString);
//获取安装的APP
function GetActivityAppList: JList;
function GetOrSetCashAppIcon(appInfo: JApplicationInfo): TBitmap;
procedure LoadActivityInfoList(var List: TList<JActivityInfo>);
procedure LoadDictonaryAppIcons(index: Integer; appInfo: JApplicationInfo;
var dictonaryAppIcons: TDictionary<Integer, TBitmap>);
procedure LoadListView(listView: TListView; AppList: TList<JActivityInfo>;
dictonaryAppIcons: TDictionary<Integer, TBitmap>);
procedure LoadListViewBitmap(listView: TListView; AppList: TList<JActivityInfo>;
var dictonaryAppIcons: TDictionary<Integer, TBitmap>);
public
{ Public declarations }
end; const
DEFAUT_INDEX: Integer = -; var
Form1: TForm1; implementation {$R *.fmx}
{$R *.NmXhdpiPh.fmx ANDROID} { TForm1 }
//调用打开APP
procedure TForm1.Button1Click(Sender: TObject);
begin
OpenApp(StringToJString('com.androidillusion.videocamillusionpro'),
StringToJString('com.androidillusion.videocamillusionpro.VideoillusionActivity'));
end; //改变事件
procedure TForm1.Edit1Change(Sender: TObject);
begin
if Edit1.Text = '' then
FilterListView(Self.ListView1, Edit1.Text.Trim);
end; //输入事件
procedure TForm1.Edit1Typing(Sender: TObject);
begin
FilterListView(Self.ListView1, Edit1.Text.Trim);
end; //过虑方法
procedure TForm1.FilterListView(AListView: TListView; AFilterName: string);
var
i: integer;
item: TListViewItem;
lower: string;
begin
if not Assigned(AListView) then
Exit;
lower := AFilterName.ToLower.Trim;
if lower.IsEmpty then
begin
if Assigned(AListView.Items.Filter) then
AListView.Items.Filter := nil;
end
else
begin
AListView.ItemIndex := DEFAUT_INDEX;
AListView.Items.Filter :=
function(sFilter: string): Boolean
begin
Result := (lower.IsEmpty) or sFilter.ToLower.Contains(lower);
end;
end;
end; procedure TForm1.FormCreate(Sender: TObject);
begin
LoadActivityInfoList(MainList);
LoadListView(Self.ListView1, MainList, self.dictAppIcons);
LoadListViewBitmap(Self.ListView1, MainList, self.dictAppIcons);
end; //获取安装的APP
function TForm1.GetActivityAppList: JList;
var
tempList: JList;
Intent: JIntent;
Manager: JPackageManager;
begin
Intent := TJIntent.Create;
Intent.SetAction(TJIntent.JavaClass.ACTION_MAIN);
Intent.AddCategory(TJIntent.JavaClass.CATEGORY_LAUNCHER);
Manager := SharedActivity.GetPackageManager;
tempList := nil;
tempList := Manager.QueryIntentActivities(Intent, );
Result := tempList;
end; function TForm1.GetOrSetCashAppIcon(appInfo: JApplicationInfo): TBitmap;
var
Drawable: JDrawable;
Bitmap: JBitmap;
itemBitmap: TBitmap;
Surface: TBitmapSurface;
saveDir: string;
pngFileName: string;
SaveParams: TBitmapCodecSaveParams;
begin
if not Assigned(appInfo) then
begin
Result := itemBitmap;
Exit;
end; saveDir := TPath.GetCachePath;
pngFileName := saveDir + '/' + JStringToString(appInfo.packageName) + '.png';
itemBitmap := TBitmap.Create;
if not TDirectory.Exists(saveDir, False) then
TDirectory.CreateDirectory(saveDir);
if TFile.Exists(pngFileName) then
itemBitmap.LoadFromFile(pngFileName)
else
begin
Drawable := appInfo.loadIcon(SharedActivity.getPackageManager);
Bitmap := TJBitmapDrawable.Wrap((Drawable as ILocalObject).GetObjectID).getBitmap;
Surface := TBitmapSurface.Create;
try
if JBitmapToSurface(Bitmap, Surface) then
begin
itemBitmap.Assign(Surface);
SaveParams.Quality := ;
itemBitmap.SaveToFile(pngFileName, @SaveParams);
end;
finally
Surface.Free;
end;
end;
Result := itemBitmap;
end; procedure TForm1.ListView1ItemClick(const Sender: TObject;
const AItem: TListViewItem);
begin
if not Assigned(MainList) then
Exit;
OpenApp(MainList.Items[AItem.Tag].applicationInfo.packageName,
MainList.Items[AItem.Tag].name);
Memo1.Lines.Add(JStringToString(MainList.Items[AItem.Tag].applicationInfo.packageName) + '/\' + JStringToString(MainList.Items[AItem.Tag].name));
end; procedure TForm1.LoadActivityInfoList(var List: TList<JActivityInfo>);
var
tempList: JList;
i: Integer;
ResolveInfo: JResolveInfo;
Info: JActivityInfo;
AppInfo: JApplicationInfo;
begin
if not Assigned(List) then
List := TList<JActivityInfo>.Create;
List.Clear;
tempList := Self.GetActivityAppList;
for i := to tempList.size - do
begin
ResolveInfo := TJResolveInfo.Wrap((tempList.get(i) as ILocalObject).GetObjectID);
Info := TJActivityInfo.Wrap((ResolveInfo.activityInfo as ILocalObject).GetObjectID);
AppInfo := TJApplicationInfo.Wrap((Info.applicationInfo as ILocalObject).GetObjectID);
List.Add(Info);
end;
end; procedure TForm1.LoadDictonaryAppIcons(index: Integer;
appInfo: JApplicationInfo;
var dictonaryAppIcons: TDictionary<Integer, TBitmap>);
var
itemBitmap : TBitmap;
begin
if not Assigned(dictonaryAppIcons) then
dictonaryAppIcons := TDictionary<Integer, TBitmap>.Create;
if not dictonaryAppIcons.ContainsKey(index) then
begin
itemBitmap := GetOrSetCashAppIcon(appInfo);
dictonaryAppIcons.AddOrSetValue(index, itemBitmap);
end;
end; procedure TForm1.LoadListView(listView: TListView;
AppList: TList<JActivityInfo>;
dictonaryAppIcons: TDictionary<Integer, TBitmap>);
var
tempItem : TListViewItem;
tempString, tempSubString, tempSubString2 : string;
i : integer;
begin
if (not Assigned(listView)) or (not Assigned(AppList)) then
Exit;
listView.Items.Clear;
listView.BeginUpdate;
for I := to AppList.Count - do
begin
tempString := JStringToString(AppList.Items[i].applicationInfo.loadLabel(SharedActivity.getPackageManager).toString);
tempItem := listView.Items.Add;
tempItem.Text := tempString;
tempItem.Tag := i;
end;
listView.EndUpdate;
end; procedure TForm1.LoadListViewBitmap(listView: TListView;
AppList: TList<JActivityInfo>;
var dictonaryAppIcons: TDictionary<Integer, TBitmap>);
var
i: integer;
begin
if (not Assigned(listView)) or (not Assigned(AppList)) then
Exit;
listView.BeginUpdate;
for I := to listView.ItemCount - do
begin
listView.Items[i].BeginUpdate;
LoadDictonaryAppIcons(i, AppList.Items[listView.Items[i].Tag].applicationInfo, dictonaryAppIcons);
if Assigned(dictonaryAppIcons) and (dictonaryAppIcons.ContainsKey(i)) then
listView.Items[i].Bitmap := dictonaryAppIcons.Items[i];
listView.Items[i].EndUpdate;
Application.ProcessMessages;
end;
listView.EndUpdate;
end; //打开APP方法
procedure TForm1.OpenApp(PackageName, AppName: JString);
var
Intent : JIntent;
NativeComponent : JComponentName;
begin
Intent := TJIntent.Create;
Intent.setAction(TJIntent.JavaClass.ACTION_MAIN);
Intent.addCategory(TJIntent.JavaClass.CATEGORY_LAUNCHER);
NativeComponent := TJComponentName.JavaClass.init(PackageName, AppName);
Intent.addFlags(TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK or TJIntent.JavaClass.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Intent.setComponent(NativeComponent);
SharedActivity.startActivity(Intent);
end; end.
Android实例-调用系统APP(XE10+小米2)的更多相关文章
- Android实例-获取程序版本号(XE10+小米2)
相关资料: 383675978群号 实例源码: unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, Sy ...
- Java乔晓松-android中调用系统拍照功能并显示拍照的图片
android中调用系统拍照功能并显示拍照的图片 如果你是拍照完,利用onActivityResult获取data数据,把data数据转换成Bitmap数据,这样获取到的图片,是拍照的照片的缩略图 代 ...
- Android Studio搭建系统App开发环境
一.前言 在Android的体系中开发普通app使用Android Studio这一利器会非常的方便.但是开发系统app可能就会有些吃力,不过经过一些配置仍然会 很简单.我们知道系统app因为涉及到一 ...
- Android中调用系统所装的软件打开文件(转)
Android中调用系统所装的软件打开文件(转) 在应用中如何调用系统所装的软件打开一个文件,这是我们经常碰到的问题,下面是我所用到的一种方法,和大家一起分享一下! 这个是打开文件的一个方法: /** ...
- android intent调用系统camera
利用android的camera通常有两种方式:利用intent调用系统的camera,或者结合surfaceview实现自己定制的camera.先分别对这两种方法说明如下: 一.使用系统自配的cam ...
- android中调用系统的发送短信、发送邮件、打电话功能
1 调用发送短信功能: Uri smsToUri = Uri.parse("smsto:"); Intent sendIntent = new Intent(Intent.ACT ...
- [Android Pro] 调用系统相机和图库,裁剪图片
private static final int PHOTO_REQUEST_TAKEPHOTO = 1;// 拍照 private static final int PHOTO_REQUEST_GA ...
- Android实例-调用GOOGLE的TTS实现文字转语音(XE7+小米2)(XE10.1+小米5)
相关资料: 注意:在手机上必须选安装文字转语音引擎“google Text To Speech”地址:http://www.shouji56.com/soft/GoogleWenZiZhuanYuYi ...
- Android实例-调用GOOGLE的TTS实现文字转语音(XE7+小米2)(无图)
注意:在手机上必须选安装文字转语音引擎“google Text To Speech”地址:http://www.shouji56.com/soft/GoogleWenZiZhuanYuYinYinQi ...
随机推荐
- mybatis源码分析(1)——SqlSessionFactory实例的产生过程
在使用mybatis框架时,第一步就需要产生SqlSessionFactory类的实例(相当于是产生连接池),通过调用SqlSessionFactoryBuilder类的实例的build方法来完成.下 ...
- js风格技巧
1.一个页面的所有js都可以写成这样,比如: var index ={}; index.User = ****; index.Init = function(){ $("$tes ...
- VS2010解决方案不显示无法添加项目问题
问题:在VS2010中不显示解决方案,导致不能添加项目. 方法:工具-选项-项目和解决方案-选中“总是显示解决方案”,ok
- android开发中eclipse里xml开发的自动提示和使用帮助快捷键提示
Eclipse Android 代码自动提示功能 Eclipse for android 设置代码提示功能 打 开 Eclipse 依次选择 Window > Preferences > ...
- CentOS6.6安装mysql出现的问题
mysql编译需要cmake,我的cmake-2.6.4-5.el6.i686,最新版的是3.1.0,我就先用2.6.4的试试 [root@localhost src]# wget http:// ...
- Web Api 中使用 PCM TO WAV 的语音操作
/// <summary> /// 语音[文件.上传.解码.保存(WAV)] /// </summary> [DeveloperEx("Liwei:秘书语音需求单&q ...
- UVALive 4128 Steam Roller(最短路(拆点,多状态))
题意:模拟了汽车的行驶过程,边上的权值为全速通过所消耗的时间,而起步(从起点出发的边).刹车(到终点结束的边).减速(即将拐弯的边).加速(刚完成拐弯的边)这四种不能达到全速的情况,消耗的时间为权值* ...
- HDU 5301 Buildings 建公寓(逻辑,水)
题意:有一个包含n*m个格子的矩阵,其中有一个格子已经被染黑,现在要拿一些矩形来填充矩阵,不能填充到黑格子,但是每一个填充进去的矩形都必须至少有一条边紧贴在矩阵的边缘(4条边)的.用于填充的矩形其中最 ...
- 【CSS】使用CSS改变超链接样式
超链接代码 <ahrefahref="http://www.divCSS5.com/"target="_blank" title="关于divC ...
- 如何获取数据块结构信息dump
有个pub_department的表,索引为PK_PUB_DEPARTMENT. 1.找到object_id select object_id from dba_objects s where ...