我在GCMIntentservice中编写了一个代码,用于向许多用户发送推送通知.我使用NotificationManager,在单击通知时将调用DescriptionActivity类.我还将event_id格式的GCMIntentService发送到DescriptionActivity
protected void onMessage(Context ctx, Intent intent) {
message = intent.getStringExtra("message");
String tempmsg=message;
if(message.contains("You"))
{
String temparray[]=tempmsg.split("=");
event_id=temparray[1];
}
nm= (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
intent = new Intent(this, DescriptionActivity.class);
Log.i("the event id in the service is",event_id+"");
intent.putExtra("event_id", event_id);
intent.putExtra("gcmevent",true);
PendingIntent pi = PendingIntent.getActivity(this,0, intent, 0);
String title="Event Notifier";
Notification n = new Notification(R.drawable.defaultimage,message,System.currentTimeMillis());
n.setLatestEventInfo(this, title, message, pi);
n.defaults= Notification.DEFAULT_ALL;
nm.notify(uniqueID,n);
sendGCMIntent(ctx, message);
}
Run Code Online (Sandbox Code Playgroud)
这里我在上面的方法中得到的event_id是正确的,即我总是得到更新的.但是在下面的代码中(DescriptionActivity.java):
intent = getIntent();
final Bundle b = intent.getExtras();
event_id = Integer.parseInt(b.getString("event_id"));
Run Code Online (Sandbox Code Playgroud)
这里的event_id总是"5".无论我把什么放在GCMIntentService类中,我得到的event_id总是5.有人可以指出问题吗?是因为未决意图?如果是,那我该怎么处理呢?
push-notification android-notifications android-notification-bar android-pendingintent
我正在尝试使用powermock测试方法.我还没有写过任何测试用例.只是试图为Mocking设置课程.这是我到目前为止:
@RunWith(PowerMockRunner.class)
@PrepareForTest({ ReadRubric.class })
public class ReadRubricTest {
@Before
public void setUp() throws Exception {
PowerMockito.mock(ReadRubric.class);
}
@After
public void tearDown() throws Exception {
}
@Test
public void invalidFile() throws Exception {
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试运行此测试时,我收到以下错误.
java.lang.VerifyError: Bad type on operand stack in arraylength
Exception Details:
Location:
com/cerner/devcenter/wag/processor/ReadRubric.readRubric()Ljava/util/List; @809: arraylength
Reason:
Invalid type: 'java/lang/Object' (current frame, stack[0])
Current Frame:
bci: @809
flags: { }
locals: { 'java/util/ArrayList', 'au/com/bytecode/opencsv/CSVReader', top, top, '[Ljava/lang/String;', 'com/cerner/devcenter/wag/processor/Rule', 'java/lang/Object', 'java/lang/Object', top, top, top, top, top, top, …Run Code Online (Sandbox Code Playgroud) 我正在尝试在Google Play商店上传应用程序.我正在构建.apk并使用Maven进行签名.我使用maven-jarsigner-plugin来签署.apk文件.我正在使用我使用Eclipse向导创建的密钥来签署另一个Android应用程序.我使用以下命令对.apk文件进行zipalign:zipalign [-f] [-v] infile.apk outfile.apk
当我尝试在playstore上上传应用程序时,我收到错误您上传了一个以调试模式签名的APK.您需要在发布模式下签署APK.任何人都可以告诉我如何在发布模式下签署apk?我是Maven的新手(今天开始使用它).谢谢
嗨,我有一个方法,将URL作为输入,并确定它是否可访问.下面是代码:
public static boolean isUrlAccessible(final String urlToValidate) throws WAGNetworkException {
URL url = null;
HttpURLConnection huc = null;
int responseCode = -1;
try {
url = new URL(urlToValidate);
huc = (HttpURLConnection) url.openConnection();
huc.setRequestMethod("HEAD");
huc.connect();
responseCode = huc.getResponseCode();
} catch (final UnknownHostException e) {
throw new WAGNetworkException(WAGConstants.INTERNET_CONNECTION_EXCEPTION);
} catch (IOException e) {
throw new WAGNetworkException(WAGConstants.INVALID_URL_EXCEPTION);
} finally {
if (huc != null) {
huc.disconnect();
}
}
return responseCode == 200;
}
Run Code Online (Sandbox Code Playgroud)
我想使用isUrlAccessible()方法对单元进行单元测试PowerMockito.我觉得我需要用来whenNew()模拟创建URL和url.openConnection()调用的时候,返回另一个模拟HttpURLConnection …
嘿,我很难在发布模式下构建和签署apk.我可以使用maven创建apk但是当我尝试上传它时,Google Playstore说我需要在发布模式下构建.
这是我的pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.kannact4.gladstonesign</groupId>
<artifactId>gladstonesign</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>apk</packaging>
<name>Android Maven Example</name>
<profiles>
<profile>
<id>release</id>
<activation>
<property>
<name>performRelease</name>
<value>true</value>
</property>
</activation>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>2.2.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>unaligned-gladstonesign</finalName>
<sourceDirectory>src</sourceDirectory>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.1.1</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
<version>1.2</version>
<configuration>
<keystore>C:\Project\Eclipse workspace\apk_key</keystore>
<alias>gs3key</alias>
<storepass>****</storepass>
<keypass>****</keypass>
<verbose>true</verbose>
<certs>true</certs>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<configuration>
<sdk>
<platform>17</platform>
</sdk>
</configuration>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助我如何在构建模式下释放它?
我正在尝试检查URL是否可访问.我正在使用HttpURLConnection.现在我正在实施它.
public static boolean isUrlAccessible(final String urlToValidate)
throws WAGException {
URL url = null;
HttpURLConnection huc = null;
int responseCode = -1;
try {
url = new URL(urlToValidate);
huc = (HttpURLConnection) url.openConnection();
huc.setRequestMethod("HEAD");
huc.connect();
responseCode = huc.getResponseCode();
} catch (final UnknownHostException e) {
e.printStackTrace();
System.out.println(e.getMessage()+" "+e.getLocalizedMessage());
return false;
} catch (final MalformedURLException e){
e.printStackTrace();
System.out.println(e.getMessage()+" "+e.getLocalizedMessage());
return false;
} catch (ProtocolException e) {
e.printStackTrace();
System.out.println(e.getMessage()+" "+e.getLocalizedMessage());
return false;
} catch (IOException e) {
e.printStackTrace();
System.out.println(e.getMessage()+" "+e.getLocalizedMessage());
return false;
} finally …Run Code Online (Sandbox Code Playgroud) 我在MultipartEntity中使用,我正在尝试引用raw文件夹中的文件.这是代码:
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart(new FormBodyPart("file", new FileBody(new File("test.txt"))));
Run Code Online (Sandbox Code Playgroud)
test.txt文件位于我的res/raw文件夹中.当我执行代码时,我得到以下异常:FileNotFoundException:/test.txt:open failed:ENOENT(没有这样的文件或目录)
谁能帮我这个?