Tag: android intent

在屏幕上更改对话框的位置

我在Activity中做了一个简单的AlertDialog : View view = layoutInflater.inflate(R.layout.my_dialog, null); AlertDialog infoDialog = new AlertDialog.Builder(MyActivity.this) .setView(view) .create(); infoDialog.show(); 使用上面的代码, 对话框显示在屏幕的中心(大约)。 我想知道,我如何自定义对话框的位置,使其显示在最上面的操作栏? (无论如何改变对话的重力或东西?),以及如何根据我的代码做到这一点?

Android / Android中的getIntent()。getExtras()方法

有了活动,我曾经这样做: 在活动1中: Intent i = new Intent(getApplicationContext(), MyFragmentActivity.class); i.putExtra("name", items.get(arg2)); i.putExtra("category", Category); startActivity(i); 活动2: Item = getIntent().getExtras().getString("name"); 你如何使用碎片来做到这一点? 我也在使用兼容性库v4。 它是否在FragmentActivity? 还是实际的片段? 它进入哪个方法? 的onCreate? onCreateView? 另一个? 我能看到示例代码吗? 编辑:值得注意的是,我试图保持活动1作为一个活动(或实际ListActivity,我通过listitem意图单击时),然后传递给一组tabbed-fragments(通过片段活动),我需要任何标签才能获得额外的。 (我希望这是可能的?)

如何跨两个不同的android应用程序共享SharedPreferences文件?

我一直在努力。 基本上,我想要有两个应用程序(它们将始终安装在一起)共享偏好,其中之一就是在后台运行的服务,需要使用偏好(应该拥有偏好,但只有真正需要阅读偏好),另一个应用程序是前端UI应用程序,需要能够写入其他应用程序拥有的首选项文件。 该服务将在后台进行操作(可能由首选项决定),用户界面将允许用户编辑首选项并查看服务中的某些信息。 但是,它们将是不同的软件包/应用程序。 我试着按照这个教程给了我一个关于如何在一个应用程序中可以被另一个应用程序读取的偏好的相当好的想法。 从本质上讲,我通过myContext = createPackageContext("com.example.package",Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);创build一个新的上下文myContext = createPackageContext("com.example.package",Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); 然后调用myContext.getSharedPreferences("pref_name", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); 但是,我无法从外部应用程序成功地写入首选项 – (SharedPreferences.Editor).commit()返回false,并在logcat中获得有关无法编辑pref_name.xml.bak的警告。 我怎样才能成功地设置我的应用程序,使他们都可以读取和写入相同的首选项文件(存储在其中之一的数据文件夹)?

如何检查是否可以从某些活动处理意图?

到目前为止,我有这个方法,但是就像缺less某些东西一样 例如我有一个文件/ SD卡/声音.3ga,返回false(就像没有活动,可以处理这种types的文件),但是当我从文件pipe理器打开它与媒体播放器没有问题 我认为这个意图不是完整的,我需要更多的东西来确保handlerExistsvariables只有在没有可以处理这个意图的活动 PackageManager pm = getPackageManager(); Intent intent = new Intent(android.content.Intent.ACTION_VIEW); String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(new File(uriString)).toString()); String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); intent.setDataAndType(Uri.fromFile(new File(uriString)),mimetype); boolean handlerExists = intent.resolveActivity(pm) != null;

无法启动服务意图

我有一个服务class。 我已经将这个类导出到jar,我已经在我的客户端应用程序中embedded了jar。 需要时,我打电话给服务class。 当我尝试这样做时,出现以下错误: Unable to start service Intent {comp={com.sample.service/com.sample.service.serviceClass}} : not found 除了服务类以外,我还有其他类,我可以访问(创build该类的对象),它们位于同一个jar中。 我觉得我已经错过了我的configuration或清单中的一些东西。 请帮我确定一下。 我的代码如下: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = new Intent () ; intent.setClassName("com.sample.service" ,"com.sample.service.serviceClass") ; this.startService(intent) ; // when I call this line I get the message… // binding other process continue here } 客户端manifest.xml <service android:name="com.sample.service.serviceClass" […]

