相关疑难解决方法(0)

116
推荐指数
6
解决办法
8万
查看次数

从android中的通知栏启动一个应用程序

我有一个应用程序,我希望在我的应用程序运行时将我的应用程序图标显示到通知栏,我还希望当用户点击通知栏中显示的应用程序图标时,我的应用程序将打开.这该怎么做?请帮忙!

android

9
推荐指数
3
解决办法
2万
查看次数

从Firebase通知意图中获取额外的MainActivity

我已经尝试了这3天的android通知工作,用户点击通知然后活动打开.但每次我举杯,它都说是空的.尝试使用SOF的一些解决方案,但不起作用.你能看看代码有什么问题吗?提前致谢.

通知代码是

private void sendPushNotification(JSONObject json) {
    //optionally we can display the json into log
    int notificationId = new Random().nextInt();

    Log.e(TAG, "Notification JSON " + json.toString());
    try {
        //getting the json data
        JSONObject data = json.getJSONObject("data");

        //parsing json data
        String title = data.getString("title");
        String message = data.getString("message");
        String imageUrl = data.getString("image");

        // Instantiate a Builder object.
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this.getApplicationContext(),"Default");

        Intent notifyIntent = new Intent(this, MainActivity.class);
        notifyIntent.putExtra("fromNotification", true);
        // Sets the Activity to start in a new, empty task …
Run Code Online (Sandbox Code Playgroud)

android firebase firebase-cloud-messaging

6
推荐指数
2
解决办法
1983
查看次数

单击通知以打开我的活动时的 firebase 消息传递

firebase 工作正常,在状态栏上推送通知,但我的挑战是点击通知时,我希望它带我到我的自定义活动而不是默认启动器,我该怎么做?

public class CustomActivity extends AppCompatActivity {

private static final String TAG = "CustomActivity";


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    TextView mymessage = (TextView) findViewById(R.id.mymessage);

    // If a notification message is tapped, any data accompanying the notification
    // message is available in the intent extras. In this sample the launcher
    // intent is fired when the notification is tapped, so any accompanying data would
    // be handled here. If you want a different intent fired, set the …
Run Code Online (Sandbox Code Playgroud)

android push-notification firebase firebase-cloud-messaging

5
推荐指数
1
解决办法
6904
查看次数

单击通知时如何打开活动

我需要使用带有单击事件的通知,我有通知方法,但此方法不会打开我的活动。

我的代码:

 private void sendNotification(String msg) {

        NotificationCompat.Builder mBuilder =  new NotificationCompat.Builder(this)
        .setContentTitle("EXX")
        .setSmallIcon(R.drawable.ic_launcher)
        .setStyle(new NotificationCompat.BigTextStyle()
        .bigText(msg))
        .setContentText(msg)          
        .setOngoing(true);          
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}    
Run Code Online (Sandbox Code Playgroud)

这可能吗,

谢谢。

java android android-notifications android-notification-bar

5
推荐指数
2
解决办法
1万
查看次数

android 如何在用户点击通知时启动活动?

我想在用户单击通知时打开活动。我知道这个问题是重复的,但找不到解决方案,这就是我所做的

NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText("Hello World!");

Intent resultIntent = new Intent(this, ResultActivity.class);

// Because clicking the notification opens a new ("special") activity, there's
// no need to create an artificial back stack.
PendingIntent resultPendingIntent =
    PendingIntent.getActivity(
    this,
    0,
    resultIntent,
    PendingIntent.FLAG_UPDATE_CURRENT
);

mBuilder.setContentIntent(resultPendingIntent);
// Sets an ID for the notification
int mNotificationId = 001;
// Gets an instance of the NotificationManager service
NotificationManager mNotifyMgr = 
    (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Builds the notification and issues it.
mNotifyMgr.notify(mNotificationId, mBuilder.build()); …
Run Code Online (Sandbox Code Playgroud)

notifications android android-pendingintent

4
推荐指数
1
解决办法
3万
查看次数

在Android中如何知道当前通知ID以清除通知

现在在android中我把这个代码放在一个活动中,以便在按下按钮时显示通知.

static int notificationCount = 0;
Run Code Online (Sandbox Code Playgroud)

然后

 btnNotification.setOnClickListener(
            new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    Intent notificationIntent = new Intent(AlertsActivity.this,NotificationActivitty.class);
                    PendingIntent pIntent = PendingIntent.getActivity(AlertsActivity.this,notificationCount,notificationIntent,Intent.FLAG_ACTIVITY_NEW_TASK);

                    // Construct the notification
                    Notification.Builder nBuilder = new Notification.Builder(AlertsActivity.this);
                    nBuilder.setContentTitle("You Have a notification!");
                    nBuilder.setContentText("See Your Notification");
                    nBuilder.setSmallIcon(android.R.drawable.btn_star);
                    nBuilder.setContentIntent(pIntent);
                   nBuilder.addAction(android.R.drawable.stat_notify_call_mute, "go to", pIntent); // from icecream sandwatch - required api 16

                    // Build the notification
                    Notification noti = nBuilder.build(); // required api 16

                    //Send it to manager
                        NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
                        manager.notify(notificationCount++,noti);
                }
            }
    ); …
Run Code Online (Sandbox Code Playgroud)

notifications android android-intent notificationmanager android-notifications

4
推荐指数
1
解决办法
2万
查看次数