gpt4 book ai didi

android - 单击通知时 Activity 不会启动

转载 作者:行者123 更新时间:2023-11-30 01:49:55 26 4
gpt4 key购买 nike

我在我的应用程序中创建了一个通知设置。当用户单击通知时,一个 Activity Coding 应该打开。但它不是。当我检查电话日志时(在android studio)里面有这样的东西:

10-19 19:18:14.598 888-1437/? W/ActivityManager:权限被拒绝:启动 Intent { flg=0x1000c000 cmp=com.defcomdevs.invento16/.Coding bnds=[0,874][1080,1060] } from null (pid=-1, uid=10169) 未从 uid 导出10185

我不明白那是什么?我的通知代码是:

public class AlarmReceiver extends BroadcastReceiver {
static int notifyId=1;
@Override
public void onReceive(Context context, Intent intent) {
//Toast.makeText(context,"Alarm has been set",Toast.LENGTH_SHORT).show();
NotificationCompat.Builder mNotify=new NotificationCompat.Builder(context);
mNotify.setSmallIcon(R.drawable.index);
mNotify.setContentTitle("Coding");
mNotify.setContentText("INVENTO: Coding competition is going to be conducted today.");
Intent resultIntent=new Intent(context,Coding.class); //activity to open up when user clicks the notification
TaskStackBuilder stackBuilder=TaskStackBuilder.create(context);
stackBuilder.addParentStack(Coding.class); //add the to-be-displayed activity to the top of stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
mNotify.setContentIntent(resultPendingIntent);
NotificationManager notificationManager=(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(notifyId, mNotify.build());
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(context, notification);
r.play();
//note: on click display activity is not working.
}
}

请帮忙!!

我的 manifest.xml 文件:

  <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.defcomdevs.invento16" >

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AlarmActivity"
android:label="@string/title_activity_alarm"
android:theme="@style/AppTheme.NoActionBar" >
</activity>

<receiver
android:name=".AlarmReceiver"
android:process=":remote" />

<activity
android:name=".Registration"
android:label="@string/title_activity_registration"
android:theme="@style/AppTheme.NoActionBar" >
</activity>
<activity
android:name=".Coding"
android:label="@string/title_activity_coding"
android:theme="@style/AppTheme.NoActionBar" >
</activity>
</application>

最佳答案

android:exported="true" 添加到 manifest.xml 文件中的 .Coding Activity 标签。但请记住,这允许其他应用程序启动您的 Activity 。

关于android - 单击通知时 Activity 不会启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33216337/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com