注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

沉默蜂B4A安卓编程

国内资料最全的B4A资料库

 
 
 

日志

 
 

[原创]小米手机截图代码  

2014-10-01 14:20:38|  分类: B.图形 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

成都-幸运之神 2014-9-18 15:04:20

像截屏、重启、关机等危害用户手机系统的行为都是谷歌禁止随意调用的,都要在特殊的环境下编译才能有效。


【话唠】大饼 2014-9-6 22:15:42

'返回主屏,这个是模拟按下home键实现的 

Dim i As Intent   

   i.Initialize(i.ACTION_MAIN, "")   

   i.AddCategory("android.intent.category.HOME")   

   i.Flags = 268435456   

   StartActivity(i)



'截屏 (大饼提供,是他发现了小米的截屏包名,发自内心感谢)
Sub Scrhot
Dim i As Intent
i.Initialize("android.intent.action.CAPTURE_SCREENSHOT", "")
Dim p As Phone
p.SendBroadcastIntent(i)
End Sub


--------------------------------------------------------------------------------------------------------------
附:

以下是来自官网,关于获取当前手机上运行的应用包名和程序图标的相关代码

http://www.b4x.com/android/forum/threads/command-to-get-packagename-of-the-current-app.21592/

Sub GetPackageName As String
   Dim r As Reflector
   Return r.GetStaticField("anywheresoftware.b4a.BA", "packageName")
End Sub


http://www.b4x.com/android/forum/threads/packagemanager.47028/#content
Sub GetAppName As String
   Dim no As NativeObject
   no = no.Initialize("NSBundle").RunMethod("mainBundle", Null)
   Dim name As Object = no.RunMethod("objectForInfoDictionaryKey:", Array("CFBundleDisplayName"))
   Return name
End Sub

Sub GetVersion As String
   Dim no As NativeObject
   no = no.Initialize("NSBundle").RunMethod("mainBundle", Null)
   Dim name As Object = no.RunMethod("objectForInfoDictionaryKey:", Array("CFBundleShortVersionString"))
   Return name
End Sub



http://www.b4x.com/android/forum/threads/list-of-running-applications-and-package-names.29735/#post-172988

Dim pm As PackageManager
Dim Icons As BitmapDrawable
Dim Appname As String


Dim Obj1, Obj2, Obj3 As Reflector
Dim size, i, flags As Int
Dim msg, name As String
Obj1.Target = Obj1.GetContext
Obj1.Target = Obj1.RunMethod("getPackageManager") ' PackageManager
Obj1.Target = Obj1.RunMethod2("getInstalledPackages", 0, "java.lang.int") ' List<PackageInfo>
size = Obj1.RunMethod("size")
For i = 0 To size -1
    Obj2.Target = Obj1.RunMethod2("get", i, "java.lang.int") ' PackageInfo
    name = Obj2.GetField("packageName")
    Obj3.Target = Obj2.GetField("applicationInfo") ' ApplicationInfo        
      
  
   
   
    Icons = pm.GetApplicationIcon(name)
    Appname = pm.GetApplicationLabel (name)
   
   AppList.AddTwoLinesAndBitmap ( Appname,name,Icons.Bitmap )










http://www.b4x.com/android/forum/threads/inline-java-4-get-running-package-name.56203/#post-353714
以下是JAVA代码


public class DetectCalendarLaunchRunnable implements Runnable {

@Override
public void run() {
  String[] activePackages;
  if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) {
    activePackages = getActivePackages();
  } else {
    activePackages = getActivePackagesCompat();
  }
  if (activePackages != null) {
    for (String activePackage : activePackages) {
      if (activePackage.equals("com.google.android.calendar")) {
        //Calendar app is launched, do something
      }
    }
  }
  mHandler.postDelayed(this, 1000);
}

String[] getActivePackagesCompat() {
  final List<ActivityManager.RunningTaskInfo> taskInfo = mActivityManager.getRunningTasks(1);
  final ComponentName componentName = taskInfo.get(0).topActivity;
  final String[] activePackages = new String[1];
  activePackages[0] = componentName.getPackageName();
  return activePackages;
}

String[] getActivePackages() {
  final Set<String> activePackages = new HashSet<String>();
  final List<ActivityManager.RunningAppProcessInfo> processInfos = mActivityManager.getRunningAppProcesses();
  for (ActivityManager.RunningAppProcessInfo processInfo : processInfos) {
    if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
      activePackages.addAll(Arrays.asList(processInfo.pkgList));
    }
  }
  return activePackages.toArray(new String[activePackages.size()]);
}
}


以下是JAVA代码
ActivityManager manager = (ActivityManager)mContext.getSystemService(Context.ACTIVITY_SERVICE);

List<ActivityManager.RunningAppProcessInfo> tasks = manager.getRunningAppProcesses(); 

Log.i("current_app",tasks.get(0).processName);
  评论这张
 
阅读(125)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017