2015-12-17 58 views
0

我没有成功响应Titanium Alloy中的通知。 所有工作示例都是经典示例。尽管我在tiampl.xml中定义了以下活动Titanium Android通知在用户单击通知时执行操作

即使tiapp.xml包含notification.js活动,您仍然可以看到AndroidManifest.xml不包含此活动。它应该加上这个!

<id>alloyandroidnotification.example.com</id> 
<name>alloyandroidnotification</name> 
<activity url="notification.js"> 
<intent-filter> 
<action android:name="android.intent.action.VIEW"/> 
<category android:name="android.intent.category.DEFAULT"/> 
</intent-filter> 
</activity> 

我在lib文件夹中定义notification.js和我的index.js文件是:

function doClick(e) { 
     var intent = Ti.Android.createIntent({ 
      action: Ti.Android.ACTION_VIEW, 
      packageName:"alloyandroidnotification.example.com", 
      className:"alloyandroidnotification.example.com.NotificationActivity" 
     }); 
     intent.addCategory(Ti.Android.CATEGORY_LAUNCHER); 


     Titanium.Android.NotificationManager.notify(1, Titanium.Android.createNotification({ 
      contentTitle: "notification", 
      contentText : "notification", 
      contentIntent: Ti.Android.createPendingIntent({ 
       intent:intent, 
       type : Ti.Android.PENDING_INTENT_FOR_ACTIVITY 
      }), 
      flags : Titanium.Android.FLAG_AUTO_CANCEL | Titanium.Android.FLAG_SHOW_LIGHTS 
     })); 
} 

$.index.open(); 

AndroidManifest.xml中

<application android:icon="@drawable/appicon" android:label="alloyandroidnotification" android:name="AlloyandroidnotificationApplication" android:debuggable="false" android:theme="@style/Theme.AppCompat"> 
    <activity android:name=".AlloyandroidnotificationActivity" android:label="@string/app_name" android:theme="@style/Theme.Titanium" android:configChanges="keyboardHidden|orientation|screenSize"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN"/> 
      <category android:name="android.intent.category.LAUNCHER"/> 
     </intent-filter> 
    </activity> 
    <activity android:name="org.appcelerator.titanium.TiActivity" android:configChanges="keyboardHidden|orientation|screenSize"/> 
    <activity android:name="org.appcelerator.titanium.TiTranslucentActivity" android:configChanges="keyboardHidden|orientation|screenSize" android:theme="@style/Theme.AppCompat.Translucent"/> 
    <activity android:name="ti.modules.titanium.ui.android.TiPreferencesActivity" android:configChanges="screenSize"/> 
    <service android:name="com.appcelerator.analytics.APSAnalyticsService" android:exported="false"/> 
</application> 

我应该在AndroidManifest.xml中看到以下缺失预期活动

<android 
    xmlns:android="http://schemas.android.com/apk/res/android"> 

     <activity url="notificationClick.js"> 
     <intent-filter> 
      <action android:name="android.intent.action.VIEW"/> 
      <category android:name="android.intent.category.DEFAULT"/> 
     </intent-filter> 
     </activity> 


    </android> 

单击通知时没有任何反应。但遵循经典的示例作品。 classic example code that works

回答

1

我想通了,你必须使用<activity>与URL <activities>之外,否则它不也工作,如果使用<application>如果你想使用<application>使用自定义AndroidManifest.xml

<android xmlns:android="http://schemas.android.com/apk/res/android"> 
<activities> 
    <activity url="notificationClick.js"> 
    <intent-filter> 
     <action android:name="android.intent.action.VIEW"/> 
     <category android:name="android.intent.category.DEFAULT"/> 
    </intent-filter> 
    </activity> 
</activities> 
</android> 
1
+0

嗨福克,它已经在安卓标签我已经更新了XML。但我想出了为什么它不工作必须在标记,否则它不起作用。如果您使用它不起作用,我认为这是一个错误。 – geekmangnu

相关问题