好的,所以我一直试图解决这个问题好几天,而且我不会来这里寻找有人为我工作,因为我一直在排除故障并修复了LogCat中的每一条错误消息.我正在使用Andengine开发Android游戏(这可能是问题的一部分,因此熟悉它可能有所帮助).我没有做任何太花哨的事情,我的游戏活动都是单一的场景,没有任何物理或类似的东西,只是一堆精灵和纹理.我还使用Andengine进行游戏中的所有其他活动,因为我觉得这是一种非常简单的方法来设置图形吸引人的屏幕.一个这样的屏幕是我的应用程序商店,用户可以购买levelpacks和新的精灵.这一切的计费部分都很有效,购买通过市场,没有什么太复杂的...
当用户点击购买时,弹出市场屏幕并加载他们选择的产品(这些是真实产品,而不是Android测试,尽管游戏未发布).市场屏幕弹出当前活动,无论我是否使用"Android 2.0"实现,它是游戏堆栈的一部分,或者我使用"Android 1.6"实现,它是自己的堆栈的一部分.我更喜欢使用Android 2.0实现,但如果我只能让1.6工作,我将采取.所以无论如何,当用户使用后退按钮取消购买或使用信用卡完成购买时,问题就出现了,这两者都导致市场屏幕消失,应用程序启动一个只是黑屏的新活动(最终时间出来并使力量接近).购买通过确定,但用户没有获得产品,因为游戏力量在我们到达代码之前退出以更改用户在游戏中的项目.现在对于一些代码,我使用本教程(http://www.anddev.org/advanced-tutorials-f21/simple-inapp-billing-payment-t52060.html)而没有做太多改动.BillingHelper类是最重要的,因为它包含requestPurchase()方法和startBuyPageActivity()方法.我从我的StoreFront活动中调用请求购买,如下所示:
BillingHelper.requestPurchase(StoreFront.this, itemID);
Run Code Online (Sandbox Code Playgroud)
在StoreFront的onCreate中我有这些东西(据tut所说):
startService(new Intent(mContext, BillingService.class));
BillingHelper.setCompletedHandler(mTransactionHandler);
Run Code Online (Sandbox Code Playgroud)
...
//some handler that billing needs
public Handler mTransactionHandler = new Handler(){
public void handleMessage(android.os.Message msg) {
Log.i(TAG, "Transaction complete");
Log.i(TAG, "Transaction status: "+BillingHelper.latestPurchase.purchaseState);
Log.i(TAG, "Item purchased is: "+BillingHelper.latestPurchase.productId);
if(BillingHelper.latestPurchase.isPurchased()){
//TODO do something here if we've completed our latest purchase,
//this should be with the status bar notifications and
//saved preferences
}
};
};
Run Code Online (Sandbox Code Playgroud)
所以我不认为那里存在问题.以下是BillingHelper的相关部分
protected static void requestPurchase(Context activityContext, String itemId){
if (amIDead()) {
return;
}
Log.i(TAG, …Run Code Online (Sandbox Code Playgroud) android timeout andengine in-app-billing android-pendingintent
我有一个安装在我的onCreate里面的android setInexactRepeating,它永远不会触发.我在其中有一个日志,以确保它实际上正在执行,并且似乎没有触发,以及我为它计划的事件.我希望它每隔10秒就会消失一次,但它甚至连第一次都没有消失.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("Restart", "First");
Intent toRun = new Intent(this, AlarmRestart.class);
PendingIntent pendingToRun = PendingIntent.getBroadcast(this, 0, toRun, 0);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.cancel(pendingToRun);
am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, System.currentTimeMillis(), 10000L, pendingToRun);
Log.d("Restart", "Second");
}
Run Code Online (Sandbox Code Playgroud)
这是在另一个文件中:
public class AlarmRestart extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Log.d("Restart", "Third");
}
}
Run Code Online (Sandbox Code Playgroud)
这就是"adb shell dumpsys alarm"所说的
com.packageName.restart
5715ms running, 64 wakeups
3 alarms: flg=0x14 cmp=com.packageName.restart/.AlarmRestart
61 alarms: flg=0x14 cmp=com.packageName.restart/.reciever.AlarmRestart
Run Code Online (Sandbox Code Playgroud) android repeat alarmmanager android-intent android-pendingintent
嗨!
我在复制PendingIntents方面遇到了麻烦.我的应用程序具有从应用程序onCreate开始的服务,执行一些异步任务并自行停止.问题是,在每一个应用程序开始我从DB在AlarmManager一套新PendingIntents的(完全一样),但他们不取消以前,即使FLAG_CANCEL_CURRENT.我通过"adb shell dumpsys alarm"来确定这个,
这是一个异步任务的onPostExecute:protected void onPostExecute(Cursor c){
while (c.moveToNext())
{
int _id = c.getInt(c.getColumnIndex(Maindb._ID));
long remind_timestamp = c.getLong(c
.getColumnIndex(Maindb.REMIND_TIMESTAMP));
String remind_name = c.getString(c.getColumnIndex(Maindb.NAME));
String remind_description = c.getString(c
.getColumnIndex(Maindb.DESCRIPTION));
Log.i("Service reminders : id = " + _id + "; REMIND_TIMESTAMP="
+ remind_timestamp + "; NAME = " + remind_name
+ "; DESCRIPTION=" + remind_description);
Intent myIntent = new Intent(ReminderService.this,
AlarmReceiver.class);
myIntent.putExtra(RemindDialog.REMIND_DIALOG_ID, _id);
myIntent.putExtra(RemindDialog.REMIND_DIALOG_NAME, remind_name);
myIntent.putExtra(RemindDialog.REMIND_DIALOG_DESCRIPTION,
remind_description);
myIntent.putExtra(RemindDialog.REMIND_DIALOG_TIMESTAMP,
remind_timestamp);
pendingIntent = PendingIntent.getService(ReminderService.this,
_id, myIntent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
AlarmManager alarmManager = …Run Code Online (Sandbox Code Playgroud) 我正在创建一个具有发送短信模块的应用程序.我正在使用2个广播接收器和待定意图,一个用于短信发送确认,另一个用于发送..短信发送广播接收器工作正常,但交付没有到来.
我在服务中使用以下代码.
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
new Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
new Intent(DELIVERED), 0);
//---when the SMS has been sent--- is working alright
registerReceiver(new BroadcastReceiver()
{
public void onReceive(Context arg0, Intent arg1)
{
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS sent",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(getBaseContext(), "Generic failure",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(getBaseContext(), "No service",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(getBaseContext(), "Null PDU",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(getBaseContext(), "Radio off",
Toast.LENGTH_SHORT).show();
break;
}
unregisterReceiver(this);
}
}, new …Run Code Online (Sandbox Code Playgroud) sms android broadcastreceiver android-service android-pendingintent
使用新的PendingIntent创建新通知时,其意图中的额外内容会覆盖任何先前通知的PendingIntent Intent附加内容.
例如,假设我使用PendingIntent1创建Notification1,它具有Intent1及其附加功能.
当我使用PendingIntent2创建Notification2时,Intent2具有自己的不同附加功能,Intent1现在将具有与Intent2相同的附加功能.为什么会这样?我该如何解决这个问题?
因此,在经过大量的努力之后,我才结束了.我的RemoteViews通知中有一个媒体播放器,我希望能够访问播放,暂停,上一个和下一个按钮.
我知道setOnClickPendingIntent()将用于通知通知.但是,我想知道它是如何工作的.
是否可以让服务处理点击?
我试过这个,但是徒劳无功.我试图让我服务处理播放器的暂停和恢复:
rm = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notif_media_player);
Intent intent = new Intent(getApplicationContext(), MusicService.class);
intent.putExtra(REQUEST_CODE, PAUSE);
PendingIntent pending = PendingIntent.getService(getApplicationContext(), PAUSE, intent, 0);
rm.setPendingIntentTemplate(R.id.pause, pending);
Notification notif = new NotificationCompat.Builder(getApplicationContext())
.setOngoing(true)
.setSmallIcon(R.drawable.ic_launcher)
.setContent(rm)
.build();
NotificationManager mgr = (NotificationManager) getApplicationContext()
.getSystemService(Context.NOTIFICATION_SERVICE);
mgr.notify(NOTIFICATION_ID, notif);
Run Code Online (Sandbox Code Playgroud)
我的IBinder是空的.如果这有所作为.
如何从通知中暂停和播放音乐?
android android-service android-pendingintent android-remoteview
我想知道按下了哪个按钮,所以我在 onReceive 上执行此操作
Log.e(TAG, "Clicked " + extras.getInt("ACTION"));
Run Code Online (Sandbox Code Playgroud)
而且我总是,无论我按哪个按钮,都会得到 3 (ActionEnum.GO_TO_REMINDERS),即setContentIntent.
另一个问题是,除非我按下通知好友,否则通知不会关闭,但是当我按下按钮时它不会关闭。
public void createNotification(Context context, Reminder reminder) {
// Build notification
Notification noti = new Notification.Builder(context)
.setContentTitle(reminder.getDisplayString())
.setContentText("Pick Action")
.setSmallIcon(R.drawable.icon_remider)
.setContentIntent(
getPendingAction(context, reminder,
ActionEnum.GO_TO_REMINDERS))
.addAction(R.drawable.icon, "Take",
getPendingAction(context, reminder, ActionEnum.TAKE))
.addAction(R.drawable.icon, "Snooze",
getPendingAction(context, reminder, ActionEnum.SNOOZE))
.addAction(R.drawable.icon, "Remove",
getPendingAction(context, reminder, ActionEnum.REMOVE))
.build();
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
// hide the notification after its selected
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, noti);
}
public PendingIntent getPendingAction(Context context, Reminder reminder,
ActionEnum …Run Code Online (Sandbox Code Playgroud) 如果我有一个被用户关闭的活动(用户按下主页,所以应用程序仍在应用程序堆栈中),然后他收到通知,当他按下它时,我开始一个活动,现在同一个活动打开了两次。我怎样才能防止这种情况发生?
我的代码:
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
NotificationManager mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.logo)
.setContentTitle("Title")
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
.setAutoCancel(true)
.setLights(GCMSIntentService.PURPLE, 500, 500)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setContentText(msg);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(1, mBuilder.build());
Run Code Online (Sandbox Code Playgroud) android android-activity android-pendingintent google-cloud-messaging
我目前正在调试应用程序中的通知问题。在某些情况下,我想做的是安排在火箭发射时应该弹出的通知。我所做的是,在从 API 获取计划启动列表后,我将获取启动日期(自 1970 年 1 月 1 日以来的毫秒数)并System.currentTimeMillis()从中减去。然后我将使用结果时间来安排将来的通知,表示为System.currentTimeMillis() + timeDifference。我注意到无论出于何种原因,只显示 1 个通知。
我已经尝试通过在未来 2、4 和 6 分钟安排通知来进行调试,但是通知仅在 6 分钟标记处显示。
一些相关的代码如下:
public void scheduleNotifications(List<Launch> launches) {
for(int i = 0; i < launches.size(); i++) {
SimpleDateFormat format = new SimpleDateFormat("MMMM dd, yyyy HH:mm:ss z");
Date date = null;
try {
date = format.parse(launches.get(i).getWindowstart());
} catch (ParseException e) {
e.printStackTrace();
}
long timeBetween = date.getTime() - System.currentTimeMillis();
Integer id = Long.valueOf(date.getTime()).intValue();
Intent notificationIntent = new Intent(this, NotificationPublisher.class); …Run Code Online (Sandbox Code Playgroud) android broadcastreceiver alarmmanager android-notifications android-pendingintent
我很久以前就在 Playstore 上有一个应用程序,最近通知未向用户打开
这是我的代码
private void showNotification () {
PhoneUtils.clearAllNotifications(getApplicationContext());
NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
String channelId = “app”;
int notificationId = 100;
createNotificationChannel(channelId , notificationManager);
Notification notification = new NotificationCompat.Builder(getApplicationContext(), channelId)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(getApplicationContext().getResources().getString(R.string.app_name))
.setContentText(mAlert)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setAutoCancel(true)
.setContentIntent(getOpenNotificationIntent())
.setDefaults(Notification.DEFAULT_ALL)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.build();
notificationManager.notify(notificationId, notification);
}
private PendingIntent getOpenNotificationIntent () {
int requestID = (int) System.currentTimeMillis();
Intent intent = new Intent(“com.app.OPEN”);
intent.putExtra(ForSaleConstants.ACTIVITY_NOTIFICATION_TYPE, mType);
intent.putExtra(ForSaleConstants.ACTIVITY_NOTIFICATION_ID, mId);
intent.putExtra(ForSaleConstants.ACTIVITY_NOTIFICATION_DIALOG_ID, mDialogId);
intent.putExtra(ForSaleConstants.ACTIVITY_NOTIFICATION_MESSAGE_ID, mMessageId);
Notification notification = null;
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), requestID,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
return pendingIntent; …Run Code Online (Sandbox Code Playgroud)