我写了一个简单的Android应用程序,显示如下自定义通知:
Context context = getApplicationContext();
NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification( R.drawable.icon, title, System.currentTimeMillis());
Intent notificationIntent = new Intent( context, this.getClass());
notificationIntent.putExtra("com.mysecure.lastpage", "SECURECODE");
PendingIntent pendingIntent = PendingIntent.getActivity( context , 0, notificationIntent, 0);
notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;
notification.contentView = new RemoteViews(context.getPackageName(), R.layout.notifypbar);
notification.contentIntent = pendingIntent;
notification.contentView.setTextViewText(R.id.notifypb_status_text, text);
notification.contentView.setProgressBar(R.id.notifypb_status_progress, 100, (int)(100*progress), false);
manager.notify(104, notification);
Run Code Online (Sandbox Code Playgroud)
这段代码在我的应用程序中被称为ONLY ONCE,它显示带有进度条的通知(全部正确).
现在,当用户点击此通知时,我的应用程序会处理该onResume事件.
public void onResume()
{
super.onResume();
// TODO: Extras è SEMPRE NULL!!! impossibile!
Intent callingintent = getIntent();
Bundle extras = …Run Code Online (Sandbox Code Playgroud) 在我的android应用程序中,我总是使用类的直接putExtra()函数Intent将任意数量的值传递给new Activity.
像这样:
Intent i = new Intent(this, MyActivity.class);
i.putExtra(ID_EXTRA1, "1");
i.putExtra(ID_EXTRA2, "111");
startActivity(i);
Run Code Online (Sandbox Code Playgroud)
我Bundle在Android中知道,我看到人们正在使用Bundle将值传递给新的Activity.
像这样:
Intent intent = new Intent(this, MyActivity.class);
Bundle extras = new Bundle();
extras.putString("EXTRA_USERNAME","my_username");
extras.putString("EXTRA_PASSWORD","my_password");
intent.putExtras(extras);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
在这里,我有两个疑问.如果我可以直接将值传递给new ,我
为什么要使用?
使用而不是直接使用有什么好处?BundleActivityIntentBundleIntent putExtra()
我在我的应用程序中发生了一个警报,它会启动一个通知,然后在按下时启动一个活动.问题是,当我创建多个警报时,从通知启动的活动会获得与第一个相同的额外内容.我认为这个问题要么是我在未决意图中的意图,要么是在未决意图本身.我想我可能需要在其中一个上放一面旗帜,但我不知道哪一个.
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);
Run Code Online (Sandbox Code Playgroud)
和通知的接收者
Bundle b = getIntent().getExtras();
String eventname = b.getString("details");
details.setText(eventname);
Run Code Online (Sandbox Code Playgroud)
每次下次通知发生时,"详细信息"额外都是相同的,而不是具有不同的值.直到我设置意图,我确信正确的值转到"详细信息",因此每次按任何通知时都会获得第一个意图的问题.如何才能启动正确的意图呢?希望我尽可能清楚,谢谢!
我一直在使用Phonegap开发Android应用程序,现在想要关闭应用程序,它仍然可以在应用程序中执行java/js代码.所以我理解我需要创建一个服务.如果我在phonegap上创建服务插件,我仍然可以执行javascript代码或只执行java吗?
有没有人做过这样的事情?我找到了这个讨论,但似乎没有用:http://groups.google.com/group/phonegap/browse_thread/thread/722b0e796baa7fc6 这就是我现在所拥有的一切.
在我转向开发本土之前,如果我无法弄清楚它以为我会问以前是否有人这样做过.我似乎无法找到任何类似的手机插件插件.
编辑:我有一个应用程序执行Java代码作为服务.但是当它调用sendjavascript时它不起作用.那么有什么方法可以在后台运行javascript代码以及使用phonegap关闭应用程序时?
谢谢
我有一个LoginActivity(用户登录).它基本上是它自己Activity的主题就像一个对话框(看起来像一个对话框).它出现在一个SherlockFragmentActivity.我想要的是:如果登录成功,应该有两个FragmentTransaction更新视图.这是代码:
在LoginActivity,如果成功登录,
setResult(1, new Intent());
Run Code Online (Sandbox Code Playgroud)
在SherlockFragmentActivity:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == 1) {
LoggedStatus = PrefActivity.getUserLoggedInStatus(this);
FragmentTransaction t = MainFragmentActivity.this.getSupportFragmentManager().beginTransaction();
SherlockListFragment mFrag = new MasterFragment();
t.replace(R.id.menu_frame, mFrag);
t.commit();
// Set up Main Screen
FragmentTransaction t2 = MainFragmentActivity.this.getSupportFragmentManager().beginTransaction();
SherlockListFragment mainFrag = new FeaturedFragment();
t2.replace(R.id.main_frag, mainFrag);
t2.commit();
}
}
Run Code Online (Sandbox Code Playgroud)
它在第一次提交时崩溃,使用此LogCat:
E/AndroidRuntime(32072): Caused by: java.lang.IllegalStateException: Can not perform this action …Run Code Online (Sandbox Code Playgroud) android android-intent android-activity android-fragmentactivity
我有一个地图视图活动,显示了一些OverlayItems.在onTap叠加方法中,我想触发一个新活动,例如,将此叠加照片显示为全屏.
当我在overlay类中执行此操作时:
Intent intent = new Intent();
intent.setClass(getApplicationContext, FullscreenView.class);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
..它无法找到应用程序上下文,因为我不在活动范围内.
当我向主要活动添加方法时,让我们说startFullscreen:
public static void startFullscreen() {
if (sCurrentPhoto != null) {
Intent intent = new Intent();
intent.setClass(getApplicationContext(), FullscreenView.class);
startActivity(intent);
}
}
Run Code Online (Sandbox Code Playgroud)
我不能打电话getApplicationContext()和startActivity(),因为我在一个静态的背景.我需要静态方法然后在Overlay类中调用它MainView.startFullscreen().
简单地说:如何从非Activity类启动Activity?
我见过很多不同的令人困惑的言论.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
的意义是什么
<action android:name="android.intent.action.MAIN" />
Run Code Online (Sandbox Code Playgroud)
和
<category android:name="android.intent.category.LAUNCHER" />
Run Code Online (Sandbox Code Playgroud)
和
<category android:name="android.intent.category.DEFAULT" />
Run Code Online (Sandbox Code Playgroud) 我想收到Android广播消息.是否有所有意图的清单?
我们所知道的通常(在实践中任何)防病毒应用程序在卸载之前用于触发简单的对话框,例如:"你要卸载应用程序,你确定吗?" - "是/否".
是的,我知道我可以使用intent-filter拦截包删除意图,例如:
<activity
android:name=".UninstallIntentActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.DELETE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="package" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
但问题很简单,这会拦截任何删除请求,而且这会触发我的应用程序和库存安装程序之间的选择器对话框.因此,如果用户将选择库存安装程序 - 我将无法做任何事情.
我的目标不是阻止用户卸载我的应用程序,而只是回滚我的应用程序所做的更改.
从这些防病毒应用程序中学习我发现这种操作是可行的,所以请帮助我并解释它是如何可能的?
更新
由于有些人不相信它是真的 - 我会参考Avast移动安全:
Anti-Theft通过各种自我保护技术伪装其组件来保护自己免于卸载.
另一个例子:适用于Android的卡巴斯基互联网安全 - 这是卸载它的特殊程序,需要输入密码.
无论如何,这意味着有办法拦截卸载程序,以防止卸载或完成一些最终工作.
我正在尝试启动Intent来发送电子邮件.所有这一切都有效,但当我尝试实际发送电子邮件时,会发生一些"奇怪"的事情.
这是代码
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("image/jpeg");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Photo");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://sdcard/dcim/Camera/filename.jpg"));
sendIntent.putExtra(Intent.EXTRA_TEXT, "Enjoy the photo");
startActivity(Intent.createChooser(sendIntent, "Email:"));
Run Code Online (Sandbox Code Playgroud)
因此,如果我使用Gmail菜单上下文启动它会显示附件,让我输入电子邮件的来源,并编辑正文和主题.没什么大不了.我点击发送,它发送.唯一的事情是附件不会被发送.
所以.我想,为什么不尝试使用电子邮件菜单上下文(对于我手机上的备份电子邮件帐户).它显示附件,但在身体或主体中根本没有文字.当我发送它时,附件发送正确.这会让我相信一些事情是错误的.我是否需要在Manifest发布中获得新的权限才能发送带附件的电子邮件?我究竟做错了什么?
android ×10
android-intent ×10
attachment ×1
broadcast ×1
bundle ×1
cordova ×1
email ×1
extra ×1
mobile ×1
uninstall ×1