0

Adobe AIR 3.2 とネイティブ拡張機能を使用して、Android 用のアクション sctipt でアプリケーションを作成しています。私の仕事は、通知にネイティブ拡張をスローさせ、その通知をクリックできるようにし、バックグラウンドからアプリケーションを開く必要があることです。通知を実行するようにしましたが、クリックしてもアプリケーションを実行できません。どうすればそれができますか?私は何を間違えましたか?助けてください、ありがとう。

package com.company.extensions;

import java.util.HashMap;
import java.util.Map;

  import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Vibrator;
import android.util.Log;

import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;

public class ToolsExtensionContext extends FREContext 
{
    public Vibrator vb = null;

    @Override
    public void dispose() 
    {

    }

    @Override
    public Map<String, FREFunction> getFunctions() 
    {
        Map<String, FREFunction> functionMap = new HashMap<String, FREFunction>();

        functionMap.put("notifyUser", new ToolsNotifyFunction());

        return functionMap;
    }

    void notifyUser()
    {
        Log.d("bla-bla-bla", "Just bla");


        // look up the notification manager service
        NotificationManager nm = (NotificationManager)this.getActivity().getSystemService(Context.NOTIFICATION_SERVICE);

        // The details of our fake message
        CharSequence from = "Hello";
        CharSequence message = "Some message!";

        // The PendingIntent to launch our activity if the user selects this
        // notification.  Note the use of FLAG_CANCEL_CURRENT so that, if there
        // is already an active matching pending intent, cancel it and replace
        // it with the new array of Intents.
        Intent k = new Intent(this.getActivity().getApplicationContext(), ToolsExtensionContext.class);

        PendingIntent contentIntent = PendingIntent.getService(this.getActivity().getApplicationContext(), 
                0, k , PendingIntent.FLAG_CANCEL_CURRENT);

        // The ticker text, this uses a formatted string so our message could be localized
        String tickerText = "Tiker text";

        // construct the Notification object.
        Notification notif = new Notification(R.drawable.close, tickerText, System.currentTimeMillis() + 100000);

        // Set the info for the views that show in the notification panel.
        notif.setLatestEventInfo(this.getActivity().getApplicationContext(), from, message, null);//contentIntent);

        // We'll have this notification do the default sound, vibration, and led.
        // Note that if you want any of these behaviors, you should always have
        // a preference for the user to turn them off.
        notif.defaults = Notification.DEFAULT_ALL;
        notif.flags = Notification.FLAG_AUTO_CANCEL;

        // Note that we use R.layout.incoming_message_panel as the ID for
        // the notification.  It could be any integer you want, but we use
        // the convention of using a resource id for a string related to
        // the notification.  It will always be a unique number within your
        // application.
        nm.notify(1, notif);
    }
}
4

1 に答える 1

1

Android でローカル通知を送信し、通知を押した後、バックグラウンドに移行する前の同じアクティビティでアプリケーションを再開する作業コードを次に示します。

void sendLocalNotification()
    {

        // look up the notification manager service
        NotificationManager nm = (NotificationManager)this.getActivity().getSystemService(Context.NOTIFICATION_SERVICE);

        // The details of our fake message
        CharSequence from = "Hello";
        CharSequence message = "some message";

        // The PendingIntent to launch our activity if the user selects this
        // notification.  Note the use of FLAG_CANCEL_CURRENT so that, if there
        // is already an active matching pending intent, cancel it and replace
        // it with the new array of Intents.


        Intent k = new Intent(this.getActivity().getApplicationContext(), this.getActivity().getClass());
        Log.d("bla-bla-bla",  this.getActivity().getClass().toString());
        k.setAction(Intent.ACTION_MAIN);
        k.addCategory(Intent.CATEGORY_LAUNCHER);


        PendingIntent contentIntent = PendingIntent.getActivity(this.getActivity().getApplicationContext(), 
                0, k , PendingIntent.FLAG_CANCEL_CURRENT);

        //PendingIntent contentIntent = PendingIntent.getService(this.getActivity().getApplicationContext(), 
        //      0, k , PendingIntent.FLAG_CANCEL_CURRENT);

        // The ticker text, this uses a formatted string so our message could be localized
        String tickerText = "Tiker text";

        // construct the Notification object.
        Notification notif = new Notification(R.drawable.close, tickerText, System.currentTimeMillis() + 100000);

        // Set the info for the views that show in the notification panel.
        notif.setLatestEventInfo(this.getActivity().getApplicationContext(), from, message, contentIntent);

        // We'll have this notification do the default sound, vibration, and led.
        // Note that if you want any of these behaviors, you should always have
        // a preference for the user to turn them off.
        notif.defaults = Notification.DEFAULT_ALL;
        notif.flags = Notification.FLAG_AUTO_CANCEL;

        // Note that we use R.layout.incoming_message_panel as the ID for
        // the notification.  It could be any integer you want, but we use
        // the convention of using a resource id for a string related to
        // the notification.  It will always be a unique number within your
        // application.
        nm.notify(1, notif);
    }
于 2012-07-04T16:31:20.457 に答える