如何让拨号程序显示电话号码?

我不需要拨打电话号码,我只需要拨号器打开已显示的电话号码。 我应该用什么Intent来达到这个目的?

确定addAction点击Android通知

我正在尝试使用新的通知界面。 我已经在通知中添加了3个button,并且每次单击它们时都想将其保存到数据库中。 通知本身运作良好,被调用时显示,我只是不知道如何捕获三个不同的button点击每一个。 我正在使用BroadcastReceiver来捕捉点击,但我不知道如何分辨哪个button被点击。 这是AddAction的代码(我已经排除了其他的通知,因为它的工作很好) – //Yes intent Intent yesReceive = new Intent(); yesReceive.setAction(CUSTOM_INTENT); Bundle yesBundle = new Bundle(); yesBundle.putInt("userAnswer", 1);//This is the value I want to pass yesReceive.putExtras(yesBundle); PendingIntent pendingIntentYes = PendingIntent.getBroadcast(this, 12345, yesReceive, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.addAction(R.drawable.calendar_v, "Yes", pendingIntentYes); //Maybe intent Intent maybeReceive = new Intent(); maybeReceive.setAction(CUSTOM_INTENT); Bundle maybeBundle = new Bundle(); maybeBundle.putInt("userAnswer", 3);//This is […]

android等待意图通知问题

我在我的应用程序中发生了一个警报事件,它会启动一个通知,然后按下时启动一个活动。 问题是,当我创build多个警报时,从通知中启动的活动获得与第一个相同的额外资源。 我认为这个问题或者是出于意图,或者是等待意图本身。 我想我可能需要在其中的一个标志,但我不知道哪一个。 Intent showIntent =new Intent(context, notificationreceiver.class); showIntent.putExtra("details", alarmname); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, showIntent, 0); notification.setLatestEventInfo(context, "The event is imminent", alarmname, contentIntent); 和通知的接收者 Bundle b = getIntent().getExtras(); String eventname = b.getString("details"); details.setText(eventname); 下一次发生通知而不是具有不同的值时,“细节”额外的相同。 在我设定意图之前,我确信正确的价值是“细节”,所以每次我按任何通知时,都会得到第一个意图的问题。 我怎样才能使其发起正确的意图? 希望我尽可能清楚,谢谢!

使用Android意图发送HTML邮件

我已经生成了一个HTML代码(包含<html><body></body></html>标记)作为String。 现在我想把这个HTML代码作为HTML发送给邮件。 我的代码如下。 Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/html"); intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"me@mydomain.com"}); intent.putExtra(Intent.EXTRA_SUBJECT, "I would like to buy the following"); intent.putExtra(Intent.EXTRA_TEXT, purchaseOrder()); startActivity(Intent.createChooser(intent, "sending mail")); 其中purchaseOrder()是将具有完整HTML代码的string传递给我的方法。 但是,尽pipeGMail客户端在我的Nexus1上打开,但它具有包含所有HTML标记的string,而不是实际的HTML视图。 我尝试了以下,但得到错误。 GMail坠毁。 intent.putExtra(Intent.EXTRA_STREAM, purchaseOrder());

Android继续caching我的意图额外,如何申报一个待定的意图,保持新鲜的额外?

几天前,我正在努力寻找一种方法来使用自定义的意图,我的报警。 虽然我得到了明确的答案,我必须根据一些独特的ID来定制Intents。 setAction()仍然有一些问题。 我这样定义一个PendingIntent: Intent intent = new Intent(this, viewContactQuick.class); intent.setAction("newmessage"+objContact.getId());//unique per contact intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK ).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP ); intent.putExtra("id", Long.parseLong(objContact.getId())); intent.putExtra("results", result.toArray()); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, 0); 那么这被通知pipe理器使用 NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns); // first try to clear any active notification with this contact ID mNotificationManager.cancel(Integer.parseInt(objContact.getId())); // then raise a new notification for this contact […]