简体   繁体   English

所需的RegId:java.io.FileNotFoundException:GCMRegId.txt(系统找不到指定的文件)

[英]RegId required: java.io.FileNotFoundException: GCMRegId.txt (The system cannot find the file specified)

I have written a program to implement Google Cloud Messaging in android using jsp . 我编写了一个程序,使用jsp在android中实现Google Cloud Messaging。 Got the reference from here ( http://javapapers.com/android/google-cloud-messaging-gcm-for-android-and-push-notifications/ ) I am not able to run on server when i try to run program in my eclipse it gives me GCMRegId.txt missing error. 从这里获得了参考( http://javapapers.com/android/google-cloud-messaging-gcm-for-android-and-push-notifications/ )当我尝试在Windows中运行程序时,我无法在服务器上运行我的日食给了我GCMRegId.txt丢失的错误。 Here are the code: 这是代码:

 GCMNotification.java

@WebServlet("/GCMNotification")
public class GCMNotification extends HttpServlet {

private static final String GOOGLE_SERVER_KEY = "AIzaSyDA5dlLInMsasJEUTIHV0u7maB82MCasdU";
static final String MESSAGE_KEY = "message";    

public GCMNotification() {
    super();
}

protected void doGet(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    doPost(request, response);

}

protected void doPost(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {


    Result result = null;

    String share = request.getParameter("shareRegId");

    // GCM RedgId of Android device to send push notification
    String regId = "APA91bG6cLX8OYyZDRypuRq6uodZ9PuMfiql9k6K66i9hZFnS5xr-QmT13nRozGQ10KXNmcMqbsLCVUIS9joGiOPasdfghjklp_AmH2iNs1YVqY3IYzgHoQ";
    if (share != null && !share.isEmpty()) {
        regId = request.getParameter("regId");
        PrintWriter writer = new PrintWriter("GCMRegId.txt");
        writer.println(regId);
        writer.close();
        request.setAttribute("pushStatus", "GCM RegId Received.");
        request.getRequestDispatcher("index.jsp")
                .forward(request, response);
    } else {

        try {
            BufferedReader br = new BufferedReader(new FileReader(
                    "GCMRegId.txt"));
            regId = br.readLine();
            br.close();
            String userMessage = request.getParameter("message");
            Sender sender = new Sender(GOOGLE_SERVER_KEY);
            Message message = new Message.Builder().timeToLive(30)
                    .delayWhileIdle(true).addData(MESSAGE_KEY, userMessage).build();
            System.out.println("regId: " + regId);
            result = sender.send(message, regId, 1);
            request.setAttribute("pushStatus", result.toString());
        } catch (IOException ioe) {
            ioe.printStackTrace();
            request.setAttribute("pushStatus",
                    "RegId required: " + ioe.toString());
        } catch (Exception e) {
            e.printStackTrace();
            request.setAttribute("pushStatus", e.toString());
        }
        request.getRequestDispatcher("index.jsp")
                .forward(request, response);
    }
}

JSP page: index.jsp JSP页面:index.jsp

  <head>
 </head>
 <body>

<h1>Google Cloud Messaging (GCM) Server in Java</h1>
 <%
String pushStatus = "";
Object pushStatusObj = request.getAttribute("pushStatus");

if (pushStatusObj != null) {
    pushStatus = pushStatusObj.toString();
}
 %>
<form action="GCMNotification" method="post">

    <div>
          <textarea rows="2" name="message" cols="23"
          placeholder="Message to transmit via GCM"></textarea>
    </div>
    <div>
        <input type="submit" value="Send Push Notification via GCM" />
    </div>
</form>
<p>
    <h3>
        <%=pushStatus%>
    </h3>
</p>

It always gives me error like RegId required: java.io.FileNotFoundException: GCMRegId.txt (The system cannot find the file specified) how can i resolve that error??? 它总是给我类似所需的RegId的错误:java.io.FileNotFoundException:GCMRegId.txt(系统找不到指定的文件)我该如何解决该错误?

Hey Guys i solved that problem. 嗨,我解决了这个问题。 GCMRegId.txt file generate automatically. GCMRegId.txt文件自动生成。 Does not make manually that file. 不手动制作该文件。

Or if you dont want to make GCMRegId.txt file simply remove from your code and and pass the DeviceId to the regID(string) and remove unused code. 或者,如果您不想制作GCMRegId.txt文件,只需从代码中删除,然后将DeviceId传递给regID(string)并删除未使用的代码。

you will get your output. 您将获得输出。 thanks. 谢谢。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.io.FileNotFoundException:read.txt(系统找不到指定的文件) - java.io.FileNotFoundException: read.txt (The system cannot find the file specified)` java.io.FileNotFoundException: 系统找不到指定的文件 - java.io.FileNotFoundException: the system cannot find the file specified 文件错误为:-java.io.FileNotFoundException:\\ files \\ storetime.txt(系统找不到指定的路径) - Error in file is :- java.io.FileNotFoundException: \files\storetime.txt (The system cannot find the path specified) java.io.FileNotFoundException:in.txt,(系统找不到指定的文件) - java.io.FileNotFoundException: in.txt, (The system cannot find the file specified) Java NetBeans - 线程“main”中的异常 java.io.FileNotFoundException: alice.txt(系统找不到指定的文件) - Java NetBeans - Exception in thread "main" java.io.FileNotFoundException: alice.txt (The system cannot find the file specified) java.io.FileNotFoundException:Database \\ User.txt(系统找不到指定的路径) - java.io.FileNotFoundException: Database\User.txt (The system cannot find the path specified) PrintWriter : java.io.FileNotFoundException: 系统找不到指定的路径 - PrintWriter : java.io.FileNotFoundException: The system cannot find the path specified 线程“main”中的异常java.io.FileNotFoundException:(系统找不到指定的文件)请求文件路径时 - Exception in thread "main" java.io.FileNotFoundException: (The system cannot find the file specified) when asking for file path java.io.FileNotFoundException:系统找不到指定的文件-在数据库中插入图像时 - java.io.FileNotFoundException: the system cannot find the file specified -while inserting an image in database java.io.FileNotFoundException :(使用多部分时,系统找不到指定的文件) - java.io.FileNotFoundException: (The system cannot find the file specified) when using multipart
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM